Skip to content

Fix default handler return values to comply with MCP spec#247

Merged
koic merged 1 commit intomodelcontextprotocol:mainfrom
koic:fix_default_handler_return_values
Mar 1, 2026
Merged

Fix default handler return values to comply with MCP spec#247
koic merged 1 commit intomodelcontextprotocol:mainfrom
koic:fix_default_handler_return_values

Conversation

@koic
Copy link
Member

@koic koic commented Feb 28, 2026

Motivation and Context

The no-op handlers for completion/complete, resources/subscribe, and resources/unsubscribe returned nil.
When a client accesses the expected response structure (e.g., result[:completion][:values]), a nil result raises NoMethodError.

The MCP spec requires specific response structures even for no-op handlers. Returning spec-compliant defaults ensures that clients receive valid responses without requiring servers to explicitly override each handler.

completion/complete now returns { completion: { values: [], hasMore: false } }.
ref: https://modelcontextprotocol.io/specification/2025-11-25/server/utilities/completion

resources/subscribe and resources/unsubscribe now return {} (empty result). ref: https://modelcontextprotocol.io/specification/2025-11-25/server/resources#subscriptions

How Has This Been Tested?

Added a repro test to verify the fix and prevent regression.

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

The no-op handlers for `completion/complete`, `resources/subscribe`,
and `resources/unsubscribe` returned `nil`.
When a client accesses the expected response structure (e.g., `result[:completion][:values]`),
a `nil` result raises `NoMethodError`.

The MCP spec requires specific response structures even for no-op handlers.
Returning spec-compliant defaults ensures that clients receive valid responses without
requiring servers to explicitly override each handler.

`completion/complete` now returns `{ completion: { values: [], hasMore: false } }`.
ref: https://modelcontextprotocol.io/specification/2025-11-25/server/utilities/completion

`resources/subscribe` and `resources/unsubscribe` now return `{}` (empty result).
ref: https://modelcontextprotocol.io/specification/2025-11-25/server/resources#subscriptions
@koic koic merged commit 200826c into modelcontextprotocol:main Mar 1, 2026
10 checks passed
@koic koic deleted the fix_default_handler_return_values branch March 1, 2026 08:23
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.

2 participants