Skip to content

feat: implement generic SendNotification method for Issue #745#844

Open
ajuijas wants to merge 1 commit intomodelcontextprotocol:mainfrom
ajuijas:feature/send-notification
Open

feat: implement generic SendNotification method for Issue #745#844
ajuijas wants to merge 1 commit intomodelcontextprotocol:mainfrom
ajuijas:feature/send-notification

Conversation

@ajuijas
Copy link

@ajuijas ajuijas commented Mar 15, 2026

The Model Context Protocol (MCP) Go SDK's middleware stack currently validates outbound notifications against a predefined set of protocol methods. This behavior prevents protocol extensions (such as ide/diffAccepted or other custom vendor-specific notifications) from being sent successfully, as they are rejected by the internal method validation logic.

This change modifies the mcp package to support sending arbitrary JSON-RPC notifications by exposing a generic SendNotification method on both ServerSession and ClientSession.

Proposed Changes:

  • Middleware Bypass: Implemented a strategy in defaultSendingMethodHandler that intercepts an internal x-notifications/ prefix, allowing custom methods to bypass strict validation checks while still utilizing the SDK's underlying connection and middleware flow.
  • Generic Parameter Wrapper: Added customNotificationParams to safely wrap any payload types, ensuring they satisfy the internal Params interface and serialize correctly to JSON.
  • Session API Extensions: Exposed SendNotification(ctx, method, params) on both ClientSession and ServerSession.
  • Testing: Added integration tests in server_test.go and client_test.go to verify end-to-end notification delivery for both server-to-client and client-to-server flows.

Fixes #745

The SDK's middleware stack currently validates outbound notifications
against a known set of MCP spec notifications, preventing protocol
extensions (e.g., 'ide/diffAccepted') from being sent successfully.

This change allows arbitrary JSON-RPC notifications to bypass the
strict method checks by internally intercepting an 'x-notifications/'
prefix. The SendNotification method is now exposed on both ServerSession
and ClientSession to wrap and serialize user-provided parameters.

Fixes modelcontextprotocol#745

Signed-off-by: Ijas Ahammed <ijas.ahmd.ap@gmail.com>
@maciej-kisiel
Copy link
Contributor

Hi @ajuijas, the issue #745 hasn't been marked as "ready for work" yet, since the decision that we want or need this functionality hasn't been made yet. Do you have any personal use cases that would require this functionality? If so, I would encourage you to add to the discussion on the issue first, before we dive into implementation. Thanks!

@ajuijas
Copy link
Author

ajuijas commented Mar 16, 2026

Hi! I don't have a personal use case for this. I was just bored and looking for open source issues to help with, so I decided to try fixing this one (I wasn't paying attention to the "ready for work" tag 😪).
Please let me know if you decide to move forward with the implementation! Thanks 🙏.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose generic SendNotification on ServerSession for custom protocol extensions

2 participants