Skip to content

Commit 91959fa

Browse files
committed
Handle requests for capability, when capability not present
Will also lower log level from err to wrn Scenario: ex: Claude Desktop polls for `/resources/list` even though `resources` is missing from the `capabilities`
1 parent f2ae0ca commit 91959fa

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/ModelContextProtocol/Shared/McpSession.cs

+13-2
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,18 @@ private void HandleMessageWithId(JsonRpcMessage message, JsonRpcMessageWithId me
298298
if (!_requestHandlers.TryGetValue(request.Method, out var handler))
299299
{
300300
LogNoHandlerFoundForRequest(EndpointName, request.Method);
301-
throw new McpException($"Method '{request.Method}' is not available.", McpErrorCode.MethodNotFound);
301+
await SendMessageAsync(new JsonRpcError
302+
{
303+
Id = request.Id,
304+
JsonRpc = "2.0",
305+
Error = new JsonRpcErrorDetail
306+
{
307+
Message = $"{EndpointName} lacks capability to do {request.Method}",
308+
Code = (int) McpErrorCode.MethodNotFound,
309+
},
310+
RelatedTransport = request.RelatedTransport
311+
}, cancellationToken).ConfigureAwait(false);
312+
return null;
302313
}
303314

304315
LogRequestHandlerCalled(EndpointName, request.Method);
@@ -764,4 +775,4 @@ private static TimeSpan GetElapsed(long startingTimestamp) =>
764775

765776
[LoggerMessage(Level = LogLevel.Trace, Message = "{EndpointName} sending message. Message: '{Message}'.")]
766777
private partial void LogSendingMessageSensitive(string endpointName, string message);
767-
}
778+
}

0 commit comments

Comments
 (0)