Secure MCP Starter
A reference MCP server demonstrating authentication, authorization, approval workflows, and audit logging for a notes domain with secure defaults.
README
Secure MCP Starter
A deliberately small TypeScript reference server that makes authentication, authorization, approval, auditability, and safe defaults visible.
Most MCP demos start with a calculator tool. This starter begins one step later: what happens when a tool can change data?
It implements a tiny notes domain so the security boundaries remain easy to inspect. Reads are scope-gated. Changes are proposed first, approved through a separate HTTP control plane, and applied exactly once. Every decision produces a structured audit event with secrets removed.
Security properties
| Control | Implementation |
|---|---|
| Authentication | Separate reader, operator, and approver credentials |
| Authorization | Scope checks inside every tool handler |
| Human approval | Out-of-band approval endpoint unavailable to the MCP agent |
| Replay protection | Approved proposals are single-use and time-limited |
| Input safety | Strict Zod schemas with size limits |
| Network safety | Loopback binding and Host allow-list by default |
| Abuse resistance | Per-credential/IP fixed-window rate limiting |
| Secret handling | Credentials come from the environment and audit fields are redacted |
| Transport | Stateless Streamable HTTP with JSON responses |
| Supply chain | Locked dependencies, Dependabot, CI, and CodeQL workflows |
This is a reference starter, not a claim of turnkey production security. The environment-token verifier intentionally keeps local setup simple. Replace it with a standards-compliant OAuth 2.1 authorization server and validate resource indicators before deploying publicly. See Production hardening.
Architecture
flowchart LR
C[MCP client] -->|Bearer token| G[HTTP security boundary]
G -->|rate limit + authenticate| M[MCP server]
M -->|scope: notes:read| N[(Note store)]
M -->|scope: notes:propose| P[(Proposal store)]
H[Human operator] -->|separate credential| A[Approval endpoint]
A --> P
M -->|approved + scope: notes:apply| P
M --> N
G --> L[Redacted audit stream]
A --> L
M --> L
The control plane and agent plane intentionally use different credentials. An agent cannot approve its own proposal through an MCP tool.
Quick start
Requirements: Node.js 20.12 or newer.
npm install
cp .env.example .env
Generate three different secrets and place them in .env:
openssl rand -hex 32
Export the file into your shell and start the server:
set -a
source .env
set +a
npm run dev
The server listens on http://127.0.0.1:3000/mcp. A public health check is available
at http://127.0.0.1:3000/healthz.
Connect an MCP client
Configure a Streamable HTTP connection with:
{
"url": "http://127.0.0.1:3000/mcp",
"headers": {
"Authorization": "Bearer ${MCP_READER_TOKEN}"
}
}
Exact configuration syntax varies by client. Do not commit expanded secrets.
For a local process-spawned integration, build and use the restricted stdio entrypoint:
{
"command": "node",
"args": ["/absolute/path/to/secure-mcp-starter/dist/stdio.js"]
}
The stdio entrypoint can read and propose, but cannot approve or apply changes.
Demonstrate the approval boundary
- Connect with the reader credential.
- Call
note_change_propose. - Copy the returned proposal ID.
- An independent operator approves it outside the MCP connection:
curl --request POST \
--header "Authorization: Bearer ${MCP_APPROVER_TOKEN}" \
--header "Content-Type: application/json" \
--data '{"decision":"approve"}' \
"http://127.0.0.1:3000/admin/proposals/PROPOSAL_ID/approval"
- Reconnect with the operator credential and call
note_change_apply. - A second apply attempt fails because approvals are single-use.
MCP surface
| Primitive | Name | Required authority |
|---|---|---|
| Tool | notes_list |
notes:read |
| Tool | note_change_propose |
notes:propose |
| Tool | note_change_apply |
notes:apply + approved proposal |
| Resource | security://policy |
Connection-level authentication |
| Prompt | review-change-safely |
Connection-level authentication |
Project structure
src/
├── auth.ts # Constant-time token checks and scopes
├── config.ts # Fail-fast environment validation
├── http.ts # Streamable HTTP and independent approval route
├── mcp-server.ts # MCP tools, resource, and prompt
├── rate-limit.ts # Small in-memory limiter
├── stdio.ts # Restricted local transport
└── stores/
├── approval-store.ts # Expiring, single-use proposals
└── note-store.ts # Replaceable sample persistence
Read Architecture, Security model, and Production hardening before extending the starter.
Quality checks
npm run check
npm run build
The repository runs formatting, linting, strict type checking, tests with coverage, CodeQL, dependency review, and Docker builds in GitHub Actions.
Extension path
- Replace environment tokens with OAuth 2.1 access-token verification.
- Replace both in-memory stores with transactional persistence.
- Add tenant identity to every storage key and authorization decision.
- Move rate-limit state to Redis or an equivalent shared store.
- Send audit events to append-only storage with retention controls.
- Add integration tests using the MCP client SDK and Inspector.
Contributing
See CONTRIBUTING.md. Security reports belong in a private GitHub security advisory as described in SECURITY.md.
Related repositories
- Agentic System Design Notes — the architectural reasoning behind permissions, approvals, memory, and evaluation.
- System Design Sketchbook — eight production-minded distributed-system studies.
License
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。