
30秒内将任何OpenAPI规范或Postman集合变成可拥有的Python MCP服务器
概览
指向 OpenAPI 规范或 Postman 集合。获取一个——没有对 mcpgen 的运行时依赖,没有代理,没有锁定。阅读它。修改它。发布它。 就这些。mcpgen读取你的规格,然后写入一个Python MCP服务器到磁盘。 一个包含你拥有源代码的自包含目录: 没有黑箱。运行时没有依赖。只有 Python。 mcpgen会打印出完全相同的配置片段,粘贴到你的 claude_desktop_config.json: - macOS:~/Library/Application Support/Claude/claude_desktop_config.json- Windows:%APPDATA%\Claude\claude_desktop_config.json 大多数API到MCP的工具都是——它们永远存在于Claude和你的API之间,你依赖它们来保持运行。 mcpgen 生成 。输出是一个普通的 Python 文件。你可以:
概述(AI 翻译)
将任何API在30秒内转化为MCP服务器。
指向 mcpgen 的 OpenAPI 规范或 Postman 集合。拿回一个你拥有的完整 Python MCP 服务器 — 不依赖 mcpgen,不依赖代理,不锁死。阅读它。修改它。发货。
安装
快速开始
就这样。mcpgen 读取你的规格,然后写入一个 Python MCP 服务器到磁盘。
你得到了什么
一个包含你拥有源代码的自包含目录:
立即运行:
生成的server.py长这样:
没有黑箱。运行时没有依赖。只有 Python。
添加到Claude桌面
mcpgen 打印出完全相同的配置片段,粘贴到你的 claude_desktop_config.json:
配置文件位置:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - 窗口:
%APPDATA%\Claude\claude_desktop_config.json
为什么要用源代码而不是代理?
大多数API到MCP的工具都是运行时代理——它们永远存在于Claude和你的API之间,你依赖它们来保持运行。
mcpgen 生成你拥有的源代码。输出是一个普通的Python文件。你可以:
- 仔细阅读发生的每一行
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
Point mcpgen at an OpenAPI spec or Postman collection. Get back a complete Python MCP server you own — no runtime dependency on mcpgen, no proxy, no lock-in. Read it. Modify it. Ship it.
Install
pip install mcpgen-cli
Quickstart
# From a URL
mcpgen https://petstore3.swagger.io/api/v3/openapi.json
# From a local OpenAPI file (JSON or YAML)
mcpgen stripe.yaml
# From a Postman collection
mcpgen postman_collection.json
# Preview without writing anything
mcpgen openapi.json --dry-run
# Custom output directory and server name
mcpgen openapi.json --output ~/my-mcp-servers --name "My API"
That’s it. mcpgen reads your spec and writes a Python MCP server to disk.
What you get
A self-contained directory with source code you own:
stripe_api_mcp/
├── server.py ← the MCP server (read it, edit it, it's yours)
└── requirements.txt ← httpx, mcp
Run it immediately:
cd stripe_api_mcp
pip install -r requirements.txt
export STRIPE_API_TOKEN="sk_live_..."
python server.py
The generated server.py looks like this:
#!/usr/bin/env python3
"""
Stripe API MCP Server
Generated by mcpgen — https://github.com/JnanaSrota/mcpgen
This file is yours. Modify it freely.
"""
import os, asyncio, httpx
from mcp.server import Server
from mcp.server.stdio import stdio_server
from mcp import types
BASE_URL = "https://api.stripe.com"
AUTH_TOKEN = os.environ.get("STRIPE_API_TOKEN", "")
app = Server("stripe-api")
@app.call_tool()
async def _handle_get_customers(name: str, arguments: dict):
if name != "get_customers":
raise ValueError(f"Unknown tool: {name}")
url = BASE_URL + "/v1/customers"
query_params = {}
if "limit" in arguments:
query_params["limit"] = arguments["limit"]
async with httpx.AsyncClient(timeout=30.0) as client:
response = await client.get(url, params=query_params,
headers={"Authorization": f"Bearer {AUTH_TOKEN}"})
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →配置
{
"mcpServers": {
"stripe-api-mcp": {
"command": "python",
"args": ["/path/to/stripe_api_mcp/server.py"],
"env": { "STRIPE_API_TOKEN": "your-key-here" }
}
}
}