Skip to content

resources/subscribe custom handler return value is discarded (always responds {}) #508

Description

@seunghan91

Problem

Server#resources_subscribe_handler / resources_unsubscribe_handler accept a block, but the dispatch path invokes the handler and then unconditionally responds with an empty object — the handler's return value is discarded (lib/mcp/server.rb:622-625 at ref f0c9665):

when Methods::RESOURCES_SUBSCRIBE, Methods::RESOURCES_UNSUBSCRIBE
  validate_resource_subscription_params!(params)
  dispatch_optional_context_handler(@handlers[method], params, ...)
  {}

So a server cannot include anything in the subscribe response (e.g. a subscription identifier for later correlation, or advisory metadata). The handler is effectively side-effect-only, which is surprising given other handlers' return values shape the response.

If this is intentional (the spec's resources/subscribe result is an empty object), a doc note on resources_subscribe_handler saying the return value is ignored would prevent the surprise — we hit this while migrating from a hand-rolled server whose subscribe response carried a subscriptionId, and pinned the difference in our compatibility specs after discovering the discard empirically.

Context

Production MCP surface on Rails, recently cut over to this gem. Related prior contribution: #493.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions