File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -242,11 +242,12 @@ When added to a Rails controller on a route that handles POST requests, your ser
242242[ Streamable HTTP] ( https://modelcontextprotocol.io/specification/latest/basic/transports#streamable-http ) transport
243243requests.
244244
245- You can use the ` Server#handle_json ` method to handle requests.
245+ You can use ` StreamableHTTPTransport#handle_request ` to handle requests with proper HTTP
246+ status codes (e.g., 202 Accepted for notifications).
246247
247248``` ruby
248- class ApplicationController < ActionController ::Base
249- def index
249+ class McpController < ActionController ::Base
250+ def create
250251 server = MCP ::Server .new (
251252 name: " my_server" ,
252253 title: " Example Server Display Name" ,
@@ -256,7 +257,11 @@ class ApplicationController < ActionController::Base
256257 prompts: [MyPrompt ],
257258 server_context: { user_id: current_user.id },
258259 )
259- render(json: server.handle_json(request.body.read))
260+ transport = MCP ::Server ::Transports ::StreamableHTTPTransport .new (server)
261+ server.transport = transport
262+ status, headers, body = transport.handle_request(request)
263+
264+ render(json: body.first, status: status, headers: headers)
260265 end
261266end
262267```
You can’t perform that action at this time.
0 commit comments