diff --git a/api/controllers/mcp/mcp.py b/api/controllers/mcp/mcp.py index 110283c630..7245767c9b 100644 --- a/api/controllers/mcp/mcp.py +++ b/api/controllers/mcp/mcp.py @@ -18,10 +18,8 @@ from models.model import App, AppMCPServer, AppMode class MCPAppApi(Resource): def post(self, server_code): def int_or_str(value): - if isinstance(value, int): + if isinstance(value, (int, str)): return value - elif isinstance(value, str): - return int(value) else: return None @@ -31,6 +29,7 @@ class MCPAppApi(Resource): parser.add_argument("params", type=dict, required=False, location="json") parser.add_argument("id", type=int_or_str, required=False, location="json") args = parser.parse_args() + server = db.session.query(AppMCPServer).filter(AppMCPServer.server_code == server_code).first() if not server: raise NotFound("Server Not Found") diff --git a/api/core/mcp/server/handler.py b/api/core/mcp/server/handler.py index 7884e8c90b..2e9e7718e1 100644 --- a/api/core/mcp/server/handler.py +++ b/api/core/mcp/server/handler.py @@ -123,7 +123,7 @@ class MCPServerReuqestHandler: db.session.add(end_user) db.session.commit() return types.InitializeResult( - protocolVersion=types.LATEST_PROTOCOL_VERSION, + protocolVersion=types.SERVER_LATEST_PROTOCOL_VERSION, capabilities=self.capabilities, serverInfo=types.Implementation(name="Dify", version=dify_config.CURRENT_VERSION), instructions=self.mcp_server.description, diff --git a/api/core/mcp/types.py b/api/core/mcp/types.py index 75c063f7dd..1c1726c799 100644 --- a/api/core/mcp/types.py +++ b/api/core/mcp/types.py @@ -30,9 +30,10 @@ for reference. * Define additional model classes instead of using dictionaries. Do this even if they're not separate types in the schema. """ - +# Client support both version, not support 2025-06-18 yet. LATEST_PROTOCOL_VERSION = "2025-03-26" - +# Server support 2024-11-05 to allow claude to use. +SERVER_LATEST_PROTOCOL_VERSION = "2024-11-05" ProgressToken = str | int Cursor = str Role = Literal["user", "assistant"]