mcp-anything
MCP-Anything
只需一条命令,即可将任何代码库转换为 MCP 服务器。不仅限于 REST API,也不仅限于 OpenAPI 规范。

入门指南
pip install mcp-anything
# Generate an MCP server from any codebase
mcp-anything generate /path/to/your/app
# Or from a URL (OpenAPI, GraphQL, gRPC spec)
mcp-anything generate https://api.example.com/openapi.json
# Or directly from a local spec file
mcp-anything generate ./openapi.json你将获得一个完整的、可通过 pip 安装的 MCP 服务器,位于 ./mcp-<name>-server/ 中。只需几秒钟即可将其添加到你的智能体中:
stdio (本地,默认): 将 mcp.json 添加到你的 Claude Code .mcp.json 中:
{
"mcpServers": {
"my-app": { "command": "mcp-my-app", "args": [] }
}
}HTTP (远程/共享,推荐): 启动服务器并将你的智能体指向它:
mcp-anything generate /path/to/app --transport http
mcp-my-app # server runs on http://localhost:8000/sse{
"mcpServers": {
"my-app": { "url": "http://localhost:8000/sse" }
}
}目标
默认情况下,mcp-anything 会生成一个 Python / FastMCP 服务器。使用 --target=mcp-use 可改为生成 TypeScript / mcp-use 服务器:
mcp-anything generate /path/to/app --target mcp-use该 TypeScript 服务器使用 mcp-use SDK,并附带内置的检查器 (inspector)。
|
| |
语言 | Python | TypeScript |
SDK | FastMCP | mcp-use |
传输方式 | stdio / HTTP | HTTP (端口 3000) |
检查器 | 外部 | 内置于 /inspector |
安装 |
|
|
支持范围
mcp-anything 可以检测并封装 8 个生态系统中的源代码——包括 REST 框架、CLI 工具、API 规范和基于协议的服务。
生态系统 | 框架 / 来源 | 置信度 |
Python | argparse CLI | 0.90 |
Click CLI | 0.90 | |
Typer CLI | 0.85 | |
Flask | 0.95 | |
FastAPI | 0.95 | |
Django REST Framework | 0.95 | |
Java / Kotlin | Spring Boot (Java + Kotlin) | 0.95 |
Spring MVC (Java + Kotlin) | 0.85 | |
JAX-RS / Quarkus (Java + Kotlin) | 0.90 | |
Micronaut | 0.90 | |
JavaScript / TypeScript | Express.js | 0.95 |
Go | Gin | 0.95 |
Echo | 0.95 | |
Chi | 0.95 | |
Fiber | 0.95 | |
gorilla/mux | 0.90 | |
net/http | 0.85 | |
Ruby | Rails | 0.95 |
Rust | Actix-web | 0.95 |
Axum | 0.95 | |
Rocket | 0.95 | |
Warp | 0.90 | |
API 规范 | OpenAPI 3.x / Swagger 2.x | 0.88 |
GraphQL SDL | 0.95 | |
gRPC / Protobuf | 0.95 | |
协议 / IPC | WebSocket (JSON-RPC) | 0.85 |
MQTT / paho-mqtt | 0.90 | |
ZeroMQ | 0.90 | |
XML-RPC / raw socket | 0.90 | |
D-Bus | 0.90 |
直接传入 URL 以获取 API 规范:
mcp-anything generate https://api.example.com/openapi.json
作用域:控制暴露的内容
大型代码库可能拥有成百上千个端点。你可能不希望将它们全部作为 MCP 工具。以下三种机制可让你控制作用域:
使用 --include / --exclude 进行快速过滤:
# Only expose /api/v2 endpoints
mcp-anything generate ./my-app --include "/api/v2/*"
# Exclude internal and debug routes
mcp-anything generate ./my-app --exclude "/internal/*" --exclude "debug_*"审查模式 — 在生成前进行筛选:
# Step 1: analyze and pause
mcp-anything generate ./my-app --review
# Step 2: edit the generated scope.yaml (enable/disable per capability)
vim mcp-my-app-server/scope.yaml
# Step 3: resume generation with your curated scope
mcp-anything generate ./my-app --resume可重用的作用域文件:
# Use a pre-built scope file (check it into your repo)
mcp-anything generate ./my-app --scope-file ./mcp-scope.yaml模式匹配使用 glob 语法针对能力名称、源文件路径和描述进行匹配。在作用域文件中,你还可以对单个能力设置 enabled: false 以实现精确控制。
描述覆盖:自定义工具描述
自动生成的描述来源于源代码(文档字符串、OpenAPI 摘要、路由注释)。它们通常已经足够好,但有时你可能希望为 LLM 智能体提供更清晰的措辞。
生成后,输出目录中会写入一个 descriptions.yaml 文件,其中包含每个工具和参数的描述。编辑它,然后使用 --description 重新运行以应用你的更改:
# 1. Generate as usual
mcp-anything generate ./my-app
# 2. Edit descriptions
vim mcp-my-app-server/descriptions.yaml文件内容如下所示:
# Edit tool descriptions below. Run `mcp-anything generate --description` to apply.
tools:
list_users:
description: "List all users with optional filtering"
parameters:
role:
description: "Filter by user role"
limit:
description: "Max results to return"
create_user:
description: "Create a new user account"
parameters:
name:
description: "Full name of the user"# 3. Apply overrides — run from the generated server directory
cd mcp-my-app-server
mcp-anything generate --description
# Or from anywhere, pointing to the output directory
mcp-anything generate --description -o ./mcp-my-app-server仅应用已更改的描述。流水线会检测编辑内容,并仅重新生成受影响的阶段(实现、文档、打包),从而保持其他内容不变。
输出
mcp-<name>-server/
├── src/<name>/
│ ├── server.py # FastMCP server (stdio or HTTP/SSE)
│ ├── backend.py # Backend adapter (CLI / HTTP proxy / Python call)
│ ├── tools/ # Tool modules, one file per capability group
│ ├── prompts.py # Server-delivered MCP prompts
│ └── resources.py # Dynamic MCP resources
├── AGENTS.md # Tool index for coding agents
├── Dockerfile # Container deployment (HTTP mode)
├── mcp.json # Ready-to-paste MCP client config
└── pyproject.toml # pip install -e .为什么我们生成 AGENTS.md
MCP 解决了工具的调用问题——智能体调用工具并获取结果。但它没有解决项目层面的工具发现问题。
当像 Claude Code 这样的智能体打开你的仓库时,它会在进行任何 MCP 调用之前读取 AGENTS.md。该文件告诉它服务器能做什么、存在哪些工具以及如何使用它们——而无需建立活动连接。正如这篇文章所论证的那样,下一代智能体工作流依赖于智能体在调用之前能够推理可用能力的能力。AGENTS.md 就是这座桥梁:它是生成的服务器所暴露的所有内容的、人类可读且智能体可索引的地图。
为什么首选 HTTP 传输
stdio MCP 将服务器作为本地子进程运行——每个智能体会话一个进程,绑定到你的机器上。它适用于个人使用,但无法扩展。
HTTP 传输 (--transport http) 允许你:
部署一次,从任何地方连接(CI、云端智能体、团队成员)
在多个智能体会话之间共享单个服务器实例
在 Docker 或任何容器平台中运行
对于本地原型设计之外的任何场景,HTTP 都是正确的默认选择。
具体示例:GitHub MCP 服务器
官方 GitHub MCP 服务器 是一个手工构建的 Go 项目,暴露了约 80 个精选工具(问题、PR、仓库、操作、安全警报等)。一个团队花费了数月时间来构建和维护它。
如果你将 mcp-anything 指向 GitHub 的公共 OpenAPI 规范,会发生什么?
mcp-anything generate https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.json --name github --no-llm官方(手工构建) | mcp-anything(自动生成) | |
语言 | Go | Python |
构建时间 | 数月 | 数秒 |
工具 | ~80(精选子集) | ~1,093(每个 API 操作) |
后端 | 原生 Go SDK + GraphQL | 来自 OpenAPI 规范的 |
认证 | PAT / OAuth | 通过 |
传输方式 | stdio, HTTP | stdio (默认), HTTP ( |
文档 | 手写 README | 自动生成的 AGENTS.md + MCP 资源 |
生成的服务器涵盖了每一个 GitHub REST API 端点——仓库、问题、PR、操作、包、安全公告、代码搜索、Gist、组织、团队、通知等。每个端点都成为一个 MCP 工具,并带有从 OpenAPI 规范中提取的类型化参数。
官方服务器是精选的:为 LLM 实际需求选择了 80 个工具,并结合了自定义逻辑和 GraphQL 集成。自动生成的服务器是全面的:1,093 个工具覆盖了整个 API 表面。这就像定制西装与现成衣橱的区别——前者完美贴合,后者立即覆盖一切。
请参阅 examples/github-server/ 获取完整的生成代码。
缩小作用域以匹配官方服务器
但如果你只需要官方服务器暴露的那 80 个左右的工具呢?使用 --scope-file:
mcp-anything generate \
https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.json \
--name github-scoped --no-llm \
--scope-file examples/github-server-scoped/scope.yaml \
-o examples/github-server-scoped官方(手工构建) | 全量自动生成 | 限定作用域的自动生成 | |
工具 | ~80(精选) | 1,093(每个端点) | 67(匹配官方) |
构建时间 | 数月 | ~6 秒 | ~6 秒 |
覆盖范围 | 精选子集 + GraphQL | 整个 REST API | 与官方相同的 REST 端点 |
作用域控制 | 硬编码在 Go 中 | 无需 |
|
作用域文件 (examples/github-server-scoped/scope.yaml) 使用 exclude_patterns: ["*"] 默认排除所有内容,然后对映射到官方端点的 67 个特定工具设置 enabled: true。11 个官方工具使用 GraphQL 或 Copilot 特定 API,没有 REST 等效项——这些在作用域文件中进行了记录。
亲自复现:
# 1. Generate the full server (1,093 tools)
mcp-anything generate \
https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.json \
--name github --no-llm
# 2. Generate the scoped server (67 tools, matching official)
mcp-anything generate \
https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.json \
--name github-scoped --no-llm \
--scope-file examples/github-server-scoped/scope.yaml
# 3. Or use review mode to curate interactively
mcp-anything generate \
https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.json \
--name github-custom --no-llm --review
# Edit mcp-github-custom-server/scope.yaml, then:
mcp-anything generate \
https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.json \
--name github-custom --resume请参阅 examples/github-server-scoped/ 获取限定作用域后的输出。
路线图
请参阅 ROADMAP.md 获取完整路线图。请参阅 CONTRIBUTING.md 了解如何为该项目做出贡献。
Star 历史
停止手动编写 MCP 服务器吧。
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Type-MCP/mcp-anything'
If you have feedback or need assistance with the MCP directory API, please join our Discord server