VM

vercel/mcp-handler

Developer tools

このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。 原文を見る

691 stars 94 forks 品質 67 トレンド 42

Next.js、Nuxt、Svelteなどで簡単にMCPサーバーを立ち上げることができます

概要

モデルコンテキストプロトコル(MCP)用のVercelアダプターで、アプリケーションとAIモデル間のリアルタイム通信を可能にします。Next.jsおよびNuxtをサポートしています。 : 1.26.0以前の@modelcontextprotocol/SDKのバージョンにはセキュリティ脆弱性があります。バージョン1.26.0以降を使用してください。 クライアントがStreamable HTTPをサポートしている場合は、直接接続してください: - クライアント統合 - Claude Desktop、カーソル、Windsurf設定 - 認証 - OAuthおよびトークン検証 - 高度な使用法 - 動的ルーティング、Nuxt、設定オプション - : Next.js および Nuxt - : Streamable HTTP および Server-Sent Events(SSE) - : SSE トランスポートの再開可能のためにオプション - : 完全な型定義が含まれます - Next.js 13+ または Nuxt 3+ - Node.js 18+ - Redis(SSE用はオプション)

概要(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-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 ルートハンドラー
  • [[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-handler 2.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/sdk 1.x, use mcp-handler 1.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 Request and Response APIs

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 };
GitHub で README 全文を見る

インストール

npx -y mcp-remote http://localhost:3000/api/mcp
MCP 初心者?mcpskill.org のガイドから始めましょう →