Skip to content

Commit 58014ae

Browse files
committed
Move MCP server out of routes
1 parent 3babd43 commit 58014ae

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Usage
44

5-
Update `app/message/route.ts` with your tools, prompts, and resources following the [MCP TypeScript SDK documentation](https://github.com/modelcontextprotocol/typescript-sdk/tree/main?tab=readme-ov-file#server).
5+
Update `app/mcp.ts` with your tools, prompts, and resources following the [MCP TypeScript SDK documentation](https://github.com/modelcontextprotocol/typescript-sdk/tree/main?tab=readme-ov-file#server).
66

77
## Notes for running on Vercel
88

app/mcp.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { z } from "zod";
2+
import { initializeMcpApiHandler } from "../lib/mcp-api-handler";
3+
4+
export const mcpHandler = initializeMcpApiHandler(
5+
(server) => {
6+
// Add more tools, resources, and prompts here
7+
server.tool("echo", { message: z.string() }, async ({ message }) => ({
8+
content: [{ type: "text", text: `Tool echo: ${message}` }],
9+
}));
10+
},
11+
{
12+
capabilities: {
13+
tools: {
14+
echo: {
15+
description: "Echo a message",
16+
},
17+
},
18+
},
19+
}
20+
);

app/message/route.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,8 @@
1-
import { z } from "zod";
2-
import { initializeMcpApiHandler } from "../../lib/mcp-api-handler";
31
import { createServerResponseAdapter } from "@/lib/server-response-adapter";
2+
import { mcpHandler } from "../mcp";
43

54
export const maxDuration = 60;
65

7-
export const mcpHandler = initializeMcpApiHandler(
8-
(server) => {
9-
// Add more tools, resources, and prompts here
10-
server.tool("echo", { message: z.string() }, async ({ message }) => ({
11-
content: [{ type: "text", text: `Tool echo: ${message}` }],
12-
}));
13-
},
14-
{
15-
capabilities: {
16-
tools: {
17-
echo: {
18-
description: "Echo a message",
19-
},
20-
},
21-
},
22-
}
23-
);
24-
256
export async function POST(req: Request) {
267
return createServerResponseAdapter(req.signal, (res) => {
278
mcpHandler(req, res);

app/sse/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createServerResponseAdapter } from "@/lib/server-response-adapter";
2-
import { mcpHandler } from "../message/route";
2+
import { mcpHandler } from "../mcp";
33

44
export const maxDuration = 60;
55

0 commit comments

Comments
 (0)