mcp: Allow registration of custom JSON-RPC methods#956
Conversation
… with type safety
…server test files
maciej-kisiel
left a comment
There was a problem hiding this comment.
Adding @jba who was responding in similar discussions regarding custom notifications. He has deeper understanding than me.
| return serverMethodInfos | ||
| } | ||
| infos := make(map[string]methodInfo, len(serverMethodInfos)+len(cs.client.customSendMethods)) | ||
| maps.Copy(infos, serverMethodInfos) |
There was a problem hiding this comment.
It feels a bit unnecessary to construct the map on every call. Maybe it's worth moving the source of truth map containing all methods under an appropriate type (Client?).
| defer c.mu.Unlock() | ||
| c.customSendMethods[method] = mi | ||
|
|
||
| return func(ctx context.Context, cs *ClientSession, params P) (R, error) { |
There was a problem hiding this comment.
I'm not sure exposing this via a return value will cover all the use cases. Most of the users of this will probably be extensions, which will do the registration for the developer. Not sure how easy it will be to propagate this.
| return nil, err | ||
| } | ||
| transport.connection.server = server | ||
| transport.connection.toolLookup = server.getServerTool |
There was a problem hiding this comment.
Nit: after this we could remove the toolLookup field and use the server.
|
@guglielmo-san Hi, thanks for handling this issue! |
| } | ||
| infos := make(map[string]methodInfo, len(serverMethodInfos)+len(cs.client.customSendMethods)) | ||
| maps.Copy(infos, serverMethodInfos) | ||
| maps.Copy(infos, cs.client.customSendMethods) |
There was a problem hiding this comment.
we should probably disallow to override the standard methods
| } | ||
| infos := make(map[string]methodInfo, len(serverMethodInfos)+len(s.customMethods)) | ||
| maps.Copy(infos, serverMethodInfos) | ||
| maps.Copy(infos, s.customMethods) |
|
Hi @guglielmo-san, thanks a lot for putting this together — really appreciate the work here. 🙏 Wanted to gently check in on where this stands. Custom JSON-RPC method support is starting to become a blocker for a growing set of MCP extensions: the Skills-over-MCP WG, for example, is speccing a It looks like there are a few open review items from @yarolegovich and @maciej-kisiel (guarding against overriding standard methods, the Totally understand if you've been busy — is there anything we can do to help move this along? I'm happy to pitch in on the merge conflicts or any of the outstanding review feedback if that would lighten the load. Just let me know what would be most useful. (cc @jba in case there's a preferred direction on the custom-method API the WG should design around.) |
Description
This PR introduces support for custom (non-standard) JSON-RPC methods in the MCP Go SDK.
This feature enables servers to handle arbitrary JSON-RPC methods and clients to invoke them, all while maintaining full type safety and integrating seamlessly with the SDK's existing middleware and session management.
Fixes #954