Skip to content

Commit 800131f

Browse files
authored
Don't throw error if there's a protocol mismatch between client and server (#103)
1 parent d3f061d commit 800131f

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

Sources/MCP/Server/Server.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ public actor Server {
337337
} catch {
338338
// Only add errors to response for requests (notifications don't have responses)
339339
if case .request(let request) = item {
340-
let mcpError = error as? MCPError ?? MCPError.internalError(error.localizedDescription)
340+
let mcpError =
341+
error as? MCPError ?? MCPError.internalError(error.localizedDescription)
341342
responses.append(AnyMethod.response(id: request.id, error: mcpError))
342343
}
343344
}
@@ -365,7 +366,9 @@ public actor Server {
365366
/// - request: The request to handle
366367
/// - sendResponse: Whether to send the response immediately (true) or return it (false)
367368
/// - Returns: The response when sendResponse is false
368-
private func handleRequest(_ request: Request<AnyMethod>, sendResponse: Bool = true) async throws -> Response<AnyMethod>? {
369+
private func handleRequest(_ request: Request<AnyMethod>, sendResponse: Bool = true)
370+
async throws -> Response<AnyMethod>?
371+
{
369372
// Check if this is a pre-processed error request (empty method)
370373
if request.method.isEmpty && !sendResponse {
371374
// This is a placeholder for an invalid request that couldn't be parsed in batch mode
@@ -478,12 +481,6 @@ public actor Server {
478481
throw MCPError.invalidRequest("Server is already initialized")
479482
}
480483

481-
// Validate protocol version
482-
guard Version.latest == params.protocolVersion else {
483-
throw MCPError.invalidRequest(
484-
"Unsupported protocol version: \(params.protocolVersion)")
485-
}
486-
487484
// Call initialization hook if registered
488485
if let hook = initializeHook {
489486
try await hook(params.clientInfo, params.capabilities)

0 commit comments

Comments
 (0)