feat(mcp): add ServerSession.Notify for custom notification methods#898
feat(mcp): add ServerSession.Notify for custom notification methods#898andylbrummer wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
Adds a public Notify method on ServerSession that allows sending notifications with arbitrary custom method names (e.g. notifications/claude/channel). The method validates that the method name starts with "notifications/" per the MCP specification before delegating to the underlying jsonrpc2 connection. This is needed for protocol extensions like Claude channels that use custom notification methods not covered by the built-in MCP notification types. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Please look at #745 and make sure you're solving the problem there. Also refer to that issue in the commit message. |
|
(No, you're not.) |
|
Use-case wise — for Claude Channels — I have exactly the same need. |
Add ServerSession.Notify for custom notification methods. Required for channel mode in agnt (pending upstream PR modelcontextprotocol#898). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
jba
left a comment
There was a problem hiding this comment.
You must go through middleware.
|
Note: we already have one PR for this: #844 It looks more advanced than this one. |
|
Following up. I created a fork of my own based on #844 so I could unblock my use-case. I have the send direction working end-to-end for Steps
Result:
@jba @findleyr: Is there a specific blocker on #844; multi-session broadcast from #745, label state, anything else? Name it and I'll work on it, or work with @ajuijas on it, so I don't have to maintain a fork. And does inbound dispatch need to be addressed, or can that be a follow-up? |
|
Thanks for the work, @mikeschinkel. A send-only solution isn't sufficient. There must be a story on the receive side. I don't think we need to broadcast these notifications to all sessions. Progress and log notifications are confined to the server session's client, so the custom ones can be too. We'd welcome your contribution, but I think it's clear we need a design sketch before proceeding. Please provide one on #745. Let's avoid continuing this discussion on this PR, and let's not write more code until we understand the solution. |
Summary
Adds a public
Notifymethod onServerSessionthat allows sendingnotifications with arbitrary custom method names (e.g.
notifications/claude/channel). The method validates that the methodname starts with
notifications/per the MCP specification beforedelegating to the underlying jsonrpc2 connection.
Motivation
The Go MCP SDK only exposes typed notification helpers (
NotifyProgress,SetLoggingLevel, etc.) for built-in MCP notification types. Protocolextensions (e.g. Claude's channel mode) need to send notifications with
custom method names that aren't part of the core MCP spec. Currently
there's no public API to do this —
handleNotify,getConn().Notify,and the sending method handler are all unexported.
Changes
(*ServerSession).Notify(ctx context.Context, method string, params any) errornotifications/prefixgetConn().Notify()which is the same path used byNotifyProgressand other built-in notification sendersTesting
The fork is used in production by agnt
with an end-to-end test that:
notifications/claude/channelwith structured paramsAlternatives Considered
custom notifications, but there's no way for the server to send them
without this method.
the abstraction boundary. A simple public method is cleaner.
🤖 Generated with Claude Code