|
|
@ -3,6 +3,7 @@ import json
|
|
|
|
import logging
|
|
|
|
import logging
|
|
|
|
from contextlib import AbstractAsyncContextManager
|
|
|
|
from contextlib import AbstractAsyncContextManager
|
|
|
|
from typing import Literal, Callable, Any
|
|
|
|
from typing import Literal, Callable, Any
|
|
|
|
|
|
|
|
from importlib import metadata
|
|
|
|
|
|
|
|
|
|
|
|
import jsonref
|
|
|
|
import jsonref
|
|
|
|
from maintainer.ai.model.nacos_mcp_info import McpToolMeta, McpServerDetailInfo, \
|
|
|
|
from maintainer.ai.model.nacos_mcp_info import McpToolMeta, McpServerDetailInfo, \
|
|
|
@ -278,6 +279,10 @@ class NacosServer(Server):
|
|
|
|
asyncio.create_task(self.subscribe())
|
|
|
|
asyncio.create_task(self.subscribe())
|
|
|
|
if self._nacos_settings.SERVICE_REGISTER and (self.type == "mcp-sse"
|
|
|
|
if self._nacos_settings.SERVICE_REGISTER and (self.type == "mcp-sse"
|
|
|
|
or self.type == "mcp-streamable"):
|
|
|
|
or self.type == "mcp-streamable"):
|
|
|
|
|
|
|
|
version = metadata.version('nacos-mcp-wrapper-python')
|
|
|
|
|
|
|
|
service_meta_data = {
|
|
|
|
|
|
|
|
"source": f"nacos-mcp-wrapper-python-{version}",
|
|
|
|
|
|
|
|
**self._nacos_settings.SERVICE_META_DATA}
|
|
|
|
await self.naming_client.register_instance(
|
|
|
|
await self.naming_client.register_instance(
|
|
|
|
request=RegisterInstanceParam(
|
|
|
|
request=RegisterInstanceParam(
|
|
|
|
group_name=server_detail_info.remoteServerConfig.serviceRef.groupName,
|
|
|
|
group_name=server_detail_info.remoteServerConfig.serviceRef.groupName,
|
|
|
@ -285,8 +290,10 @@ class NacosServer(Server):
|
|
|
|
ip=self._nacos_settings.SERVICE_IP,
|
|
|
|
ip=self._nacos_settings.SERVICE_IP,
|
|
|
|
port=self._nacos_settings.SERVICE_PORT if self._nacos_settings.SERVICE_PORT else port,
|
|
|
|
port=self._nacos_settings.SERVICE_PORT if self._nacos_settings.SERVICE_PORT else port,
|
|
|
|
ephemeral=self._nacos_settings.SERVICE_EPHEMERAL,
|
|
|
|
ephemeral=self._nacos_settings.SERVICE_EPHEMERAL,
|
|
|
|
|
|
|
|
metadata=service_meta_data
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
logging.info(f"Register to nacos success,{self.name},version:{self.version}")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
mcp_tool_specification = None
|
|
|
|
mcp_tool_specification = None
|
|
|
@ -335,7 +342,7 @@ class NacosServer(Server):
|
|
|
|
mcp_tool_specification,
|
|
|
|
mcp_tool_specification,
|
|
|
|
endpoint_spec)
|
|
|
|
endpoint_spec)
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
logger.info(f"Failed to create MCP server to Nacos,try to update mcp server")
|
|
|
|
logger.info(f"Found MCP server {self.name} in Nacos,try to update it")
|
|
|
|
version_detail = None
|
|
|
|
version_detail = None
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
version_detail = await self.mcp_service.get_mcp_server_detail(
|
|
|
|
version_detail = await self.mcp_service.get_mcp_server_detail(
|
|
|
@ -344,12 +351,12 @@ class NacosServer(Server):
|
|
|
|
self.version
|
|
|
|
self.version
|
|
|
|
)
|
|
|
|
)
|
|
|
|
except Exception as e_2:
|
|
|
|
except Exception as e_2:
|
|
|
|
logger.info(f"Cant found version {self.version} of Mcp server {self.name}")
|
|
|
|
logger.info(f" Version {self.version} of Mcp server {self.name} is not in Nacos, try to update it")
|
|
|
|
if version_detail is None:
|
|
|
|
if version_detail is None:
|
|
|
|
await self.mcp_service.update_mcp_server(
|
|
|
|
await self.mcp_service.update_mcp_server(
|
|
|
|
self._nacos_settings.NAMESPACE,
|
|
|
|
self._nacos_settings.NAMESPACE,
|
|
|
|
self.name,
|
|
|
|
self.name,
|
|
|
|
False,
|
|
|
|
True,
|
|
|
|
server_basic_info,
|
|
|
|
server_basic_info,
|
|
|
|
mcp_tool_specification,
|
|
|
|
mcp_tool_specification,
|
|
|
|
endpoint_spec
|
|
|
|
endpoint_spec
|
|
|
@ -362,6 +369,8 @@ class NacosServer(Server):
|
|
|
|
f"mcp server info is not compatible,{self.name},version:{self.version},reason:{error_msg}"
|
|
|
|
f"mcp server info is not compatible,{self.name},version:{self.version},reason:{error_msg}"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if self._nacos_settings.SERVICE_REGISTER:
|
|
|
|
if self._nacos_settings.SERVICE_REGISTER:
|
|
|
|
|
|
|
|
version = metadata.version('nacos-mcp-wrapper-python')
|
|
|
|
|
|
|
|
service_meta_data = {"source": f"nacos-mcp-wrapper-python-{version}",**self._nacos_settings.SERVICE_META_DATA}
|
|
|
|
await self.naming_client.register_instance(
|
|
|
|
await self.naming_client.register_instance(
|
|
|
|
request=RegisterInstanceParam(
|
|
|
|
request=RegisterInstanceParam(
|
|
|
|
group_name="DEFAULT_GROUP" if self._nacos_settings.SERVICE_GROUP is None else self._nacos_settings.SERVICE_GROUP,
|
|
|
|
group_name="DEFAULT_GROUP" if self._nacos_settings.SERVICE_GROUP is None else self._nacos_settings.SERVICE_GROUP,
|
|
|
@ -369,8 +378,10 @@ class NacosServer(Server):
|
|
|
|
ip=self._nacos_settings.SERVICE_IP,
|
|
|
|
ip=self._nacos_settings.SERVICE_IP,
|
|
|
|
port=self._nacos_settings.SERVICE_PORT if self._nacos_settings.SERVICE_PORT else port,
|
|
|
|
port=self._nacos_settings.SERVICE_PORT if self._nacos_settings.SERVICE_PORT else port,
|
|
|
|
ephemeral=self._nacos_settings.SERVICE_EPHEMERAL,
|
|
|
|
ephemeral=self._nacos_settings.SERVICE_EPHEMERAL,
|
|
|
|
|
|
|
|
metadata=service_meta_data,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
asyncio.create_task(self.subscribe())
|
|
|
|
asyncio.create_task(self.subscribe())
|
|
|
|
|
|
|
|
logging.info(f"Register to nacos success,{self.name},version:{self.version}")
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
logging.error(f"Failed to register MCP server to Nacos: {e}")
|
|
|
|
logging.error(f"Failed to register MCP server to Nacos: {e}")
|
|
|
|