@@ -56,43 +56,6 @@ It implements the Model Context Protocol specification, handling model context r
5656
5757### Usage
5858
59- > [ !IMPORTANT]
60- > ` MCP::Server::Transports::StreamableHTTPTransport ` stores session and SSE stream state in memory,
61- > so it must run in a single process. Use a single-process server (e.g., Puma with ` workers 0 ` ).
62- > Multi-process configurations (Unicorn, or Puma with ` workers > 0 ` ) fork separate processes that
63- > do not share memory, which breaks session management and SSE connections.
64- > Stateless mode (` stateless: true ` ) does not use sessions and works with any server configuration.
65-
66- #### Rails Controller
67-
68- When added to a Rails controller on a route that handles POST requests, your server will be compliant with non-streaming
69- [ Streamable HTTP] ( https://modelcontextprotocol.io/specification/latest/basic/transports#streamable-http ) transport
70- requests.
71-
72- You can use ` StreamableHTTPTransport#handle_request ` to handle requests with proper HTTP
73- status codes (e.g., 202 Accepted for notifications).
74-
75- ``` ruby
76- class McpController < ActionController ::Base
77- def create
78- server = MCP ::Server .new (
79- name: " my_server" ,
80- title: " Example Server Display Name" ,
81- version: " 1.0.0" ,
82- instructions: " Use the tools of this server as a last resort" ,
83- tools: [SomeTool , AnotherTool ],
84- prompts: [MyPrompt ],
85- server_context: { user_id: current_user.id },
86- )
87- transport = MCP ::Server ::Transports ::StreamableHTTPTransport .new (server)
88- server.transport = transport
89- status, headers, body = transport.handle_request(request)
90-
91- render(json: body.first, status: status, headers: headers)
92- end
93- end
94- ```
95-
9659#### Stdio Transport
9760
9861If you want to build a local command-line application, you can use the stdio transport:
@@ -140,6 +103,43 @@ $ ruby examples/stdio_server.rb
140103{"jsonrpc":"2.0","id":"3","method":"tools/call","params":{"name":"example_tool","arguments":{"message":"Hello"}}}
141104```
142105
106+ #### Rails Controller
107+
108+ When added to a Rails controller on a route that handles POST requests, your server will be compliant with non-streaming
109+ [ Streamable HTTP] ( https://modelcontextprotocol.io/specification/latest/basic/transports#streamable-http ) transport
110+ requests.
111+
112+ You can use ` StreamableHTTPTransport#handle_request ` to handle requests with proper HTTP
113+ status codes (e.g., 202 Accepted for notifications).
114+
115+ ``` ruby
116+ class McpController < ActionController ::Base
117+ def create
118+ server = MCP ::Server .new (
119+ name: " my_server" ,
120+ title: " Example Server Display Name" ,
121+ version: " 1.0.0" ,
122+ instructions: " Use the tools of this server as a last resort" ,
123+ tools: [SomeTool , AnotherTool ],
124+ prompts: [MyPrompt ],
125+ server_context: { user_id: current_user.id },
126+ )
127+ transport = MCP ::Server ::Transports ::StreamableHTTPTransport .new (server)
128+ server.transport = transport
129+ status, headers, body = transport.handle_request(request)
130+
131+ render(json: body.first, status: status, headers: headers)
132+ end
133+ end
134+ ```
135+
136+ > [ !IMPORTANT]
137+ > ` MCP::Server::Transports::StreamableHTTPTransport ` stores session and SSE stream state in memory,
138+ > so it must run in a single process. Use a single-process server (e.g., Puma with ` workers 0 ` ).
139+ > Multi-process configurations (Unicorn, or Puma with ` workers > 0 ` ) fork separate processes that
140+ > do not share memory, which breaks session management and SSE connections.
141+ > Stateless mode (` stateless: true ` ) does not use sessions and works with any server configuration.
142+
143143### Configuration
144144
145145The gem can be configured using the ` MCP.configure ` block:
0 commit comments