|
1 | 1 | # mcp-handler |
2 | 2 |
|
3 | | -A Vercel adapter for the Model Context Protocol (MCP), enabling real-time communication between your applications and AI models. Currently supports Next.js with more framework adapters coming soon. |
| 3 | +A Vercel adapter for the Model Context Protocol (MCP), enabling real-time communication between your applications and AI models. Currently supports Next.js and Nuxt with more framework adapters coming soon. |
4 | 4 |
|
5 | 5 | ## Installation |
6 | 6 |
|
@@ -50,11 +50,12 @@ const handler = createMcpHandler( |
50 | 50 | export { handler as GET, handler as POST }; |
51 | 51 | ``` |
52 | 52 |
|
53 | | -## Advanced Routing |
| 53 | +### Advanced Routing |
| 54 | + |
54 | 55 | ```typescript |
55 | 56 | // app/dynamic/[p]/[transport]/route.ts |
56 | 57 |
|
57 | | -import { createMcpHandler } from "@vercel/mcp-adapter"; |
| 58 | +import { createMcpHandler } from "mcp-handler"; |
58 | 59 | import type { NextRequest } from "next/server"; |
59 | 60 | import { z } from "zod"; |
60 | 61 |
|
@@ -96,8 +97,36 @@ const handler = async ( |
96 | 97 | )(req); |
97 | 98 | }; |
98 | 99 | export { handler as GET, handler as POST, handler as DELETE }; |
| 100 | +``` |
| 101 | + |
| 102 | +## Nuxt Usage |
| 103 | + |
| 104 | +```typescript |
| 105 | +// server/api/mcp/[transport].ts |
| 106 | + |
| 107 | +import { createMcpHandler } from "mcp-handler"; |
| 108 | +import { getHeader, defineEventHandler, fromWebHandler } from "h3"; |
| 109 | +import { z } from "zod"; |
99 | 110 |
|
| 111 | +const handler = createMcpHandler((server) => { |
| 112 | + server.tool( |
| 113 | + "roll_dice", |
| 114 | + "Rolls an N-sided die", |
| 115 | + { |
| 116 | + sides: z.number().int().min(2) |
| 117 | + }, |
| 118 | + async ({ sides }) => { |
| 119 | + const value = 1 + Math.floor(Math.random() * sides) |
| 120 | + return { |
| 121 | + content: [{ type: "text", text: `🎲 You rolled a ${value}!` }] |
| 122 | + } |
| 123 | + } |
| 124 | + ) |
| 125 | +}, { |
| 126 | + // Optional server options |
| 127 | +}); |
100 | 128 |
|
| 129 | +export default fromWebHandler(handler); |
101 | 130 | ``` |
102 | 131 |
|
103 | 132 | ## Connecting to your MCP server via stdio |
|
0 commit comments