mcp-helmet

mcp-helmet

A production middleware toolkit for MCP servers providing auth, health checks, graceful shutdown, and transport ergonomics, enabling rapid development of robust MCP servers.

Category
访问服务器

README

mcp-helmet

npm CI License Types

Production middleware for MCP servers. Auth, sessions, health checks, graceful shutdown, transport ergonomics. Composable middleware borrowed in spirit from Express's helmet.

mcp-helmet wraps the official @modelcontextprotocol/sdk with the things it doesn't ship: auto transport detection, content wrapping, health checks, graceful shutdown, session management, and auth middleware. One package. Composable. Drop what you don't need. Go from hello world to production in minutes, not days.

npm install mcp-helmet @modelcontextprotocol/sdk zod

Peer dependencies: @modelcontextprotocol/sdk ^1.29.0, zod ^3.22.0 or ^3.25 (v4). zod-to-json-schema is an optional peer for Zod v3 users.

Quickstart

The fastest way is the scaffolder:

npx mcp-helmet init my-server --transport http --auth bearer
cd my-server
npm install
npm run dev

You get a working MCP server with healthCheck(), gracefulShutdown(), optional auth, a multistage Dockerfile, and a typechecked tsconfig. Drop flags to skip pieces (--no-docker, --no-health, etc.) or customise after the fact.

Or wire it manually:

import { createServer } from "mcp-helmet";
import { z } from "zod";

const server = createServer({ name: "hello", version: "1.0.0" });

server.tool("greet", { name: z.string() }, async ({ name }) => {
  return `Hello, ${name}!`;
});

await server.start();

That's it. No transport wiring, no content array construction, no signal handlers. Run it:

# Local development (stdio, the default)
npx tsx src/index.ts

# Production (HTTP)
MCP_TRANSPORT=http PORT=3000 node dist/index.js

Same code, both modes.

Auth in 6 lines

Bearer token verification, with the verified principal available inside any tool handler:

import { createServer, bearerAuth, getAuthContext } from "mcp-helmet";

const server = createServer({ name: "secure", version: "1.0.0" });

server.use(bearerAuth({
  verify: async (token) => {
    const claims = await verifyJwt(token); // your call
    return { user: claims.sub, scopes: claims.scope?.split(" ") ?? [] };
  },
}));

server.tool("whoami", {}, async () => {
  const auth = getAuthContext();
  return { user: auth?.user, scopes: auth?.scopes };
});

await server.start();

The single-argument tool handler signature stays the same — getAuthContext() reads from AsyncLocalStorage, so it works from any depth in the async chain.

Why this exists

We audited 30 production MCP servers and 320 GitHub issues across the official SDKs. Three patterns kept showing up:

  1. Every server rewrites the same 20-40 lines of setup. Transport selection, content wrapping, error formatting, signal handling. The SDK gives you the building blocks; this gives you the house.

  2. Servers that work locally break in production. Docker containers exit after one response, Kubernetes pods lose sessions, no health check for load balancers to probe. 52% of remote MCP endpoints in a recent survey were dead.

  3. Nobody can figure out auth. "How do I access the bearer token inside my tool?" is the most asked question across both SDK repos.

mcp-helmet solves these with composable middleware that extends the SDK without replacing it.

Status

v0.1.0-alpha — feature complete. Currently shipped:

  • createServer() with auto content wrapping (string, object, Content[])
  • ✅ Auto transport detection via MCP_TRANSPORT env var
  • ✅ Zod v3 + v4 compatibility shim
  • ✅ Composable middleware system (server.use(mw))
  • healthCheck() middleware
  • gracefulShutdown() middleware
  • bearerAuth() and apiKeyAuth() middleware with AsyncLocalStorage-based getAuthContext()
  • rateLimiter() middleware (sliding window, IP- or key-based, standard 429 headers)
  • npx mcp-helmet init CLI scaffolder + Docker template

v0.1.0 stable will follow once the alpha cycle has 30+ days of real-world usage. v0.2 is on the ROADMAP: Redis-backed session store, structured logging middleware, Python port via FastMCP plugin.

How it relates to the official SDK

mcp-helmet is not a fork, an alternative, or a replacement. It's a convenience layer.

Concern Official SDK mcp-helmet
Protocol implementation Yes No, delegates to SDK
Transport classes Yes No, wraps SDK transports
Tool/resource/prompt registration Yes Yes, thinner API
OAuth server flows Yes (in v2 dev) No, out of scope
Bearer/API-key middleware Express-coupled in v2 Transport-agnostic, composable
Health checks No Yes, planned
Session externalization No Stopgap until upstream SEP
Docker/deployment templates No Yes, planned

The SDK is a peer dependency. You bring your own version. If the SDK adds features that overlap, the toolkit middleware becomes a thin pass-through.

Requirements

  • Node.js 20+
  • @modelcontextprotocol/sdk ^1.29.0
  • TypeScript 5.4+ (recommended, not required)
  • Zod 3.22+ or 3.25+ (v4 via zod/v4 subpath)

Contributing

PRs and issues welcome. See CONTRIBUTING.md for setup, test, and PR conventions.

Security

See SECURITY.md for the responsible disclosure path.

License

MIT

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选