AI Skill Hub 强烈推荐:FastMCP 是一款优质的MCP工具。已获得 3.1k 颗 GitHub Star,AI 综合评分 8.0 分,在同类工具中表现稳健。如果你正在寻找可靠的MCP工具解决方案,这是一个值得深入了解的选择。
FastMCP 是一款遵循 MCP(Model Context Protocol)标准协议的 AI 工具扩展。通过 MCP 协议,它可以让 Claude、Cursor 等主流 AI 客户端直接访问和操作外部工具、数据源和服务,实现 AI 能力的无缝扩展。无论是文件操作、数据库查询还是 API 调用,都可以通过自然语言在 AI 对话中直接触发,极大提升生产效率。
FastMCP 是一款遵循 MCP(Model Context Protocol)标准协议的 AI 工具扩展。通过 MCP 协议,它可以让 Claude、Cursor 等主流 AI 客户端直接访问和操作外部工具、数据源和服务,实现 AI 能力的无缝扩展。无论是文件操作、数据库查询还是 API 调用,都可以通过自然语言在 AI 对话中直接触发,极大提升生产效率。
# 方式一:通过 Claude Code CLI 一键安装
claude skill install https://github.com/punkpeye/fastmcp
# 方式二:手动配置 claude_desktop_config.json
{
"mcpServers": {
"fastmcp": {
"command": "npx",
"args": ["-y", "fastmcp"]
}
}
}
# 配置文件位置
# macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
# Windows: %APPDATA%/Claude/claude_desktop_config.json
# 安装后在 Claude 对话中直接使用 # 示例: 用户: 请帮我用 FastMCP 执行以下任务... Claude: [自动调用 FastMCP MCP 工具处理请求] # 查看可用工具列表 # 在 Claude 中输入:"列出所有可用的 MCP 工具"
// claude_desktop_config.json 配置示例
{
"mcpServers": {
"fastmcp": {
"command": "npx",
"args": ["-y", "fastmcp"],
"env": {
// "API_KEY": "your-api-key-here"
}
}
}
}
// 保存后重启 Claude Desktop 生效
A TypeScript framework for building MCP servers capable of handling client sessions.
[!NOTE] For a Python implementation, see FastMCP.
npm install fastmcp
[!NOTE] There are many real-world examples of using FastMCP in the wild. See the Showcase for examples.
import { FastMCP } from "fastmcp";
import { z } from "zod"; // Or any validation library that supports Standard Schema
const server = new FastMCP({
name: "My Server",
version: "1.0.0",
});
server.addTool({
name: "add",
description: "Add two numbers",
parameters: z.object({
a: z.number(),
b: z.number(),
}),
execute: async (args) => {
return String(args.a + args.b);
},
});
server.start({
transportType: "stdio",
});
That's it! You have a working MCP server.
You can test the server in terminal with:
```bash git clone https://github.com/punkpeye/fastmcp.git cd fastmcp
pnpm install pnpm build
npx fastmcp dev src/examples/addition.ts
npx fastmcp inspect src/examples/addition.ts ```
If you are looking for a boilerplate repository to build your own MCP server, check out fastmcp-boilerplate.
FastMCP supports multiple transport options for remote communication, allowing an MCP hosted on a remote machine to be accessed over the network.
HTTP streaming provides a more efficient alternative to SSE in environments that support it, with potentially better performance for larger payloads.
You can run the server with HTTP streaming support:
server.start({
transportType: "httpStream",
httpStream: {
port: 8080,
},
});
This will start the server and listen for HTTP streaming connections on http://localhost:8080/mcp.
Note: You can also customize the endpoint path using thehttpStream.endpointoption (default is/mcp).
Note: This also starts an SSE server on http://localhost:8080/sse.
You can connect to these servers using the appropriate client transport.
For HTTP streaming connections:
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
const client = new Client(
{
name: "example-client",
version: "1.0.0",
},
{
capabilities: {},
},
);
const transport = new StreamableHTTPClientTransport(
new URL(`http://localhost:8080/mcp`),
);
await client.connect(transport);
For SSE connections:
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
const client = new Client(
{
name: "example-client",
version: "1.0.0",
},
{
capabilities: {},
},
);
const transport = new SSEClientTransport(new URL(`http://localhost:8080/sse`));
await client.connect(transport);
FastMCP supports HTTPS for secure connections by providing SSL certificate options:
server.start({
transportType: "httpStream",
httpStream: {
port: 8443,
sslCert: "./path/to/cert.pem",
sslKey: "./path/to/key.pem",
sslCa: "./path/to/ca.pem", // Optional: for client certificate authentication
},
});
This will start the server with HTTPS on https://localhost:8443/mcp.
SSL Options:
sslCert - Path to SSL certificate filesslKey - Path to SSL private key filesslCa - (Optional) Path to CA certificate for mutual TLS authenticationFor testing, you can generate self-signed certificates:
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes -subj "/CN=localhost"
For production, obtain certificates from a trusted CA like Let's Encrypt.
See the https-server example for a complete demonstration.
FastMCP allows you to add custom HTTP routes alongside MCP endpoints, enabling you to build comprehensive HTTP services that include REST APIs, webhooks, admin interfaces, and more - all within the same server process.
// Add REST API endpoints
server.addRoute("GET", "/api/users", async (req, res) => {
res.json({ users: [] });
});
// Handle path parameters
server.addRoute("GET", "/api/users/:id", async (req, res) => {
res.json({
userId: req.params.id,
query: req.query, // Access query parameters
});
});
// Handle POST requests with body parsing
server.addRoute("POST", "/api/users", async (req, res) => {
const body = await req.json();
res.status(201).json({ created: body });
});
// Serve HTML content
server.addRoute("GET", "/admin", async (req, res) => {
res.send("<html><body><h1>Admin Panel</h1></body></html>");
});
// Handle webhooks
server.addRoute("POST", "/webhook/github", async (req, res) => {
const payload = await req.json();
const event = req.headers["x-github-event"];
// Process webhook...
res.json({ received: true });
});
Custom routes support:
:param) and wildcards (*)authenticate function as MCPRoutes are matched in the order they are registered, allowing you to define specific routes before catch-all patterns.
By default, custom routes require authentication (if configured). You can make routes public by adding the { public: true } option:
// Public route - no authentication required
server.addRoute(
"GET",
"/.well-known/openid-configuration",
async (req, res) => {
res.json({
issuer: "https://example.com",
authorization_endpoint: "https://example.com/auth",
token_endpoint: "https://example.com/token",
});
},
{ public: true },
);
// Private route - requires authentication
server.addRoute("GET", "/api/users", async (req, res) => {
// req.auth contains authenticated user data
res.json({ users: [] });
});
// Public static files
server.addRoute(
"GET",
"/public/*",
async (req, res) => {
// Serve static files without authentication
res.send(`File: ${req.url}`);
},
{ public: true },
);
Public routes are perfect for:
.well-known/*)See the custom-routes example for a complete demonstration.
FastMCP supports edge runtimes like Cloudflare Workers, enabling deployment of MCP servers to the edge with minimal latency worldwide.
| Use Case | Class | Import |
|---|---|---|
| Node.js, Express, Bun | FastMCP | import { FastMCP } from "fastmcp" |
| Cloudflare Workers, Deno Deploy | EdgeFastMCP | import { EdgeFastMCP } from "fastmcp/edge" |
| Feature | FastMCP | EdgeFastMCP |
|---|---|---|
| Runtime | Node.js | Edge (V8 isolates) |
| Start method | server.start({ port }) | export default server |
| Transport | stdio, httpStream, SSE | HTTP Streamable only |
| Sessions | Stateful or stateless | Stateless only |
| File system | Yes | No |
| OAuth/Authentication | Built-in authenticate option | Use Hono middleware (built-in planned) |
| Custom routes | server.getApp() | server.getApp() |
Note: Built-in authentication for EdgeFastMCP is planned for a future release. Both FastMCP and EdgeFastMCP use Hono internally, so there's no technical barrier—EdgeFastMCP was simply written before OAuth was added to FastMCP. PRs are welcome to add anauthenticateoption that accepts webRequestinstead of Node.jshttp.IncomingMessage. In the meantime, use Hono middleware:> const app = server.getApp(); > app.use("/api/*", async (c, next) => { > if (c.req.header("authorization") !== "Bearer secret") { > return c.json({ error: "Unauthorized" }, 401); > } > await next(); > }); >
To deploy FastMCP to Cloudflare Workers, use the EdgeFastMCP class from the /edge subpath:
import { EdgeFastMCP } from "fastmcp/edge";
import { z } from "zod";
const server = new EdgeFastMCP({
name: "My Edge Server",
version: "1.0.0",
description: "MCP server running on Cloudflare Workers",
});
// Add tools, resources, prompts as usual
server.addTool({
name: "greet",
description: "Greet someone",
parameters: z.object({
name: z.string(),
}),
execute: async ({ name }) => {
return `Hello, ${name}! Served from the edge.`;
},
});
// Export the server as the default (required for Cloudflare Workers)
export default server;
When running on edge runtimes:
You can access the underlying Hono app to add custom HTTP routes:
const app = server.getApp();
// Add a landing page
app.get("/", (c) => c.html("<h1>Welcome to my MCP server</h1>"));
// Add REST API endpoints
app.get("/api/status", (c) => c.json({ status: "ok" }));
Configure your wrangler.toml:
name = "my-mcp-server"
main = "src/index.ts"
compatibility_date = "2024-01-01"
Deploy with:
wrangler deploy
See the edge-cloudflare-worker example for a complete demonstration.
FastMCP supports stateless operation for HTTP streaming, where each request is handled independently without maintaining persistent sessions. This is ideal for serverless environments, load-balanced deployments, or when session state isn't required.
In stateless mode:
You can enable stateless mode by adding the stateless: true option:
server.start({
transportType: "httpStream",
httpStream: {
port: 8080,
stateless: true,
},
});
Note: Stateless mode is only available with HTTP streaming transport. Features that depend on persistent sessions (like session-specific state) will not be available in stateless mode.
You can also enable stateless mode using CLI arguments or environment variables:
```bash
FASTMCP_STATELESS=true npx fastmcp dev src/server.ts
The `/ready` health check endpoint will indicate when the server is running in stateless mode:
json { "mode": "stateless", "ready": 1, "status": "ready", "total": 1 } ```
FastMCP is built on top of the official SDK.
The official SDK provides foundational blocks for building MCPs, but leaves many implementation details to you:
FastMCP eliminates this complexity by providing an opinionated framework that:
When to choose FastMCP: You want to build MCP servers quickly without dealing with low-level implementation details.
When to use the official SDK: You need maximum control or have specific architectural requirements. In this case, we encourage referencing FastMCP's implementation to avoid common pitfalls.
npx fastmcp dev src/server.ts --transport http-stream --port 8080 --stateless true
When you run FastMCP with the httpStream transport you can optionally expose a simple HTTP endpoint that returns a plain-text response useful for load-balancer or container orchestration liveness checks.
Enable (or customise) the endpoint via the health key in the server options:
const server = new FastMCP({
name: "My Server",
version: "1.0.0",
health: {
// Enable / disable (default: true)
enabled: true,
// Body returned by the endpoint (default: 'ok')
message: "healthy",
// Path that should respond (default: '/health')
path: "/healthz",
// HTTP status code to return (default: 200)
status: 200,
},
});
await server.start({
transportType: "httpStream",
httpStream: { port: 8080 },
});
Now a request to http://localhost:8080/healthz will return:
HTTP/1.1 200 OK
content-type: text/plain
healthy
The endpoint is ignored when the server is started with the stdio transport.
FastMCP supports Roots - Feature that allows clients to provide a set of filesystem-like root locations that can be listed and dynamically updated. The Roots feature can be configured or disabled in server options:
const server = new FastMCP({
name: "My Server",
version: "1.0.0",
roots: {
// Set to false to explicitly disable roots support
enabled: false,
// By default, roots support is enabled (true)
},
});
This provides the following benefits:
You can listen for root changes in your server:
server.on("connect", (event) => {
const session = event.session;
// Access the current roots
console.log("Initial roots:", session.roots);
// Listen for changes to the roots
session.on("rootsChanged", (event) => {
console.log("Roots changed:", event.roots);
});
});
When a client doesn't support roots or when roots functionality is explicitly disabled, these operations will gracefully handle the situation without throwing errors.
FastMCP 是一个专为 TypeScript 开发者设计的轻量级框架,旨在简化 MCP (Model Context Protocol) 服务器的构建过程。它能够高效处理客户端 Session,让开发者能够快速构建具备复杂交互能力的 MCP 服务。需要注意的是,本项目为 TypeScript 实现,若您更倾向于 Python 生态,可以参考对应的 Python 版本 FastMCP。
FastMCP 提供了丰富且易用的功能特性,包括极其简单�� Tool、Resource 和 Prompt 定义方式。它原生支持 Authentication 身份验证、通过 Context 传递 Header、以及完善的 Session ID 和 Request ID 追踪机制。此外,框架还支持多媒体内容(如 Image 和 Audio)的返回、Embedded 资源处理、详细的 Logging 日志记录以及健壮的 Error handling 错误处理机制。
您可以通过 npm 包管理器快速安装 FastMCP。在您的项目目录下运行以下命令即可完成安装:`npm install fastmcp`。安装完成后,即可开始构建您的 MCP 服务。
FastMCP 提供了极简的快速入门体验。您可以结合 zod 等验证库轻松定义 Tool。例如,通过 `server.addTool` 即可定义具备参数校验的工具。开发过程中,您可以使用 `npx fastmcp dev` 进行本地调试,或者使用 `npx fastmcp inspect` 调用 MCP Inspector 进行交互式测试。如果您需要项目模板,推荐使用 fastmcp-boilerplate。
FastMCP 支持多种传输协议(Transport options)以实现远程通信,允许通过网络访问托管在远程机器上的 MCP 服务。针对支持的环境,它提供了比 SSE 更高效的 HTTP Streaming 模式。此外,您可以通过环境变量 `FASTMCP_STATELESS=true` 或 CLI 参数 `--stateless true` 来开��无状态模式,并利用 `/ready` 健康检查接口监控服务状态。
FastMCP 是基于官方 SDK 构建的高层封装。相比于官方 SDK 需要开发者处理大量底层实现细节,FastMCP 极大地简化了初始化与配置过程。它不仅提供了更高级的抽象,还通过内置的 HTTP 传输支持和健康检查(Health-check)端点,为负载均衡器或容器编排工具(如 Kubernetes)提供了友好的集成能力。
高质量的开源MCP工具
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
✅ MIT 协议 — 最宽松的开源协议之一,可自由商用、修改、分发,仅需保留版权声明。
总体来看,FastMCP 是一款质量优秀的MCP工具,在同类工具中具备一定竞争力。AI Skill Hub 将持续追踪其更新动态,建议收藏备用,结合自身场景选择合适时机引入使用。
| 原始名称 | fastmcp |
| Topics | mcptypescriptsse |
| GitHub | https://github.com/punkpeye/fastmcp |
| License | MIT |
| 语言 | TypeScript |
收录时间:2026-05-27 · 更新时间:2026-05-27 · License:MIT · AI Skill Hub 不对第三方内容的准确性作法律背书。
选择 Agent 类型,复制安装指令后粘贴到对应客户端