mcp-server-template
A production-ready MCP server template with typed tools, schema validation, tests, and Docker support, including example tools for text stats, weather, and notes.
README
MCP Server Template
A production-ready starting point for a Model Context Protocol server: typed tools with schema-validated inputs, real tests, a multi-stage Docker image, and a CI pipeline — the boring parts done right so the next MCP server starts at mile 10.
It ships with three example tools that cover the shapes you'll actually build: a pure tool, a networked tool, and a stateful tool.
Architecture
flowchart TD
Client["MCP client<br/>Claude Desktop · IDE · agent"] -->|JSON-RPC over stdio| Entry["index.ts<br/>load env · connect transport"]
Entry --> Server["server.ts<br/>buildServer()"]
Server --> Tools["tools/*<br/>name + zod schema + handler"]
Tools --> Lib["lib/*<br/>logger · result · http · env"]
Construction is kept separate from transport, so the same server runs over stdio in production and over an in-memory transport in tests — no mocks. Full write-up in ARCHITECTURE.md.
Enterprise architecture
| Pillar | How the template applies it |
|---|---|
| Resilience | a thrown tool handler is contained per call (returned as an error result) — one bad call never crashes the server |
| Observability | structured, leveled logging to stderr (stdout is reserved for the MCP protocol) |
| Reproducibility | committed lockfile + Node pinned via .nvmrc, and tests that run the real server over an in-memory transport — no mocks |
Features
- 🧩 Modular tools — one file per tool group, registered in one place
- ✅ Schema-validated inputs via zod — bad calls fail fast
- 🧪 Real tests — an in-memory client/server harness, no mocks (
node:test) - 🐳 Multi-stage Docker image that runs as a non-root user
- 🤖 CI — format, type-check, test, build, and a Docker build, on every push/PR
- 🔇 Protocol-safe logging — stdout is reserved for MCP; logs go to stderr
- 🔑 No secrets in the repo — config via env, with a
.env.example
Quickstart
nvm use # or Node 20+
npm install
npm run dev # run the server over stdio (Ctrl-C to stop)
npm test # run the test suite
npm run build # compile to dist/
Example tools
| Tool | Kind | What it shows |
|---|---|---|
text_stats |
pure | Validated input → structured output, no side effects |
get_weather |
networked | External API (Open-Meteo, no key), timeouts, error handling |
note_set / note_get / note_list / note_delete |
stateful | File-backed persistence shared across tools |
Adding your own tool
This is the whole point of the template — it's a three-step change:
-
Create
src/tools/my-thing.ts:import { z } from "zod"; import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { text } from "../lib/result.js"; export function registerMyThingTools(server: McpServer): void { server.tool( "greet", "Say hello to someone.", { name: z.string().describe("Who to greet") }, async ({ name }) => text(`Hello, ${name}!`), ); } -
Register it in
src/tools/index.ts(one line). -
Done — transport, validation, error handling, tests, and Docker need no changes.
Connect it to a client
Build first (npm run build), then point your MCP client at dist/index.js.
Example config (e.g. Claude Desktop) in examples/mcp-config.json:
{
"mcpServers": {
"template": {
"command": "node",
"args": ["/absolute/path/to/mcp-server-template/dist/index.js"]
}
}
}
Testing
npm test builds the real server, connects a real MCP client over an in-memory
transport, and exercises tools end to end (schema validation included). Network
tools aren't hit in CI — tests stay fast and deterministic.
Docker
docker build -t mcp-server-template .
docker run --rm -i mcp-server-template # -i: MCP talks over stdio
Project structure
src/
├── index.ts # entrypoint: load env, build server, connect stdio
├── server.ts # buildServer() — construction, transport-agnostic
├── lib/
│ ├── logger.ts # stderr-only logging
│ ├── result.ts # text() / errorResult() content helpers
│ ├── http.ts # fetchJson() with timeout
│ └── env.ts # minimal .env loader
└── tools/
├── index.ts # registerAllTools() — add new groups here
├── text.ts # pure tool
├── weather.ts # networked tool
└── notes.ts # stateful tool
test/ # in-memory client/server tests
License
MIT © Eric Agyemang
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。