Skip to content

Commit 8a97ceb

Browse files
authored
Merge pull request #252 from koic/fix_rails_controller_example_to_return_202_for_notifications
[Doc] Fix Rails controller example to return 202 for notifications
2 parents 5d8f1bd + 7e0a339 commit 8a97ceb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff 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
243243
requests.
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
261266
end
262267
```

0 commit comments

Comments
 (0)