feat(mcp): add ServerSession.Notify for custom notification methods#898
Open
andylbrummer wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
feat(mcp): add ServerSession.Notify for custom notification methods#898andylbrummer wants to merge 1 commit intomodelcontextprotocol:mainfrom
andylbrummer 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>
Contributor
|
Please look at #745 and make sure you're solving the problem there. Also refer to that issue in the commit message. |
Contributor
|
(No, you're not.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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