@@ -126,7 +126,6 @@ class McpController < ActionController::API
126126 )
127127 # Since the `MCP-Session-Id` is not shared across requests, `stateless: true` is set.
128128 transport = MCP ::Server ::Transports ::StreamableHTTPTransport .new (server, stateless: true )
129- server.transport = transport
130129 status, headers, body = transport.handle_request(request)
131130
132131 render(json: body.first, status: status, headers: headers)
@@ -821,7 +820,61 @@ This enables servers to leverage the client's LLM capabilities without needing d
821820- ** Tool Support** : When using tools in sampling requests, clients must declare ` sampling.tools ` capability
822821- ** Human-in-the-Loop** : Clients can implement user approval before forwarding requests to LLMs
823822
824- ** Using Sampling in Tools:**
823+ ** Usage Example (Stdio transport):**
824+
825+ ` Server#create_sampling_message ` is for single-client transports (e.g., ` StdioTransport ` ).
826+ For multi-client transports (e.g., ` StreamableHTTPTransport ` ), use ` server_context.create_sampling_message ` inside tools instead,
827+ which routes the request to the correct client session.
828+
829+ ``` ruby
830+ server = MCP ::Server .new (name: " my_server" )
831+ transport = MCP ::Server ::Transports ::StdioTransport .new (server)
832+ ```
833+
834+ Client must declare sampling capability during initialization.
835+ This happens automatically when the client connects.
836+
837+ ``` ruby
838+ result = server.create_sampling_message(
839+ messages: [
840+ { role: " user" , content: { type: " text" , text: " What is the capital of France?" } }
841+ ],
842+ max_tokens: 100 ,
843+ system_prompt: " You are a helpful assistant." ,
844+ temperature: 0.7
845+ )
846+ ```
847+
848+ Result contains the LLM response:
849+
850+ ``` ruby
851+ {
852+ role: " assistant" ,
853+ content: { type: " text" , text: " The capital of France is Paris." },
854+ model: " claude-3-sonnet-20240307" ,
855+ stopReason: " endTurn"
856+ }
857+ ```
858+
859+ ** Parameters:**
860+
861+ Required:
862+
863+ - ` messages: ` (Array) - Array of message objects with ` role ` and ` content `
864+ - ` max_tokens: ` (Integer) - Maximum tokens in the response
865+
866+ Optional:
867+
868+ - ` system_prompt: ` (String) - System prompt for the LLM
869+ - ` model_preferences: ` (Hash) - Model selection preferences (e.g., ` { intelligencePriority: 0.8 } ` )
870+ - ` include_context: ` (String) - Context inclusion: ` "none" ` , ` "thisServer" ` , or ` "allServers" ` (soft-deprecated)
871+ - ` temperature: ` (Float) - Sampling temperature
872+ - ` stop_sequences: ` (Array) - Sequences that stop generation
873+ - ` metadata: ` (Hash) - Additional metadata
874+ - ` tools: ` (Array) - Tools available to the LLM (requires ` sampling.tools ` capability)
875+ - ` tool_choice: ` (Hash) - Tool selection mode (e.g., ` { mode: "auto" } ` )
876+
877+ ** Using Sampling in Tools (works with both Stdio and HTTP transports):**
825878
826879Tools that accept a ` server_context: ` parameter can call ` create_sampling_message ` on it.
827880The request is automatically routed to the correct client session.
@@ -1120,7 +1173,6 @@ For more details, see the [MCP Logging specification](https://modelcontextprotoc
11201173``` ruby
11211174server = MCP ::Server .new (name: " my_server" )
11221175transport = MCP ::Server ::Transports ::StdioTransport .new (server)
1123- server.transport = transport
11241176
11251177# The client first configures the logging level (on the client side):
11261178transport.send_request(
@@ -1174,8 +1226,6 @@ server = MCP::Server.new(name: "my_server")
11741226# Default Streamable HTTP - session oriented
11751227transport = MCP ::Server ::Transports ::StreamableHTTPTransport .new (server)
11761228
1177- server.transport = transport
1178-
11791229# When tools change, notify clients
11801230server.define_tool(name: " new_tool" ) { |** args | { result: " ok" } }
11811231server.notify_tools_list_changed
0 commit comments