MCP Production Demo
An MCP server providing live GitHub repository and issue search tools, with production-grade features like config validation, structured logging, authentication, and support for both stdio and HTTP transports.
README
MCP Production Demo (TypeScript)
A minimal but genuinely production-shaped MCP server: real API calls (live GitHub API), typed config validation, structured logging, consistent error handling, auth on the network transport, health checks, graceful shutdown, Docker packaging, and tests. This is what the toy stdio scripts were missing.
What's different from the toy version
| Concern | Toy version | This version |
|---|---|---|
| Data | hardcoded fake dict | live GitHub REST API |
| Config | none | zod-validated env, fails fast on boot if misconfigured |
| Errors | uncaught = crash/hang | every handler wrapped, typed errors, client never sees a stack trace |
| Logging | none | structured JSON (pino), stderr-only so it can't corrupt stdio protocol |
| Timeouts | none | every outbound call has an AbortController timeout |
| Auth | none | bearer token required on the HTTP transport |
| Transport | stdio only | both stdio (local/desktop) and Streamable HTTP (deployed) |
| Deployment | none | multi-stage Dockerfile, non-root user, health check |
| Tests | none | error-handling contract covered with node:test |
Project layout
src/
config.ts env validation (zod) — the only place process.env is read
lib/
logger.ts pino logger, stderr-only
errors.ts typed error classes (Validation / Upstream / Timeout)
http.ts fetch wrapper: timeout + typed errors
safeTool.ts wraps every tool: catch, log, clean client-facing result
tools/
github.ts real tools: get_repo, search_issues (live GitHub API)
mcpServer.ts registers all tools onto an McpServer instance
stdioEntry.ts entrypoint for local/desktop clients
httpEntry.ts entrypoint for a deployed, authenticated server
safeTool.test.ts tests for the error-handling contract
Setup
npm install
cp .env.example .env
# edit .env: add a GITHUB_TOKEN (unauthenticated GitHub calls are capped
# at 60/hour and will 403 fast — I hit this in testing), and if you'll
# run the HTTP transport, an MCP_AUTH_TOKEN (openssl rand -hex 32)
Run it — stdio (local/desktop)
npm run dev:stdio
This is what you'd point Claude Desktop / Claude Code at directly (see their MCP config docs) instead of writing your own client script.
Run it — HTTP (deployed)
MCP_TRANSPORT=http npm run dev:http
# in another terminal:
curl http://localhost:3000/health
curl -X POST http://localhost:3000/mcp \
-H "Authorization: Bearer $MCP_AUTH_TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"curl","version":"1.0"}}}'
A request with no/wrong Authorization header gets a 401 before it ever
reaches the MCP layer.
Tests
npm test
Covers the actual thing that matters in production: no matter what a tool
handler throws, the client always gets back a well-formed
{ content, isError } — never a raw stack trace, never a hang.
Docker
docker build -t mcp-production-demo .
docker run -p 3000:3000 \
-e MCP_AUTH_TOKEN=$(openssl rand -hex 32) \
-e GITHUB_TOKEN=ghp_xxx \
mcp-production-demo
Multi-stage build (compiled output only ships, no devDependencies),
runs as a non-root user, has a HEALTHCHECK.
Production decisions worth understanding (not just copying)
- Logs go to stderr, always. stdout is reserved for the JSON-RPC
protocol stream on the stdio transport. A single stray
console.logwould silently corrupt every message after it — this bit me in early testing of similar setups, which is whylogger.tscalls it out explicitly. - Fail fast on bad config.
config.tsvalidates env vars at import time and callsprocess.exit(1)on failure, with the specific field that's wrong. A server that boots "successfully" into a broken state is worse than one that refuses to start. - Never forward raw errors to the client.
safeTool.tslogs full detail server-side (including stack traces for unexpected errors) but only ever returns a small set of clean, typed messages to the MCP client. I confirmed this live: an unauthenticated call to the GitHub API from this sandbox hit their real rate limit and returned a403with a detailed message — the client only saw "The upstream service returned an error (403). Please try again later," while the full GitHub response was in the server log. - Stateless HTTP by default. Each
/mcprequest gets a freshMcpServer+StreamableHTTPServerTransport. No shared session state means it scales horizontally with zero coordination. If you need long-lived stateful sessions (e.g. server-initiated notifications between calls), you'd switch to the SDK's stateful mode with asessionId -> transportmap — more capable, more to get right. - Every outbound call has a timeout.
lib/http.tsusesAbortControllerso a hung upstream can't hang your tool call indefinitely and, transitively, whatever's waiting on it. - Graceful shutdown matters for zero-downtime deploys.
httpEntry.tshandlesSIGTERM/SIGINTby stopping new connections and waiting for in-flight ones to finish, with a forced-exit timeout as a backstop. Without this, a rolling deploy on k8s/ECS kills in-flight requests mid-response.
Where this still isn't "enterprise production"
Being straight about the gaps rather than overselling it:
- Auth is a single shared bearer token. Fine for an internal tool; for anything multi-tenant you'd want the SDK's OAuth support instead.
- No rate limiting on the HTTP endpoint itself (only on the upstream
GitHub calls) — add something like
express-rate-limitbefore internet exposure. - No metrics/tracing (Prometheus, OpenTelemetry) — logs alone aren't enough to debug latency issues at scale.
- No CI pipeline —
npm testanddocker buildshould run in GitHub Actions (or similar) on every PR, not just locally.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。