Skip to content
Merged
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
2 changes: 2 additions & 0 deletions starter/mcp-api-wrapper/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vercel
node_modules
7 changes: 7 additions & 0 deletions starter/mcp-api-wrapper/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2025 Vercel, Inc

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 changes: 27 additions & 0 deletions starter/mcp-api-wrapper/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Run an MCP Server on Vercel

## 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).

[There is also a Next.js version of this template](https://vercel.com/templates/next.js/model-context-protocol-mcp-with-next-js)

## Notes for running on Vercel

- 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
- [Deploy the MCP template](https://vercel.com/templates/other/model-context-protocol-mcp-with-vercel-functions)

## Local dev

- Run `vercel dev` for local development
- Alternatively, integrate the system into the server framework of your choice.

## Sample Client

`script/test-client.mjs` contains a sample client to try invocations.

```sh
node scripts/test-client.mjs https://mcp-on-vercel.vercel.app
```
41 changes: 41 additions & 0 deletions starter/mcp-api-wrapper/api/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { createMcpHandler } from 'mcp-handler'
import { z } from 'zod'

const handler = createMcpHandler((server) => {
server.tool(
'roll_dice',
'Rolls an N-sided die',
{ sides: z.number().int().min(2) },
async ({ sides }) => {
const value = 1 + Math.floor(Math.random() * sides)
return {
content: [{ type: 'text', text: `🎲 You rolled a ${value}!` }],
}
}
)
server.tool(
'get_weather',
'Get the current weather at a location',
{
latitude: z.number(),
longitude: z.number(),
city: z.string(),
},
async ({ latitude, longitude, city }) => {
const response = await fetch(
`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&current_weather=true`
)
const weatherData = await response.json()
return {
content: [
{
type: 'text',
text: `The weather in ${city} is ${weatherData.current_weather.temperature}°C currently.`,
},
],
}
}
)
})

export { handler as GET, handler as POST, handler as DELETE }
21 changes: 21 additions & 0 deletions starter/mcp-api-wrapper/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "mcp-on-vercel",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"packageManager": "pnpm@9.4.0",
"dependencies": {
"mcp-handler": "^1.0.1",
"zod": "^3.24.2"
},
"devDependencies": {
"@types/node": "^22.13.10"
}
}
Loading