Skip to content

Commit 21833b9

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 21833b9

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/ModelContextProtocol/Shared/McpSession.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,17 @@ 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 = 400
309+
},
310+
}, cancellationToken).ConfigureAwait(false);
311+
return null;
302312
}
303313

304314
LogRequestHandlerCalled(EndpointName, request.Method);
@@ -764,4 +774,4 @@ private static TimeSpan GetElapsed(long startingTimestamp) =>
764774

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

0 commit comments

Comments
 (0)