mcp-trellis

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.

Category
Visit Server

README

mcp-trellis

CI License: MIT

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:

Architecture: connector → edge → OAuth or MCP → your ports

Sequence: OAuth authorize and token, then MCP tool call

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

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured