Skip to content

Commit ba89760

Browse files
committed
Handle requests for capabilty, when capability not present
ex: Claude Desktop polls for `/resources/list` even though `resources` is missing from the `capabilities`
1 parent adb95c8 commit ba89760

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/ModelContextProtocol/Shared/McpSession.cs

+16-2
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,27 @@ private void HandleMessageWithId(IJsonRpcMessage message, IJsonRpcMessageWithId
276276
_logger.NoRequestFoundForMessageWithId(EndpointName, messageWithId.Id.ToString());
277277
}
278278
}
279-
279+
public class BadRequest
280+
{
281+
public RequestId RequestId { get; init; }
282+
}
280283
private async Task HandleRequest(JsonRpcRequest request, CancellationToken cancellationToken)
281284
{
282285
if (!_requestHandlers.TryGetValue(request.Method, out var handler))
283286
{
284287
_logger.NoHandlerFoundForRequest(EndpointName, request.Method);
285-
throw new McpException("The method does not exist or is not available.", ErrorCodes.MethodNotFound);
288+
await _transport.SendMessageAsync(new JsonRpcNotification
289+
{
290+
JsonRpc = "2.0",
291+
Method = NotificationMethods.LoggingMessageNotification,
292+
Params = new JsonObject
293+
{
294+
["message"] = $"{EndpointName} lacks capability to do {request.Method}",
295+
["requestId"] = request.Id.ToString(),
296+
["type"] = nameof(BadRequest)
297+
}
298+
}, cancellationToken).ConfigureAwait(false);
299+
return;
286300
}
287301

288302
_logger.RequestHandlerCalled(EndpointName, request.Method);

0 commit comments

Comments
 (0)