From 7a2043b49c48b561a2c30424cdbcda768fa7b9e2 Mon Sep 17 00:00:00 2001 From: Sam Bostock Date: Tue, 24 Jun 2025 11:21:27 -0400 Subject: [PATCH 1/3] Add space before pipe --- examples/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/README.md b/examples/README.md index 72a71544..d6c7d4ef 100644 --- a/examples/README.md +++ b/examples/README.md @@ -110,7 +110,7 @@ You can also test SSE functionality manually using cURL: ```bash SESSION_ID=$(curl -D - -s -o /dev/null -X POST http://localhost:9393 \ -H "Content-Type: application/json" \ - -d '{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"curl-test","version":"1.0"}}}' |grep -i "Mcp-Session-Id:" | cut -d' ' -f2- | tr -d '\r') + -d '{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"curl-test","version":"1.0"}}}' | grep -i "Mcp-Session-Id:" | cut -d' ' -f2- | tr -d '\r') ``` 2. Connect to SSE stream (in one terminal): From cccb7494facb92ead3ae363fa230403bbef0c524 Mon Sep 17 00:00:00 2001 From: Sam Bostock Date: Tue, 24 Jun 2025 11:22:46 -0400 Subject: [PATCH 2/3] Log headers in curl initialize requests The user needs the `mcp-session-id` header, so we should log headers. --- examples/http_server.rb | 2 +- examples/streamable_http_server.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/http_server.rb b/examples/http_server.rb index 350875cd..f460db3f 100644 --- a/examples/http_server.rb +++ b/examples/http_server.rb @@ -156,7 +156,7 @@ def template(args, server_context:) puts "Starting MCP HTTP server on http://localhost:9292" puts "Use POST requests to initialize and send JSON-RPC commands" puts "Example initialization:" -puts ' curl -X POST http://localhost:9292 -H "Content-Type: application/json" -d \'{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}\'' +puts ' curl -i -X POST http://localhost:9292 -H "Content-Type: application/json" -d \'{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}\'' puts "" puts "The server will return a session ID in the Mcp-Session-Id header." puts "Use this session ID for subsequent requests." diff --git a/examples/streamable_http_server.rb b/examples/streamable_http_server.rb index 1c0a286f..5c8cfb4e 100644 --- a/examples/streamable_http_server.rb +++ b/examples/streamable_http_server.rb @@ -147,7 +147,7 @@ def call(message:, delay: 0) puts "Testing SSE:" puts "" puts "1. Initialize session:" -puts ' curl -X POST http://localhost:9393 -H "Content-Type: application/json" \\' +puts ' curl -i -X POST http://localhost:9393 -H "Content-Type: application/json" \\' puts ' -d \'{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"sse-test","version":"1.0"}}}\'' puts "" puts "2. Connect SSE stream (use the session ID from step 1):" From 9a85975d12c92c4fc321c309cec5ae51fb36daf1 Mon Sep 17 00:00:00 2001 From: Sam Bostock Date: Tue, 24 Jun 2025 11:23:33 -0400 Subject: [PATCH 3/3] Log headers in all curl examples The examples showcase to the user how the server works, so it makes sense to include headers to show the full picture. --- examples/README.md | 10 +++++----- examples/streamable_http_server.rb | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/README.md b/examples/README.md index d6c7d4ef..429adcae 100644 --- a/examples/README.md +++ b/examples/README.md @@ -115,13 +115,13 @@ SESSION_ID=$(curl -D - -s -o /dev/null -X POST http://localhost:9393 \ 2. Connect to SSE stream (in one terminal): ```bash -curl -N -H "Mcp-Session-Id: $SESSION_ID" http://localhost:9393 +curl -i -N -H "Mcp-Session-Id: $SESSION_ID" http://localhost:9393 ``` 3. Trigger notifications (in another terminal): ```bash # Send immediate notification -curl -X POST http://localhost:9393 \ +curl -i -X POST http://localhost:9393 \ -H "Content-Type: application/json" \ -H "Mcp-Session-Id: $SESSION_ID" \ -d '{"jsonrpc":"2.0","method":"tools/call","id":2,"params":{"name":"notification_tool","arguments":{"message":"Hello from cURL!"}}}' @@ -152,14 +152,14 @@ The HTTP server implements the MCP Streamable HTTP transport protocol: Initialize a session: ```bash -curl -X POST http://localhost:9292 \ +curl -i -X POST http://localhost:9292 \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}' ``` List tools (using the session ID from initialization): ```bash -curl -X POST http://localhost:9292 \ +curl -i -X POST http://localhost:9292 \ -H "Content-Type: application/json" \ -H "Mcp-Session-Id: YOUR_SESSION_ID" \ -d '{"jsonrpc":"2.0","method":"tools/list","id":2}' @@ -167,7 +167,7 @@ curl -X POST http://localhost:9292 \ Call a tool: ```bash -curl -X POST http://localhost:9292 \ +curl -i -X POST http://localhost:9292 \ -H "Content-Type: application/json" \ -H "Mcp-Session-Id: YOUR_SESSION_ID" \ -d '{"jsonrpc":"2.0","method":"tools/call","id":3,"params":{"name":"ExampleTool","arguments":{"a":5,"b":3}}}' diff --git a/examples/streamable_http_server.rb b/examples/streamable_http_server.rb index 5c8cfb4e..5b124b8b 100644 --- a/examples/streamable_http_server.rb +++ b/examples/streamable_http_server.rb @@ -151,16 +151,16 @@ def call(message:, delay: 0) puts ' -d \'{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"sse-test","version":"1.0"}}}\'' puts "" puts "2. Connect SSE stream (use the session ID from step 1):" -puts ' curl -N -H "Mcp-Session-Id: YOUR_SESSION_ID" http://localhost:9393' +puts ' curl -i -N -H "Mcp-Session-Id: YOUR_SESSION_ID" http://localhost:9393' puts "" puts "3. In another terminal, test tools (responses will be sent via SSE if stream is active):" puts "" puts " Echo tool:" -puts ' curl -X POST http://localhost:9393 -H "Content-Type: application/json" -H "Mcp-Session-Id: YOUR_SESSION_ID" \\' +puts ' curl -i -X POST http://localhost:9393 -H "Content-Type: application/json" -H "Mcp-Session-Id: YOUR_SESSION_ID" \\' puts ' -d \'{"jsonrpc":"2.0","method":"tools/call","id":2,"params":{"name":"echo","arguments":{"message":"Hello SSE!"}}}\'' puts "" puts " Notification tool (with 2 second delay):" -puts ' curl -X POST http://localhost:9393 -H "Content-Type: application/json" -H "Mcp-Session-Id: YOUR_SESSION_ID" \\' +puts ' curl -i -X POST http://localhost:9393 -H "Content-Type: application/json" -H "Mcp-Session-Id: YOUR_SESSION_ID" \\' puts ' -d \'{"jsonrpc":"2.0","method":"tools/call","id":3,"params":{"name":"notification_tool","arguments":{"message":"Hello SSE!", "delay": 2}}}\'' puts "" puts "Note: When an SSE stream is active, tool responses will appear in the SSE stream and the POST request will return {\"accepted\": true}"