Token导航 LogoToken导航TokenDH.com
Vercel Template logo
AI代理未说明官方级别未说明来源级核验

Vercel Template

MCP Server

一个生产就绪的Model Context Protocol (MCP)服务器模板,可在5分钟内部署到Vercel,支持Bun运行时、JWT认证和服务注入。

工具数

3

提示词数

0

GitHub Stars

0

资源数

0
服务器模板TypeScriptAI代理

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

linyiru

提供方

linyiru

最后核验

2026/5/17 20:19

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

MCP服务器Vercel模板

生产准备就绪 模型上下文协议(MCP) 服务器模板,可部署到 维塞尔 随着 包子 运行时间不到5分钟。

特性

  • 荣誉 具有CORS、中间件和类型化上下文的web框架
  • Bun本地bundler → 单 index.js 通过生成输出API v3
  • JWT身份验证 通过JWKS(jose)提供可选的不透明令牌支持
  • 服务注入 通过代理模式(在您自己的数据库/API层中交换)
  • MCP传输:流式HTTP(POST/)和SSE(/sse + /message)
  • OAuth元数据:RFC 9728 /.well-known/oauth-protected-resource
  • 3个示例工具:Notes CRUD,Weather API,文档阅读器

快速开始

1.从模板创建

点击 “使用此模板” 在GitHub上,或:

git clone https://github.com/user/mcp-server-vercel-template.git my-mcp-server
cd my-mcp-server

2.安装依赖项

bun install

3.配置

复制 .env.example.env 并设置 AUTH_SKIP=true 地方发展:

cp .env.example .env
echo 'AUTH_SKIP=true' >> .env

4.构建和验证

bun scripts/build.ts

5.部署到Vercel

vercel deploy

项目结构

src/
├── index.ts                  # Entry point (re-exports app)
├── app.ts                    # Hono app: CORS, routes, MCP handler, OAuth metadata
├── config.ts                 # Centralized configuration from env vars
├── env.ts                    # Hono context type definitions
├── context.ts                # Service Proxy (lazy initialization)
├── server.ts                 # Tool/prompt registration
├── middleware/
│   └── mcp-auth.ts           # JWT (jose) + opaque token verification
├── services/
│   ├── types.ts              # Service interface definitions
│   └── in-memory.ts          # Example: in-memory implementation
├── tools/
│   ├── index.ts              # Barrel export
│   ├── errors.ts             # Standardized error responses
│   ├── notes.ts              # Example: CRUD tools (services proxy)
│   └── weather.ts            # Example: external API tool (Open-Meteo)
├── prompts/
│   └── index.ts              # Example MCP prompts
└── resources/
    ├── index.ts              # Lazy fs.readFileSync loader
    └── getting-started.md    # Example documentation
scripts/
└── build.ts                  # Bun bundler → Build Output API v3

建筑

服务代理模式

使此模板工作的核心模式是 服务注入代理context.ts:

// context.ts — tools import this proxy
import type { Services } from './services/types.js'

let _services: Services
export function initServices(impl: Services) { _services = impl }
export const services: Services = new Proxy({} as Services, {
  get(_, prop, receiver) { return Reflect.get(_services, prop, receiver) }
})
// tools/notes.ts — uses the proxy, no concrete dependency
import { services } from '../context.js'
const notes = await services.notes.list()
// app.ts middleware — injects the concrete implementation once
initServices(new InMemoryServices())

为什么? 当10+个工具文件都导入同一个重模块(如数据库客户端)时,Bun的ESM链接器可能会失败,并显示“请求的模块尚未实例化”。代理将大量进口商品隔离在 app.ts.

认证

JWT验证通过 何塞 使用JWKS端点:

  • JWT代币:已在本地验证 jwtVerify() + createRemoteJWKSet()
  • 不透明令牌:可选回拨方式 setOpaqueTokenVerifier()
  • 发展:设置 AUTH_SKIP=true 绕过所有身份验证

构建系统

Bun的本地bundler制作了一首单曲 index.js 文件,然后构建脚本生成Vercel的build Output API v3结构:

.vercel/output/
├── config.json              # Route config
└── functions/
    └── index.func/
        ├── index.js         # Bundled application
        ├── .vc-config.json  # Bun runtime config
        └── src/resources/   # Copied .md files

MCP运输

路线方法描述
/GET服务器发现(未经身份验证)
/POST可流式HTTP传输
/DELETE会话清理
/sseGETSSE运输
/messagePOSTHTTP消息传输
/.well-known/oauth-protected-resourceGETOAuth元数据(RFC 9728)

定制指南

更换服务层

  1. 在中定义您的接口 src/services/types.ts
  2. 创建一个实现(例如。, src/services/database.ts)
  3. src/app.ts,替换 new InMemoryServices() 随着您的实施

添加新工具

  1. 创建 src/tools/my-tool.ts:
   import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
   import { z } from 'zod'
   import { services } from '../context.js'

   export function registerMyTools(server: McpServer) {
     server.tool('my_tool', 'Description', { param: z.string() }, async ({ param }) => {
       // Your logic here
       return { content: [{ type: 'text', text: JSON.stringify({ success: true }) }] }
     })
   }
  1. 出口自 src/tools/index.ts
  2. 呼叫 registerMyTools(server)src/server.ts

添加文档资源

  1. 添加 .md 文件到 src/resources/
  2. 将它们注册到 src/resources/index.ts (标题+文件地图)
  3. 将文件名添加到 scripts/build.ts 复制列表

配置身份验证

设置这些环境变量(或在Vercel仪表板中):

变量描述示例
AUTH_ISSUERJWT发行人URLhttps://auth.example.com
AUTH_JWKS_URLJWKS端点https://auth.example.com/.well-known/jwks.json
AUTH_AUDIENCES接受的受众(逗号分隔)https://mcp.example.com
AUTH_SKIP跳过身份验证(仅限开发人员)true

启用Redis会话

REDIS_URL 在无服务器调用之间持久化MCP会话:

REDIS_URL="redis://your-redis-host:6379"

依赖项

包装用途
honoWeb框架
mcp-handlerMCP协议+会话管理
@modelcontextprotocol/sdkMCP类型定义
joseJWT/JWKS验证
zod参数验证

许可证

麻省理工学院

目录标签

目录标签

服务器模板TypeScriptAI代理本地部署MCP协议JWT认证服务注入Bun运行时

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

oauth

工具数量(toolCount,工具数)

3

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明oauth部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP