Skip to content

Commit 40e8b47

Browse files
authored
Merge pull request #71 from sambostock/curl-headers
Include response headers in `curl` examples
2 parents c806e1e + 9a85975 commit 40e8b47

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

examples/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,18 @@ You can also test SSE functionality manually using cURL:
110110
```bash
111111
SESSION_ID=$(curl -D - -s -o /dev/null -X POST http://localhost:9393 \
112112
-H "Content-Type: application/json" \
113-
-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')
113+
-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')
114114
```
115115

116116
2. Connect to SSE stream (in one terminal):
117117
```bash
118-
curl -N -H "Mcp-Session-Id: $SESSION_ID" http://localhost:9393
118+
curl -i -N -H "Mcp-Session-Id: $SESSION_ID" http://localhost:9393
119119
```
120120

121121
3. Trigger notifications (in another terminal):
122122
```bash
123123
# Send immediate notification
124-
curl -X POST http://localhost:9393 \
124+
curl -i -X POST http://localhost:9393 \
125125
-H "Content-Type: application/json" \
126126
-H "Mcp-Session-Id: $SESSION_ID" \
127127
-d '{"jsonrpc":"2.0","method":"tools/call","id":2,"params":{"name":"notification_tool","arguments":{"message":"Hello from cURL!"}}}'
@@ -152,22 +152,22 @@ The HTTP server implements the MCP Streamable HTTP transport protocol:
152152

153153
Initialize a session:
154154
```bash
155-
curl -X POST http://localhost:9292 \
155+
curl -i -X POST http://localhost:9292 \
156156
-H "Content-Type: application/json" \
157157
-d '{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}'
158158
```
159159

160160
List tools (using the session ID from initialization):
161161
```bash
162-
curl -X POST http://localhost:9292 \
162+
curl -i -X POST http://localhost:9292 \
163163
-H "Content-Type: application/json" \
164164
-H "Mcp-Session-Id: YOUR_SESSION_ID" \
165165
-d '{"jsonrpc":"2.0","method":"tools/list","id":2}'
166166
```
167167

168168
Call a tool:
169169
```bash
170-
curl -X POST http://localhost:9292 \
170+
curl -i -X POST http://localhost:9292 \
171171
-H "Content-Type: application/json" \
172172
-H "Mcp-Session-Id: YOUR_SESSION_ID" \
173173
-d '{"jsonrpc":"2.0","method":"tools/call","id":3,"params":{"name":"ExampleTool","arguments":{"a":5,"b":3}}}'

examples/http_server.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def template(args, server_context:)
156156
puts "Starting MCP HTTP server on http://localhost:9292"
157157
puts "Use POST requests to initialize and send JSON-RPC commands"
158158
puts "Example initialization:"
159-
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"}}}\''
159+
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"}}}\''
160160
puts ""
161161
puts "The server will return a session ID in the Mcp-Session-Id header."
162162
puts "Use this session ID for subsequent requests."

examples/streamable_http_server.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,20 +147,20 @@ def call(message:, delay: 0)
147147
puts "Testing SSE:"
148148
puts ""
149149
puts "1. Initialize session:"
150-
puts ' curl -X POST http://localhost:9393 -H "Content-Type: application/json" \\'
150+
puts ' curl -i -X POST http://localhost:9393 -H "Content-Type: application/json" \\'
151151
puts ' -d \'{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"sse-test","version":"1.0"}}}\''
152152
puts ""
153153
puts "2. Connect SSE stream (use the session ID from step 1):"
154-
puts ' curl -N -H "Mcp-Session-Id: YOUR_SESSION_ID" http://localhost:9393'
154+
puts ' curl -i -N -H "Mcp-Session-Id: YOUR_SESSION_ID" http://localhost:9393'
155155
puts ""
156156
puts "3. In another terminal, test tools (responses will be sent via SSE if stream is active):"
157157
puts ""
158158
puts " Echo tool:"
159-
puts ' curl -X POST http://localhost:9393 -H "Content-Type: application/json" -H "Mcp-Session-Id: YOUR_SESSION_ID" \\'
159+
puts ' curl -i -X POST http://localhost:9393 -H "Content-Type: application/json" -H "Mcp-Session-Id: YOUR_SESSION_ID" \\'
160160
puts ' -d \'{"jsonrpc":"2.0","method":"tools/call","id":2,"params":{"name":"echo","arguments":{"message":"Hello SSE!"}}}\''
161161
puts ""
162162
puts " Notification tool (with 2 second delay):"
163-
puts ' curl -X POST http://localhost:9393 -H "Content-Type: application/json" -H "Mcp-Session-Id: YOUR_SESSION_ID" \\'
163+
puts ' curl -i -X POST http://localhost:9393 -H "Content-Type: application/json" -H "Mcp-Session-Id: YOUR_SESSION_ID" \\'
164164
puts ' -d \'{"jsonrpc":"2.0","method":"tools/call","id":3,"params":{"name":"notification_tool","arguments":{"message":"Hello SSE!", "delay": 2}}}\''
165165
puts ""
166166
puts "Note: When an SSE stream is active, tool responses will appear in the SSE stream and the POST request will return {\"accepted\": true}"

0 commit comments

Comments
 (0)