Don't throw error if there's a protocol mismatch between client and server (#103)
This commit is contained in:
parent
d3f061dacd
commit
800131fb9c
1 changed files with 5 additions and 8 deletions
|
|
@ -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<AnyMethod>, sendResponse: Bool = true) async throws -> Response<AnyMethod>? {
|
||||
private func handleRequest(_ request: Request<AnyMethod>, sendResponse: Bool = true)
|
||||
async throws -> Response<AnyMethod>?
|
||||
{
|
||||
// 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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue