Skip to content

[Doc] Fix Rails controller example to return 202 for notifications#252

Open
koic wants to merge 1 commit intomodelcontextprotocol:mainfrom
koic:fix_rails_controller_example_to_return_202_for_notifications
Open

[Doc] Fix Rails controller example to return 202 for notifications#252
koic wants to merge 1 commit intomodelcontextprotocol:mainfrom
koic:fix_rails_controller_example_to_return_202_for_notifications

Conversation

@koic
Copy link
Member

@koic koic commented Mar 5, 2026

Motivation and Context

The previous example used Server#handle_json directly, which does not control HTTP status codes. Notifications such as notifications/initialized require 202 Accepted per the MCP spec, but the example always returned 200.

Use StreamableHTTPTransport#handle_request instead, which returns the correct HTTP status code for each request type.

Closes #158

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 previous example used `Server#handle_json` directly, which does not control HTTP status codes.
Notifications such as `notifications/initialized` require 202 Accepted per the MCP spec,
but the example always returned 200.

Use `StreamableHTTPTransport#handle_request` instead, which returns the correct HTTP status code
for each request type.

- https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#sending-messages-to-the-server
- https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#sending-messages-to-the-server

Closes modelcontextprotocol#158
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.

Rails controller example doesn't return 202 on notifications/initialized

1 participant