mcp-trellis
ost-agnostic MCP + OAuth ports — you bring the runtime and IdP; the library owns the connector protocol. Web-standard Request → Response. Same handler on Cloudflare Workers, Next.js App Router, Deno, Bun, and Node HTTP via mcp-trellis/node. Zero runtime dependencies.
README
mcp-trellis
Host-agnostic MCP + OAuth ports — you bring the runtime and IdP; the library owns the connector protocol.
Web-standard Request → Response. Same handler on Cloudflare Workers, Next.js App Router, Deno, Bun, and Node HTTP via mcp-trellis/node. Zero runtime dependencies.
Why mcp-trellis
The whole connector stack in one package — MCP handler and OAuth 2.1 authorization server — with no database and no vendor signup. You own login, token minting, and storage; the library owns the protocol.
| mcp-trellis | Official MCP SDK | workers-oauth-provider |
@mcpauth/auth |
Auth0 / Clerk / Authlete | |
|---|---|---|---|---|---|
| MCP handler | ✅ | ✅ | ❌ | ❌ | ❌ |
| OAuth 2.1 authorization server | ✅ | ❌ bring your own | ✅ | ✅ | ✅ |
| Runtime | any Web-standard | any Web-standard | Workers only | Node | — |
| Database | none | — | KV (optional) | required | — |
| Runtime dependencies | zero | several | several | several | — |
| Self-hosted | ✅ | ✅ | ✅ | ✅ | ❌ SaaS |
| Named connector profiles (Claude / Gemini / Codex), enforced | ✅ | ❌ | ❌ | ❌ | ❌ |
Prefer the official SDK when you already have a separate AS. Prefer
workers-oauth-provider when you want Cloudflare's Workers-only
implementation. Prefer a managed IdP when you'd rather pay than operate one.
Named alternatives in the same problem space:
@mcpauth/auth/getmcpauth/mcp-auth— OAuth for MCP, typically with a DB or a different runtime/stack assumption. mcp-trellis is the zero-dependency option that ships the MCP handler and the OAuth 2.1 AS in one package.fastmcp-oauth— OAuth helpers around FastMCP. mcp-trellis is host-agnostic (Request/Response) and not tied to a particular MCP framework.
Requirements
- Node ≥ 20 for Node hosts (global WebCrypto in ESM)
- Or any runtime with WebCrypto +
fetch(Workers, Deno, Bun)
Install
npm install mcp-trellis
Quick start
One call mounts the MCP endpoint, the OAuth authorization server, and both discovery documents:
import { createMcpApp } from "mcp-trellis";
const app = createMcpApp({
serverInfo: { name: "demo", version: "1.0.0" },
clients: ["claude"],
tools: [
{
name: "echo",
description: "Echo text back",
inputSchema: {
type: "object",
properties: { text: { type: "string" } },
required: ["text"],
},
scope: "mcp",
handler: (_ctx, args) => String(args.text ?? ""),
},
],
auth: {
codeSecret: process.env.OAUTH_CODE_SECRET!,
resolveUser: async (req) => getSession(req),
loginUrl: (_req, next) => `/login?next=${encodeURIComponent(next)}`,
mintAccessToken: async ({ userId, scope, resource }) => ({
// Embed `resource` as the token audience (RFC 8707).
accessToken: await issueUserToken(userId, { aud: resource, scope }),
expiresIn: 3600,
}),
verifyToken: async (token) => {
const claims = await readUserToken(token);
if (!claims) return null;
return {
userId: claims.sub,
scopes: claims.scope.split(" "),
audience: claims.aud,
};
},
},
});
export default { fetch: (req: Request) => app.fetch(req) };
You return the token's audience; the library rejects tokens minted for a different resource before any tool runs. Details: docs/security.md.
A real /authorize walk includes an approval step: a resolved session doesn't redirect straight back with a code, it renders a consent screen first (built in, or your own via consent). First-time integrators clicking through by hand should expect an HTML page there, not an immediate redirect — see Consent.
Smoke-test with initialize (public — no Bearer needed):
curl -s http://127.0.0.1:8787/mcp \
-H 'content-type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18"}}'
{"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2025-06-18","capabilities":{"tools":{}},"serverInfo":{"name":"demo","version":"1.0.0"},"instructions":""}}
Clients
| Client | Registration | Token endpoint auth | Notes |
|---|---|---|---|
claude |
Dynamic (DCR), public + PKCE | none |
Claude Custom Connectors callback allowlisted |
gemini |
Pre-registered, confidential | client_secret_basic, client_secret_post |
Supply auth.clientStore |
codex |
OAuth 2.1 per MCP auth spec, public + PKCE | none |
ChatGPT / Codex share one contract |
Pre-registered clients, DCR enforcement, and clientStore wiring: docs/guide.md#clients.
Architecture
createMcpApp wires MCP and OAuth and routes between them:
Host recipes, ports, tools, and multi-tenant: docs/guide.md.
Docs
| Doc | Contents |
|---|---|
| docs/guide.md | Architecture, clients, recipes, ports, tools, multi-tenant |
| docs/reference.md | Routes, methods, status codes, options, exports |
| docs/security.md | Protocol promises, threat model, not in scope |
| docs/ROADMAP.md | What's next |
Examples: examples/ — HTTP server, Worker, multi-tenant, stores, audit.
Contributing
PRs welcome — see CONTRIBUTING.md.
npm test
npm run build
npm run typecheck
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。