MCP Server Starter

MCP Server Starter

A production-shaped starter for putting an MCP server in front of an existing app, with OAuth and enterprise SSO handled through Clerk, enabling AI assistants to act on your product on behalf of logged-in users.

Category
访问服务器

README

MCP Server Starter

A production-shaped starting point for putting an MCP server in front of an existing app, so AI assistants can act on your product on behalf of a logged-in user.

Clerk handles all the OAuth. That is the headline: your customers sign in through whatever identity provider they already use -- Okta, Entra ID, Google Workspace -- and it flows straight through to the MCP connection with no extra work from you. See docs/AUTH.md.

What you get

  • A working OAuth 2.1 authorization flow, including the discovery endpoints and dynamic client registration that MCP clients require. This is the part that eats a week if you hand-roll it.
  • Enterprise SSO for free, via Clerk connections.
  • Scope-gated tools -- callers only ever see the tools their grant covers.
  • A tool registry with one uniform handler signature, audit logging, and a sane error contract.
  • Three example tools showing the shape to copy.

What you have to write

One file: mcp/tools.ts. Plus services/index.ts, which is where you point at your app's real business logic instead of the shipped stub.

Building this with an AI assistant

This repo ships with AGENTS.md — standing instructions for coding agents. Claude Code picks it up automatically via CLAUDE.md; Cursor, Codex, and most other agents read AGENTS.md directly.

It tells the agent which two files to edit, which files to leave alone, the anti-patterns to refuse (a raw-SQL tool being the big one), and the exact commands to verify its own work rather than declaring success because the code compiled.

So the workflow is just: open the repo with your assistant and tell it what your app does and what your users need to accomplish. It has the rest.

One thing worth doing yourself: skim docs/TOOL-DESIGN.md first. Which tools you expose is a product decision, and it is the decision that determines whether the finished server is good. The agent can write them well; it cannot tell you what your users are trying to do.

Quickstart

npm install
cp .env.example .env.local     # add your Clerk keys
npm run dev

Then in the Clerk Dashboard, enable dynamic client registration under OAuth applications (details and the security trade-off are in docs/AUTH.md).

Point an MCP client at http://localhost:3000/mcp. For local testing the MCP Inspector is the fastest path:

npx @modelcontextprotocol/inspector

You should get bounced through a Clerk sign-in, land back in the client, and see three tools listed.

Layout

Path What it is
AGENTS.md Standing instructions for AI coding agents. CLAUDE.md imports it.
mcp/tools.ts The file you edit. Your tool definitions.
services/index.ts The other file you edit. Adapter onto your app's business logic. Ships as a stub.
mcp/registry.ts Tool type, scope filtering, error and result helpers.
mcp/context.ts Per-request context handed to every tool (user, org, scopes, services).
mcp/scopes.ts Scope definitions and the fail-closed check.
mcp/audit.ts Metadata-only audit logging.
app/[transport]/route.ts Auth-to-tools wiring. Serves /mcp and /sse.
app/.well-known/** OAuth discovery documents. Must stay public.

Read these before you build

  • docs/TOOL-DESIGN.md -- the one that actually determines whether your server is any good. Covers why exposing a generic query tool over your database is the wrong move, and what to do instead.
  • docs/AUTH.md -- how the Clerk flow works, the SSO story, and the dynamic-client-registration security setting you need to make a deliberate call on.
  • docs/ADAPTING.md -- step-by-step from clone to your own server.

Stack

Next.js 15 App Router · @modelcontextprotocol/sdk · mcp-handler · @clerk/nextjs + @clerk/mcp-tools · Zod. Deploys to Vercel as-is; nothing here is Vercel-specific except the convenience of it.

Built and verified against: next@15.5.23, @clerk/nextjs@6.39.6, @clerk/mcp-tools@0.2.2, mcp-handler@1.1.0, @modelcontextprotocol/sdk@1.26.0, zod@3.25.76. If something in the auth wiring stops working after an upgrade, that combination is a known-good baseline to fall back to.

What was actually tested

Not just "it compiles":

  • tsc --noEmit clean across all files, including the .well-known routes (which tsc's default globs skip, because the directory starts with a dot — they were checked separately).
  • next build succeeds and registers all three routes, confirming Next.js does serve dot-directory paths.
  • Unauthenticated POST /mcp returns 401 with a correct WWW-Authenticate: Bearer ... resource_metadata="..." header pointing at the metadata route.
  • GET /.well-known/oauth-protected-resource/mcp returns 200 with CORS headers and a well-formed document naming the Clerk authorization server.

The tools themselves have not been exercised against a live Clerk instance — that needs real keys. Step 1 of docs/ADAPTING.md walks through it.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选