
vercel-labs/mcp-handler
Developer toolsこのページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。 原文を見る
Next.js、Nuxt、Svelteなどで簡単にMCPサーバーを立ち上げることができます
概要
mcp-handlerは、JavaScriptおよびTypeScriptアプリケーションでModel Context Protocol(MCP)サーバーをホストするためのフレームワークに依存しないHTTPアダプターです。MCPサーバーの定義をWeb標準(Request)=>約束ハンドラに変換し、Next.js、Nuxt/Nitro、SvelteKit、Hono、その他のFetch互換フレームワークにマウント可能です。 MCP SDK v2を基盤に構築されており、MCP仕様をネイティブに提供しながら、2025年当時のクライアント向けにステートレスなStreamable HTTPに透過的にフォールバックします — 両世代のハンドラが1つずつです。 : mcp-handler 2.xはMCP SDK v2パッケージ(@modelcontextprotocol/server ^2.0.0)、zod ^4.2.0、Node.js 20+が必要です。@modelcontextprotocol/sdk 1.xを使っている場合は、mcp-handler 1.xを使いましょう。 createMcpHandlerはWeb標準のリクエストハンドラを返すため、パッケージはVercelや特定のフレームワークに縛られません。以下にマウント可能です: - Next.js ルートハンドラ - fromWebHandler を使用したNuxt/Nitroサーバーハンドラ- SvelteKitサーバールート - c.reqを使用したHonoルート
概要(AI 翻訳)
mcp-handlerは、JavaScriptおよびTypeScriptアプリケーションにおけるModel Context Protocol(MCP)サーバーをホストするためのフレームワークに依存しないHTTPアダプターです。MCPサーバーの定義をWeb標準の(Request) => Promise ハンドラに変換し、Next.js、Nuxt/Nitro、SvelteKit、Hono、その他のFetch互換フレームワークにマウント可能です。
MCP SDK v2を基盤とし、2026-07-28 MCP仕様をネイティブに提供しつつ、2025年当時のクライアント向けにはステートレスなStreamable HTTPに透過的にフォールバックします — 1つのハンドラ、両世代のプロトコルです。
設置
注:
mcp-handler2.xはMCP SDK v2パッケージ(@modelcontextprotocol/server^2.0.0)、zod ^4.2.0、Node.js 20+が必要です。@modelcontextprotocol/sdk1.xを使っている場合は、mcp-handler1.xを使いましょう。
フレームワーク互換性
createMcpHandlerはWeb標準のリクエストハンドラを返すため、パッケージはVercelや特定のフレームワークに紐づけられません。以下にマウント可能です:
- Next.js ルートハンドラー
- [[T7]を使用したNuxt/Nitroサーバーハンドラ
- SvelteKitサーバールート
- [[T8]を使用したホノルート
- Fetch互換の
RequestおよびResponseAPIを公開するその他のフレームワーク
Nodeをベースにしたフレームワーク。
このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。
README
以下は原文 README の抜粋です。原文を見る。
mcp-handler
mcp-handler is a framework-agnostic HTTP adapter for hosting Model Context Protocol (MCP) servers in JavaScript and TypeScript applications. It turns an MCP server definition into a Web-standard (Request) => Promise handler that can be mounted in Next.js, Nuxt/Nitro, SvelteKit, Hono, and other Fetch-compatible frameworks.
Built on MCP SDK v2, it serves the 2026-07-28 MCP specification natively while transparently falling back to stateless Streamable HTTP for 2025-era clients — one handler, both protocol generations.
Installation
npm install mcp-handler@^2 @modelcontextprotocol/server@^2 zod@^4
Note:
mcp-handler2.x requires the MCP SDK v2 packages (@modelcontextprotocol/server^2.0.0), zod ^4.2.0, and Node.js 20+. If you’re on@modelcontextprotocol/sdk1.x, usemcp-handler1.x.
Framework Compatibility
createMcpHandler returns a Web-standard request handler, so the package is not tied to Vercel or any particular framework. It can be mounted in:
- Next.js Route Handlers
- Nuxt/Nitro server handlers using
fromWebHandler - SvelteKit server routes
- Hono routes using
c.req.raw - Other frameworks that expose Fetch-compatible
RequestandResponseAPIs
Frameworks based on Node.js IncomingMessage and ServerResponse, such as Express, require a Web Request adapter or the official MCP framework middleware.
Quick Start (Next.js)
// app/api/mcp/route.ts
import { createMcpHandler } from "mcp-handler";
import { z } from "zod";
const handler = createMcpHandler((server) => {
server.registerTool(
"roll_dice",
{
title: "Roll Dice",
description: "Roll a dice with a specified number of sides.",
inputSchema: z.object({
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}!` }],
};
},
);
});
export { handler as GET, handler as POST };
インストール
npx -y mcp-remote http://localhost:3000/api/mcp