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

1 participant