Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@ai-sdk/react": "^1.2.9",
"@ai-sdk/xai": "^1.2.15",
"@cloudflare/workers-oauth-provider": "^0.0.2",
"@modelcontextprotocol/sdk": "^1.10.2",
"@modelcontextprotocol/sdk": "^1.11.2",
"@radix-ui/react-accordion": "^1.2.8",
"@radix-ui/react-avatar": "^1.1.7",
"@radix-ui/react-dialog": "^1.1.11",
Expand All @@ -60,7 +60,7 @@
"@remix-run/cloudflare": "^2.16.5",
"@types/react": "^19.1.2",
"@types/react-dom": "^19.1.2",
"agents": "^0.0.66",
"agents": "^0.0.84",
"ai": "^4.3.10",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
Expand Down
125 changes: 101 additions & 24 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ export class MyMCP extends McpAgent {
}
}

const mcpHandler = MyMCP.mount("/*");

// Export a request handler that checks the transport header
export default {
async fetch(request: Request, env: any, ctx: any) {
Expand Down Expand Up @@ -139,7 +137,7 @@ export default {
}
}

const isSse =
const isStreamMethod =
request.headers.get("accept")?.includes("text/event-stream") &&
!!url.pathname &&
url.pathname !== "/";
Expand All @@ -151,16 +149,19 @@ export default {
ctx.props.request = request;

if (isMessage) {
return await mcpHandler.fetch(request, env, ctx);
return await MyMCP.serveSSE("/*").fetch(request, env, ctx);
}

if (isSse) {
if (isStreamMethod) {
const newHeaders = new Headers(request.headers);
if (!newHeaders.has("accept")) {
newHeaders.set("Content-Type", "text/event-stream");
}
const modifiedRequest = new Request(request, { headers: newHeaders });
return await mcpHandler.fetch(modifiedRequest, env, ctx);
const isSse = request.method === "GET";
return isSse
? await MyMCP.serveSSE("/*").fetch(modifiedRequest, env, ctx)
: await MyMCP.serve("/*").fetch(modifiedRequest, env, ctx);
} else {
// Default to serving the regular page
return requestHandler(request, {
Expand Down
Loading
Loading