[Doc] Update Rails controller example in README.md#299
Open
koic wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
[Doc] Update Rails controller example in README.md#299koic wants to merge 1 commit intomodelcontextprotocol:mainfrom
koic wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
9 tasks
atesgoral
previously approved these changes
Apr 5, 2026
The following two points have been updated: ## 1. Use ActionController::API in README controller example `ActionController::Base` includes CSRF protection which rejects POST requests without an authenticity token. MCP clients do not send CSRF tokens, so the controller example should inherit from `ActionController::API` instead. ## 2. Use `stateless: true` for `StreamableHTTPTransport.new` The controller creates a new transport per request, so the session stored on the previous transport is lost. Without `stateless: true`, the second request with `Mcp-Session-Id` returns 404 because the new transport has an empty session map. To share sessions via `Mcp-Session-Id` across requests, there are two approaches. One is persisting the transport in a class variable. The other is mounting the transport as a Rack app via modelcontextprotocol#263. Both approaches maintain sessions, so features that depend on `server_context` within the SDK (Progress, Sampling) work correctly. However, per-request user-specific context such as `server_context: { user_id: current_user.id }` cannot be passed since the server is shared across all requests.
45e5be4 to
17604be
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
The following two points have been updated:
1. Use ActionController::API in README controller example
ActionController::Baseincludes CSRF protection which rejects POST requests without an authenticity token. MCP clients do not send CSRF tokens, so the controller example should inherit fromActionController::APIinstead.2. Use
stateless: trueforStreamableHTTPTransport.newThe controller creates a new transport per request, so the session stored on the previous transport is lost. Without
stateless: true, the second request withMcp-Session-Idreturns 404 because the new transport has an empty session map.To share sessions via
Mcp-Session-Idacross requests, there are two approaches. One is persisting the transport in a class variable. The other is mounting the transport as a Rack app via #263.Both approaches maintain sessions, so features that depend on
server_contextwithin the SDK (Progress, Sampling) work correctly. However, per-request user-specific context such asserver_context: { user_id: current_user.id }cannot be passed since the server is shared across all requests.Types of changes
Checklist