Skip to content

Commit 5c5a330

Browse files
committed
add GET to examples servers
1 parent 755534e commit 5c5a330

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

src/client/streamableHttp.ts

-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ export class StreamableHTTPClientTransport implements Transport {
131131
`Failed to open SSE stream: ${response.statusText}`,
132132
);
133133
}
134-
135134
// Successful connection, handle the SSE stream as a standalone listener
136135
this._handleSseStream(response.body);
137136
} catch (error) {

src/examples/client/simpleStreamableHttp.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async function main(): Promise<void> {
2525
const transport = new StreamableHTTPClientTransport(
2626
new URL('http://localhost:3000/mcp')
2727
);
28-
const supportsStandaloneSse = false;
28+
let supportsStandaloneSse = false;
2929

3030
// Connect the client using the transport and initialize the server
3131
await client.connect(transport);
@@ -34,7 +34,7 @@ async function main(): Promise<void> {
3434
console.log('Opening SSE stream to receive server notifications...');
3535
try {
3636
await transport.openSseStream();
37-
const supportsStandaloneSse = false;
37+
supportsStandaloneSse = true;
3838
console.log('SSE stream established successfully. Waiting for notifications...');
3939
}
4040
catch (error) {

src/examples/server/jsonResponseStreamableHttp.ts

+7
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ app.post('/mcp', async (req: Request, res: Response) => {
138138
}
139139
});
140140

141+
// Handle GET requests for SSE streams according to spec
142+
app.get('/mcp', async (req: Request, res: Response) => {
143+
// Since this is a very simple example, we don't support GET requests for this server
144+
// The spec requires returning 405 Method Not Allowed in this case
145+
res.status(405).set('Allow', 'POST').send('Method Not Allowed');
146+
});
147+
141148
// Helper function to detect initialize requests
142149
function isInitializeRequest(body: unknown): boolean {
143150
if (Array.isArray(body)) {

src/examples/server/simpleStreamableHttp.ts

+13
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,19 @@ app.post('/mcp', async (req: Request, res: Response) => {
174174
}
175175
});
176176

177+
// Handle GET requests for SSE streams (now using built-in support from StreamableHTTP)
178+
app.get('/mcp', async (req: Request, res: Response) => {
179+
const sessionId = req.headers['mcp-session-id'] as string | undefined;
180+
if (!sessionId || !transports[sessionId]) {
181+
res.status(400).send('Invalid or missing session ID');
182+
return;
183+
}
184+
185+
console.log(`Establishing SSE stream for session ${sessionId}`);
186+
const transport = transports[sessionId];
187+
await transport.handleRequest(req, res);
188+
});
189+
177190
// Helper function to detect initialize requests
178191
function isInitializeRequest(body: unknown): boolean {
179192
if (Array.isArray(body)) {

0 commit comments

Comments
 (0)