Skip to content

Commit 92f7112

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 adb95c8 commit 92f7112

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/ModelContextProtocol/Shared/McpSession.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,17 @@ private async Task HandleRequest(JsonRpcRequest request, CancellationToken cance
282282
if (!_requestHandlers.TryGetValue(request.Method, out var handler))
283283
{
284284
_logger.NoHandlerFoundForRequest(EndpointName, request.Method);
285-
throw new McpException("The method does not exist or is not available.", ErrorCodes.MethodNotFound);
285+
await SendMessageAsync(new JsonRpcError
286+
{
287+
Id = request.Id,
288+
JsonRpc = "2.0",
289+
Error = new JsonRpcErrorDetail
290+
{
291+
Message = $"{EndpointName} lacks capability to do {request.Method}",
292+
Code = 400
293+
},
294+
}, cancellationToken).ConfigureAwait(false);
295+
return;
286296
}
287297

288298
_logger.RequestHandlerCalled(EndpointName, request.Method);
@@ -614,4 +624,4 @@ private static TimeSpan GetElapsed(long startingTimestamp) =>
614624
#else
615625
new((long)(s_timestampToTicks * (Stopwatch.GetTimestamp() - startingTimestamp)));
616626
#endif
617-
}
627+
}

0 commit comments

Comments
 (0)