Skip to content

Commit 731b4f6

Browse files
Merge pull request #14 from sveltejs/close-sse-stream
2 parents bb9a6e0 + 582e0e1 commit 731b4f6

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ pnpm dev
1212

1313
1. Set the VOYAGE_API_KEY for embeddings support
1414

15+
> [!NOTE]
16+
> Currently to prevent having a bunch of Timeout logs on vercel we shut down the SSE channel immediately. This means that we can't use `server.log` and we are not sending `list-changed` notifications. We can use elicitation and sampling since those are sent on the same stream of the POST request
17+
1518
### Local dev tools
1619

1720
#### MCP inspector

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"@eslint/compat": "^1.2.5",
6565
"@eslint/js": "^9.18.0",
6666
"@tmcp/adapter-valibot": "^0.1.4",
67-
"@tmcp/transport-http": "^0.6.0",
67+
"@tmcp/transport-http": "^0.6.1",
6868
"@tmcp/transport-stdio": "^0.1.3",
6969
"@typescript-eslint/parser": "^8.43.0",
7070
"eslint": "^9.36.0",

pnpm-lock.yaml

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/hooks.server.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
import { http_transport } from '$lib/mcp';
22

33
export async function handle({ event, resolve }) {
4-
return (await http_transport.respond(event.request)) ?? resolve(event);
4+
const mcp_response = await http_transport.respond(event.request);
5+
// we are deploying on vercel the SSE connection will timeout after 5 minutes...for
6+
// the moment we are not sending back any notifications (logs, or list changed notifications)
7+
// so it's a waste of resources to keep a connection open that will error
8+
// after 5 minutes making the logs dirty. For this reason if we have a response from
9+
// the MCP server and it's a GET request we just return an empty response (it has to be
10+
// 200 or the MCP client will complain)
11+
if (mcp_response && event.request.method === 'GET') {
12+
try {
13+
await mcp_response.body?.cancel();
14+
} catch {
15+
// ignore
16+
}
17+
return new Response('', { status: 200 });
18+
}
19+
return mcp_response ?? resolve(event);
520
}

0 commit comments

Comments
 (0)