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.
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