Skip to content

Update example and README to use @vercel/mcp-adapter #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Run an MCP Server on Vercel

**Uses [Vercel MCP Adapter](https://github.com/vercel/vercel/mcp-adapter/tree/main)**

## Usage

Update `api/server.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).
Expand All @@ -8,9 +10,9 @@ Update `api/server.ts` with your tools, prompts, and resources following the [MC

## Notes for running on Vercel

- Requires a Redis attached to the project under `process.env.REDIS_URL`
- To use the SSE transport, requires a Redis attached to the project under `process.env.REDIS_URL`
- Make sure you have [Fluid compute](https://vercel.com/docs/functions/fluid-compute) enabled for efficient execution
- After enabling Fluid compute, open `vercel.json` and adjust max duration to 800 if you using a Vercel Pro or Enterprise account
- After enabling Fluid compute, open `app/server.ts` and adjust `maxDuration` to 800 if you using a Vercel Pro or Enterprise account
- [Deploy the MCP template](https://vercel.com/templates/other/model-context-protocol-mcp-with-vercel-functions)

## Sample Client
Expand Down
30 changes: 10 additions & 20 deletions api/server.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
import { z } from "zod";
import { initializeMcpApiHandler } from "../lib/mcp-api-handler";
const z = require("zod");

const handler = initializeMcpApiHandler(
(server) => {
// Add more tools, resources, and prompts here
server.tool("echo", { message: z.string() }, async ({ message }) => ({
content: [{ type: "text", text: `Tool echo: ${message}` }],
}));
},
{
capabilities: {
tools: {
echo: {
description: "Echo a message",
},
},
},
}
);
// TODO this is exported from `next` but is generic to all isomorphic web API signatures
const createMcpApiHandler = require("@vercel/mcp-adapter/next");

export default handler;
const handler = createMcpApiHandler((server) => {
server.tool("echo", { message: z.string() }, async ({ message }) => ({
content: [{ type: "text", text: `Tool echo: ${message}` }],
}));
});

export { handler as GET, handler as POST, handler as DELETE };
329 changes: 0 additions & 329 deletions lib/mcp-api-handler.ts

This file was deleted.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
"license": "ISC",
"packageManager": "[email protected]+sha512.c85cd21b6da10332156b1ca2aa79c0a61ee7ad2eb0453b88ab299289e9e8ca93e6091232b25c07cbf61f6df77128d9c849e5c9ac6e44854dbd211c49f3a67adc",
"dependencies": {
"@modelcontextprotocol/sdk": "^1.10.2",
"content-type": "^1.0.5",
"raw-body": "^3.0.0",
"redis": "^4.7.0",
"@vercel/mcp-adapter": "^0.2.1",
"zod": "^3.24.2"
},
"devDependencies": {
Expand Down
Loading