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
This commit is contained in:
commit
8a97cebc33
1 changed files with 9 additions and 4 deletions
13
README.md
13
README.md
|
|
@ -242,11 +242,12 @@ When added to a Rails controller on a route that handles POST requests, your ser
|
|||
[Streamable HTTP](https://modelcontextprotocol.io/specification/latest/basic/transports#streamable-http) transport
|
||||
requests.
|
||||
|
||||
You can use the `Server#handle_json` method to handle requests.
|
||||
You can use `StreamableHTTPTransport#handle_request` to handle requests with proper HTTP
|
||||
status codes (e.g., 202 Accepted for notifications).
|
||||
|
||||
```ruby
|
||||
class ApplicationController < ActionController::Base
|
||||
def index
|
||||
class McpController < ActionController::Base
|
||||
def create
|
||||
server = MCP::Server.new(
|
||||
name: "my_server",
|
||||
title: "Example Server Display Name",
|
||||
|
|
@ -256,7 +257,11 @@ class ApplicationController < ActionController::Base
|
|||
prompts: [MyPrompt],
|
||||
server_context: { user_id: current_user.id },
|
||||
)
|
||||
render(json: server.handle_json(request.body.read))
|
||||
transport = MCP::Server::Transports::StreamableHTTPTransport.new(server)
|
||||
server.transport = transport
|
||||
status, headers, body = transport.handle_request(request)
|
||||
|
||||
render(json: body.first, status: status, headers: headers)
|
||||
end
|
||||
end
|
||||
```
|
||||
|
|
|
|||
Loading…
Reference in a new issue