mcp-trellis
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 |
|
| 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.
Related MCP server: Remote MCP Server on Cloudflare
Requirements
Node ≥ 20 for Node hosts (global WebCrypto in ESM)
Or any runtime with WebCrypto +
fetch(Workers, Deno, Bun)
Install
npm install mcp-trellisQuick 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 |
| Dynamic (DCR), public + PKCE |
| Claude Custom Connectors callback allowlisted |
| Pre-registered, confidential |
| Supply |
| OAuth 2.1 per MCP auth spec, public + PKCE |
| 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 |
Architecture, clients, recipes, ports, tools, multi-tenant | |
Routes, methods, status codes, options, exports | |
Protocol promises, threat model, not in scope | |
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 typecheckLicense
MIT
This server cannot be installed
Maintenance
Related MCP Servers
- FlicenseNot gradedqualityCmaintenanceEnables deploying a Model Context Protocol (MCP) server on Cloudflare Workers with built-in OAuth authentication. It allows local clients like Claude Desktop to securely connect to and use remote tools through an HTTP/SSE transport.
- FlicenseNot gradedqualityCmaintenanceEnables deploying and running a Model Context Protocol (MCP) server on Cloudflare Workers with built-in OAuth authentication. It allows users to host and access tools remotely via Server-Sent Events (SSE) transport from clients like Claude Desktop.
- AlicenseNot gradedqualityDmaintenanceA dual-runtime template for building Model Context Protocol servers compatible with Node.js and Cloudflare Workers. It features integrated OAuth, encrypted token storage, and multi-tenant session management to simplify the creation of secure tool, resource, and prompt interfaces.16138ISC
- AlicenseNot gradedqualityDmaintenanceEnables developers to build OAuth-protected MCP servers on Cloudflare Workers with pluggable authentication adapters, allowing user-specific access control and secure token exchange.1326MIT
Related MCP Connectors
Self-hosted federated MCP gateway: one OAuth 2.1 MCP server in front of N apps, user-level scopes.
Artifact store for AI agents. Hosted OAuth at mcp.artifacta.io/mcp; local stdio via npm/PyPI.
Self-hosted MCP gateway: turn any API, database or MCP server into AI connectors — no code.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/amir1824/mcp-trellis'
If you have feedback or need assistance with the MCP directory API, please join our Discord server