From bc609f832310ed9d06b504425e2f9ac54069f65c Mon Sep 17 00:00:00 2001 From: Mattt Zmuda Date: Tue, 6 May 2025 11:44:58 -0700 Subject: [PATCH] Don't throw error if there's a protocol mismatch between client and server --- Sources/MCP/Server/Server.swift | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Sources/MCP/Server/Server.swift b/Sources/MCP/Server/Server.swift index 9d348d24..945698d9 100644 --- a/Sources/MCP/Server/Server.swift +++ b/Sources/MCP/Server/Server.swift @@ -337,7 +337,8 @@ public actor Server { } catch { // Only add errors to response for requests (notifications don't have responses) if case .request(let request) = item { - let mcpError = error as? MCPError ?? MCPError.internalError(error.localizedDescription) + let mcpError = + error as? MCPError ?? MCPError.internalError(error.localizedDescription) responses.append(AnyMethod.response(id: request.id, error: mcpError)) } } @@ -365,7 +366,9 @@ public actor Server { /// - request: The request to handle /// - sendResponse: Whether to send the response immediately (true) or return it (false) /// - Returns: The response when sendResponse is false - private func handleRequest(_ request: Request, sendResponse: Bool = true) async throws -> Response? { + private func handleRequest(_ request: Request, sendResponse: Bool = true) + async throws -> Response? + { // Check if this is a pre-processed error request (empty method) if request.method.isEmpty && !sendResponse { // This is a placeholder for an invalid request that couldn't be parsed in batch mode @@ -478,12 +481,6 @@ public actor Server { throw MCPError.invalidRequest("Server is already initialized") } - // Validate protocol version - guard Version.latest == params.protocolVersion else { - throw MCPError.invalidRequest( - "Unsupported protocol version: \(params.protocolVersion)") - } - // Call initialization hook if registered if let hook = initializeHook { try await hook(params.clientInfo, params.capabilities)