feat: add ignorable JSON-RPC methods support for both client and server#417
feat: add ignorable JSON-RPC methods support for both client and server#417tzolov wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
- Add ignorableJsonRpcMethods support to McpClientSession and McpServerSession - Implement request and notification filtering for specified methods - Add default ignorable methods: notifications/cancelled, notifications/stderr - Extend both client and server builders with ignorableJsonRpcMethods() methods - Support both List<String> and varargs configurations - Add comprehensive test coverage for client and server-side functionality - Maintain full backward compatibility with deprecated constructors - Log ignored methods as DEBUG for debugging visibility This feature allows both MCP clients and servers to gracefully handle unknown or unwanted JSON-RPC methods without generating errors, improving compatibility with various implementations and reducing log noise. Resolves modelcontextprotocol#416, modelcontextprotocol#377 Related to modelcontextprotocol#130 It provides a workaround until the `notification/cancelled` is supposed. Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
45b2b27 to
e3b999a
Compare
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
I think in the current form this PR does not address this. The mechanism introduced requires the JSON-RPC methods to be known and actually wanted. Have you considered an alternative mechanism, which I'd call "ignoreByDefault" accompanied by a mechanism for "disallowed methods", which would consist of a Well, I have a bit of an issue with requests though. For example, a server that accepts a request and returns no body makes the client wait forever? Or until timeout? What is the expected next step for the client? Depending on the transport it might consider the server as misbehaving. From the perspective of a client author, I'd expect to be told I'm sending something the server will not provide a response for. So this mechanism probably should only work for notifications. The other part of my proposal is about the disallowed methods, for which the user might explicitly specify that an error should be reported against the other party. |
|
I agree that we can not silence the request! |
This feature allows both MCP clients and servers to gracefully handle unknown or unwanted JSON-RPC methods without generating errors, improving compatibility with various implementations and reducing log noise.
Resolves #416, #377
Related to #130 It provides a workaround until the
notification/cancelledis supposed.Motivation and Context
This change addresses the need for more robust MCP communication by allowing clients and servers to ignore specific JSON-RPC methods rather than generating error responses. This is particularly useful for:
How Has This Been Tested?
AbstractMcpAsyncClientTests,AbstractMcpSyncClientTests)AbstractMcpAsyncServerTests,AbstractMcpSyncServerTests)McpClientSessionTests,McpServerSessionTests)Breaking Changes
This is a non-breaking change. All existing APIs remain unchanged, and the new functionality is opt-in through builder methods. Default behavior is preserved with a predefined list of commonly ignorable methods.
Types of changes
Checklist
Additional context
Implementation Details:
Utils.DEFAULT_IGNORABLE_JSON_RPC_METHODSconstant with default methods: "notifications/cancelled" and "notifications/stderr"