Skip to content

Commit 24ce36e

Browse files
authored
add cli support (#12)
* update: update the docs to match the new spec * add cli support * update the basePath fix * update the CLI * updated changeset * update readme * updated changeset * update readme (again)
1 parent 1aa28eb commit 24ce36e

File tree

8 files changed

+4220
-12
lines changed

8 files changed

+4220
-12
lines changed

.changeset/dirty-seas-greet.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vercel/mcp-adapter": patch
3+
---
4+
5+
updated readme

.changeset/petite-badgers-tie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vercel/mcp-adapter": minor
3+
---
4+
5+
added cli support to auto add the mcp route to a nextjs project

README.md

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ npm install @vercel/mcp-adapter
1212
yarn add @vercel/mcp-adapter
1313
# or
1414
pnpm add @vercel/mcp-adapter
15+
# or
16+
bun add @vercel/mcp-adapter
1517
```
1618

1719
## Next.js Usage
1820

19-
1. Create an API route for MCP communication:
20-
2121
```typescript
2222
// app/api/[transport]/route.ts
2323
import { createMcpHandler } from '@vercel/mcp-adapter';
@@ -26,7 +26,9 @@ const handler = createMcpHandler(
2626
server.tool(
2727
'roll_dice',
2828
'Rolls an N-sided die',
29-
{ sides: z.number().int().min(2) },
29+
{
30+
sides: z.number().int().min(2)
31+
},
3032
async ({ sides }) => {
3133
const value = 1 + Math.floor(Math.random() * sides);
3234
return {
@@ -39,18 +41,62 @@ const handler = createMcpHandler(
3941
// Optional server options
4042
},
4143
{
42-
// Optional configuration
44+
// Optional redis config
4345
redisUrl: process.env.REDIS_URL,
44-
// Set the basePath to where the handler is to automatically derive all endpoints
45-
// This base path is for if this snippet is located at: /app/api/[transport]/route.ts
46-
basePath: '/api',
46+
// You need these endpoints
47+
basePath: '/api', // this needs to match where the [transport] is located.
48+
// @deprecated use 'basePath' instead
49+
streamableHttpEndpoint?: string; // Endpoint for streamable HTTP transport
50+
// @deprecated use 'basePath' instead
51+
sseEndpoint?: string; // Endpoint for SSE transport
52+
// @deprecated use 'basePath' instead
53+
sseMessageEndpoint?: string; // Endpoint for SSE message transport
4754
maxDuration: 60,
4855
verboseLogs: true,
4956
}
5057
);
5158
export { handler as GET, handler as POST };
5259
```
5360

61+
## Integrating into your client
62+
63+
When you want to use it in your MCP client of choice:
64+
65+
### Claude Desktop
66+
[Official Docs](https://modelcontextprotocol.io/quickstart/user)
67+
68+
In order to add an MCP server to Claude Desktop you need to edit the configuration file located at:
69+
70+
```json
71+
"remote-example": {
72+
"command": "npx",
73+
"args": [
74+
"mcp-remote",
75+
"http://localhost:3000/api/mcp" // this is your app/api/[transport]/route.ts
76+
]
77+
}
78+
```
79+
80+
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
81+
Windows: %APPDATA%\Claude\claude_desktop_config.json
82+
If it does not exist yet, you may need to enable it under Settings > Developer.
83+
84+
Restart Claude Desktop to pick up the changes in the configuration file. Upon restarting, you should see a hammer icon in the bottom right corner of the input box.
85+
86+
### Cursor
87+
[Official Docs](https://docs.cursor.com/context/model-context-protocol)
88+
89+
The configuration file is located at ~/.cursor/mcp.json.
90+
91+
As of version 0.48.0, Cursor supports unauthed SSE servers directly. If your MCP server is using the official MCP OAuth authorization protocol, you still need to add a "command" server and call mcp-remote.
92+
93+
### Windsurf
94+
[Official Docs](https://docs.codeium.com/windsurf/mcp)
95+
96+
The configuration file is located at ~/.codeium/windsurf/mcp_config.json.
97+
98+
## Usage in your app
99+
54100
1. Use the MCP client in your application:
55101

56102
```typescript
@@ -59,7 +105,7 @@ import { McpClient } from '@modelcontextprotocol/sdk/client';
59105

60106
const client = new McpClient({
61107
// When using basePath, the SSE endpoint will be automatically derived
62-
transport: new SSEClientTransport('/api/mcp/sse'),
108+
transport: new SSEClientTransport('/api/mcp/mcp'),
63109
});
64110

65111
// Use the client to make requests
@@ -73,12 +119,11 @@ The `initializeMcpApiHandler` function accepts the following configuration optio
73119
```typescript
74120
interface Config {
75121
redisUrl?: string; // Redis connection URL for pub/sub
122+
// @deprecated use streamableHttpEndpoint, sseEndpoint, sseMessageEndpoint
76123
basePath?: string; // string; // Base path for MCP endpoints
77-
// @deprecated use 'basePath' instead
124+
78125
streamableHttpEndpoint?: string; // Endpoint for streamable HTTP transport
79-
// @deprecated use 'basePath' instead
80126
sseEndpoint?: string; // Endpoint for SSE transport
81-
// @deprecated use 'basePath' instead
82127
sseMessageEndpoint?: string; // Endpoint for SSE message transport
83128
maxDuration?: number; // Maximum duration for SSE connections in seconds
84129
verboseLogs?: boolean; // Log debugging information

bun.lock

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

0 commit comments

Comments
 (0)