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

`subscriptions/listen` accepts a request missing the required `notifications` field

Open cclabadmin opened this issue 5 months ago • 2 comments

Describe the bug

When a subscriptions/listen request omits the required notifications field, the Go SDK server does not reject the request with an error. Instead, the request is handled as if it specified an empty subscription set: the server sends a notifications/subscriptions/acknowledged notification with notifications: {} and opens a long-lived stream with zero active subscriptions.

The 2026-07-28 draft schema defines notifications as a required field on SubscriptionsListenRequestParams:

export interface SubscriptionsListenRequestParams extends RequestParams {
  notifications: SubscriptionFilter;
}

A request that omits a required field in params should receive a JSON-RPC error (for example, -32602 Invalid params), rather than being treated as a valid stream-establishment request.

Environment tested:

  • main snapshot from 2026-06-28: 65ece5964304528e7568507e2b17351824ef73fc
  • Server used: conformance/everything-server
  • Transport: stdio

To Reproduce

Steps to reproduce the behavior:

  1. Start the Go SDK stdio server.
  2. Send a server/discover request using the 2026-07-28 per-request _meta fields.
  3. Send a subscriptions/listen request with _meta but without the notifications field:
{"jsonrpc":"2.0","id":1001,"method":"subscriptions/listen","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientInfo":{"name":"repro","version":"0.1.0"},"io.modelcontextprotocol/clientCapabilities":{}}}}
  1. Observe the server response.

Expected behavior

The server should reject the request with a JSON-RPC error indicating that the required notifications field is missing from params.

Observed behavior

The server sends a notifications/subscriptions/acknowledged notification with an empty subscription set:

{"jsonrpc":"2.0","method":"notifications/subscriptions/acknowledged","params":{"_meta":{"io.modelcontextprotocol/subscriptionId":1001},"notifications":{}}}

The stream stays open with zero subscriptions until the process exits. The server remains healthy (post-health server/discover succeeds).

Additional context

In mcp/protocol.go, SubscriptionsListenParams declares Notifications as a non-pointer value type:

type SubscriptionsListenParams struct {
    Meta          `json:"_meta,omitempty"`
    Notifications NotificationSubscriptions `json:"notifications"`
}

Because Notifications is a non-pointer struct field, the decoded request contains the zero value NotificationSubscriptions{} when the field is absent from the JSON input. The handler then passes that value to allowedSubscriptions:

func (s *Server) subscriptionsListen(ctx context.Context, req *SubscriptionsListenRequest) (*emptyResult, error) {
    // ...
    allowed := s.allowedSubscriptions(req.Params.Notifications)  // zero-value {} accepted

The allowedSubscriptions function processes the empty struct, returns an empty filter, and the handler proceeds to send the acknowledgement notification with notifications: {}.

cclabadmin avatar Jun 30 '26 09:06 cclabadmin

I am interested in contributing to this bug

rahulkrishnanfs avatar Jul 04 '26 04:07 rahulkrishnanfs

@cclabadmin thank you for reporting, the bug has been fixed in PR #1050

guglielmo-san avatar Jul 07 '26 09:07 guglielmo-san