Skip to content

Commit 962a9c9

Browse files
committed
clean up and docs fixes
1 parent 77352db commit 962a9c9

File tree

5 files changed

+99
-19
lines changed

5 files changed

+99
-19
lines changed

src/examples/README.md

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,43 @@ The server will start on port 3000. You can test the initialization and tool cal
2020

2121
```bash
2222
# Initialize the server and get the session ID from headers
23-
SESSION_ID=$(curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" \
24-
-d '{"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{}},"id":"1"}' \
23+
SESSION_ID=$(curl -X POST \
24+
-H "Content-Type: application/json" \
25+
-H "Accept: application/json" \
26+
-H "Accept: text/event-stream" \
27+
-d '{
28+
"jsonrpc": "2.0",
29+
"method": "initialize",
30+
"params": {
31+
"capabilities": {},
32+
"protocolVersion": "2025-03-26",
33+
"clientInfo": {
34+
"name": "test",
35+
"version": "1.0.0"
36+
}
37+
},
38+
"id": "1"
39+
}' \
2540
-i http://localhost:3000/mcp 2>&1 | grep -i "mcp-session-id" | cut -d' ' -f2 | tr -d '\r')
2641
echo "Session ID: $SESSION_ID"
2742

2843
# Call the greet tool using the saved session ID
29-
curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" \
44+
curl -X POST \
45+
-H "Content-Type: application/json" \
46+
-H "Accept: application/json" \
47+
-H "Accept: text/event-stream" \
3048
-H "mcp-session-id: $SESSION_ID" \
31-
-d '{"jsonrpc":"2.0","method":"mcp.call_tool","params":{"name":"greet","arguments":{"name":"World"}},"id":"2"}' \
49+
-d '{
50+
"jsonrpc": "2.0",
51+
"method": "tools/call",
52+
"params": {
53+
"name": "greet",
54+
"arguments": {
55+
"name": "World"
56+
}
57+
},
58+
"id": "2"
59+
}' \
3260
http://localhost:3000/mcp
3361
```
3462

@@ -52,10 +80,25 @@ The server will start on port 3000. You can test the initialization and tool lis
5280

5381
```bash
5482
# First initialize the server and save the session ID to a variable
55-
SESSION_ID=$(curl -X POST -H "Content-Type: application/json" -H "Accept: application/json, text/event-stream" \
56-
-d '{"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{}},"id":"1"}' \
83+
SESSION_ID=$(curl -X POST \
84+
-H "Content-Type: application/json" \
85+
-H "Accept: application/json" \
86+
-H "Accept: text/event-stream" \
87+
-d '{
88+
"jsonrpc": "2.0",
89+
"method": "initialize",
90+
"params": {
91+
"capabilities": {},
92+
"protocolVersion": "2025-03-26",
93+
"clientInfo": {
94+
"name": "test",
95+
"version": "1.0.0"
96+
}
97+
},
98+
"id": "1"
99+
}' \
57100
-i http://localhost:3000/mcp 2>&1 | grep -i "mcp-session-id" | cut -d' ' -f2 | tr -d '\r')
58-
echo "Session ID: $SESSION_ID"
101+
echo "Session ID: $SESSION_ID
59102
60103
# Then list tools using the saved session ID
61104
curl -X POST -H "Content-Type: application/json" -H "Accept: application/json, text/event-stream" \

src/examples/server/jsonResponseStreamableHttp.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,29 @@ function isInitializeRequest(body: unknown): boolean {
149149
// Start the server
150150
const PORT = 3000;
151151
app.listen(PORT, () => {
152-
console.log(`MCP Streamable HTTP Server with JSON responses listening on port ${PORT}`);
153-
console.log(`Server is running. Press Ctrl+C to stop.`);
154-
console.log(`Initialize with: curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{}},"id":"1"}' http://localhost:${PORT}/mcp`);
155-
console.log(`Then call tool with: curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -H "mcp-session-id: YOUR_SESSION_ID" -d '{"jsonrpc":"2.0","method":"mcp.call_tool","params":{"name":"greet","arguments":{"name":"World"}},"id":"2"}' http://localhost:${PORT}/mcp`);
152+
console.log(`MCP Streamable HTTP Server listening on port ${PORT}`);
153+
console.log(`Initialize session with the command below id you are using curl for testing:
154+
-----------------------------
155+
SESSION_ID=$(curl -X POST \
156+
-H "Content-Type: application/json" \
157+
-H "Accept: application/json" \
158+
-H "Accept: text/event-stream" \
159+
-d '{
160+
"jsonrpc": "2.0",
161+
"method": "initialize",
162+
"params": {
163+
"capabilities": {},
164+
"protocolVersion": "2025-03-26",
165+
"clientInfo": {
166+
"name": "test",
167+
"version": "1.0.0"
168+
}
169+
},
170+
"id": "1"
171+
}' \
172+
-i http://localhost:3000/mcp 2>&1 | grep -i "mcp-session-id" | cut -d' ' -f2 | tr -d '\\r')
173+
echo "Session ID: $SESSION_ID"
174+
-----------------------------`);
156175
});
157176

158177
// Handle server shutdown

src/examples/server/simpleStreamableHttp.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,28 @@ function isInitializeRequest(body: unknown): boolean {
186186
const PORT = 3000;
187187
app.listen(PORT, () => {
188188
console.log(`MCP Streamable HTTP Server listening on port ${PORT}`);
189-
console.log(`Test with: curl -X POST -H "Content-Type: application/json" -H "Accept: application/json, text/event-stream" -d '{"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{}},"id":"1"}' http://localhost:${PORT}/mcp`);
189+
console.log(`Initialize session with the command below id you are using curl for testing:
190+
-----------------------------
191+
SESSION_ID=$(curl -X POST \
192+
-H "Content-Type: application/json" \
193+
-H "Accept: application/json" \
194+
-H "Accept: text/event-stream" \
195+
-d '{
196+
"jsonrpc": "2.0",
197+
"method": "initialize",
198+
"params": {
199+
"capabilities": {},
200+
"protocolVersion": "2025-03-26",
201+
"clientInfo": {
202+
"name": "test",
203+
"version": "1.0.0"
204+
}
205+
},
206+
"id": "1"
207+
}' \
208+
-i http://localhost:3000/mcp 2>&1 | grep -i "mcp-session-id" | cut -d' ' -f2 | tr -d '\\r')
209+
echo "Session ID: $SESSION_ID"
210+
-----------------------------`);
190211
});
191212

192213
// Handle server shutdown
-16 KB
Binary file not shown.

src/server/streamableHttp.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ describe("StreamableHTTPServerTransport", () => {
12521252
it("should return JSON response for a single request", async () => {
12531253
const requestMessage: JSONRPCMessage = {
12541254
jsonrpc: "2.0",
1255-
method: "test",
1255+
method: "tools/list",
12561256
params: {},
12571257
id: "test-req-id",
12581258
};
@@ -1306,8 +1306,8 @@ describe("StreamableHTTPServerTransport", () => {
13061306

13071307
it("should return JSON response for batch requests", async () => {
13081308
const batchMessages: JSONRPCMessage[] = [
1309-
{ jsonrpc: "2.0", method: "test1", params: {}, id: "req1" },
1310-
{ jsonrpc: "2.0", method: "test2", params: {}, id: "req2" },
1309+
{ jsonrpc: "2.0", method: "tools/list", params: {}, id: "req1" },
1310+
{ jsonrpc: "2.0", method: "tools/call", params: {}, id: "req2" },
13111311
];
13121312

13131313
const req = createMockRequest({
@@ -1334,9 +1334,6 @@ describe("StreamableHTTPServerTransport", () => {
13341334

13351335
await jsonResponseTransport.handleRequest(req, mockResponse);
13361336

1337-
// Wait for all promises to resolve - give it enough time
1338-
await new Promise(resolve => setTimeout(resolve, 100));
1339-
13401337
// Should respond with application/json header
13411338
expect(mockResponse.writeHead).toHaveBeenCalledWith(
13421339
200,
@@ -1350,7 +1347,7 @@ describe("StreamableHTTPServerTransport", () => {
13501347
const responseJson = JSON.parse(mockResponse.end.mock.calls[0][0] as string);
13511348
expect(Array.isArray(responseJson)).toBe(true);
13521349
expect(responseJson).toHaveLength(2);
1353-
1350+
13541351
// Check each response exists separately without assuming order
13551352
expect(responseJson).toContainEqual(expect.objectContaining({ id: "req1", result: { value: "result-for-req1" } }));
13561353
expect(responseJson).toContainEqual(expect.objectContaining({ id: "req2", result: { value: "result-for-req2" } }));

0 commit comments

Comments
 (0)