go-sdk icon indicating copy to clipboard operation
go-sdk copied to clipboard

mcp: Allow registration of custom JSON-RPC methods

Open guglielmo-san opened this issue 6 months ago • 3 comments

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.

  • Server-Side Registration: Added AddReceivingCustomMethod to allow servers to register handlers for custom methods. Incoming requests are automatically unmarshaled into user-defined parameter structs.
  • Client-Side Calling: Added AddSendingCustomMethod which returns a strongly-typed caller function that clients can use to invoke custom methods and receive strongly-typed results.
  • Helper Structs: Provided ParamsBase and ResultBase for users to embed in their custom structs. This allows them to easily satisfy the SDK's internal Params and Result interfaces.

Fixes #954

guglielmo-san avatar May 13 '26 12:05 guglielmo-san

@guglielmo-san Hi, thanks for handling this issue! I want to add one more comment here, that sending custom method in server, and receiving custom method in client should be also needed for completeness. (supporting bi directional use cases)

jeongukjae avatar May 28 '26 13:05 jeongukjae

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 resources/directory/read method (SEP-2640), and without a way to register non-standard methods in the Go SDK we can't build a Go skills SDK on top of it. I expect more extensions will hit the same wall going forward, so landing some form of this would unblock quite a bit.

It looks like there are a few open review items from @yarolegovich and @maciej-kisiel (guarding against overriding standard methods, the s.mu access, and the API shape for extension-driven registration), plus the branch has drifted into conflicts with main.

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

sambhav avatar Jun 09 '26 20:06 sambhav

@sambhav there is an open discussion on the issue, you can add your thoughts/reasons to support custom methods there

guglielmo-san avatar Jun 10 '26 09:06 guglielmo-san

the Skills-over-MCP WG, for example, is speccing a resources/directory/read method (SEP-2640), and without a way to register non-standard methods in the Go SDK we can't build a Go skills SDK on top of it.

This is my main point of confusion. Why is anyone but the maintainers of this repo building a Go SDK? If you did want to build your own SDK, why wouldn't you fork this repo? If you're building an upcoming feature, why wouldn't that be a PR for this repo? If the feature is still unaccepted or experimental, you could provide a PR gated by a build tag.

What am I missing?

jba avatar Jun 22 '26 17:06 jba

@guglielmo-san thanks for the merge, there are still a few ergonomic/syntactic things missing that would be nice IMO and as @jeongukjae mentioned, for the sake of completeness we are missing notifications and also client side extensions which allow for extensions similar to roots or sampling.

Happy to do it as a follow up.

sambhav avatar Jun 25 '26 23:06 sambhav