一个强大的命令行工具和cookiecutter模板,用于创建模型上下文协议(MCP)服务器。只需一条命令即可在几秒钟内生成一个完全配置好的MCP服务器,然后根据您的API进行自定义。
pip install mcp-cookie-cutter && mcp-cookie-cutter最快的方式开始:
# 安装命令行工具
pip install mcp-cookie-cutter
# 生成您的MCP服务器
mcp-cookie-cutter
# 或者使用特定选项
mcp-cookie-cutter --no-input project_name="我的API服务器"
就这样! 命令行工具捆绑了您所需的一切。
如果您更喜欢直接使用cookiecutter:
# 首先安装cookiecutter
pip install cookiecutter
# 使用GitHub上的模板
cookiecutter gh:maheshmahadevan/mcp-cookie-cutter
所有依赖项都会通过命令行工具自动安装。如果直接使用cookiecutter:
没有这些可选依赖项,您仍然可以生成MCP服务器,但OpenAPI规范解析和工具建议将不可用。
使用命令行(推荐):
pip install mcp-cookie-cutter
mcp-cookie-cutter
或者使用cookiecutter:
cookiecutter gh:maheshmahadevan/mcp-cookie-cutter
您将被要求配置:
生成的服务器包括示例工具。请参阅CUSTOMIZATION.md指南以添加您的API端点。
按照生成后显示的设置说明操作,或查看生成的README.md。
my-mcp-server/
├── src/
│ └── my_mcp_server/
│ ├── server.py # 自动发现的FastMCP服务器
│ ├── tools/ # 单个工具文件(自动生成)
│ │ ├── __init__.py
│ │ ├── addPet.py # 示例:POST /pet
│ │ ├── getPetById.py # 示例:GET /pet/{petId}
│ │ └── ...
│ ├── prompts/ # 从OpenAPI自动生成的提示
│ │ ├── __init__.py
│ │ └── pet_operations.py
│ └── models/ # 从OpenAPI生成的Pydantic模型
│ ├── __init__.py
│ └── schemas.py
├── test_server.py # 开发测试,带自动重载
├── pyproject.toml # Python项目配置
├── .env.example # 环境变量模板
├── Dockerfile # Docker容器配置
├── docker-compose.yml # Docker Compose,便于部署
├── README.md # 生成的文档
├── CUSTOMIZATION.md # 添加自定义工具的指南
└── .gitignore
模板包括智能OpenAPI解析,它:
# 提供您的OpenAPI规范路径
openapi_spec_path: https://petstore.swagger.io/v2/swagger.json
# 钩子将扫描并显示:
✨ 找到20个可用的API操作:
----------------------------------------------------------------------
1. POST /pet - addPet
添加一个新的宠物到商店
2. GET /pet/{petId} - getPetById
根据ID查找宠物
...
----------------------------------------------------------------------
💡 您可以在生成的服务器中实现这些作为MCP工具。
deployment_type: local
auth_mechanism: none
openapi_spec_path: https://petstore3.swagger.io/api/v3/openapi.json
结果:基于STDIO的服务器,适用于Claude Desktop,并自动生成工具
deployment_type: remote
server_port: 9090
auth_mechanism: api_key
openapi_spec_path: https://petstore3.swagger.io/api/v3/openapi.json
结果:带API密钥认证的流式HTTP服务器,并自动生成工具
deployment_type: remote
server_port: 8000
auth_mechanism: oauth2
openapi_spec_path: https://api.github.com/openapi.json
结果:带OAuth 2.1认证的流式HTTP服务器
生成的服务器遵循MCP最佳实践:
安全性:
传输:
错误处理:
代码质量:
模板使用Jinja2模板。关键文件:
cookiecutter.json:配置选项hooks/pre_gen_project.py:预生成验证和OpenAPI扫描hooks/post_gen_project.py:生成后的设置和清理{{cookiecutter.project_slug}}/:带有Jinja2语法的模板文件# 生成一个测试项目
cookiecutter . --no-input
# 或者使用特定值
cookiecutter . --no-input deployment_type=local auth_mechanism=none
# 使用OpenAPI规范测试
cookiecutter . --no-input \
openapi_spec_path="https://petstore3.swagger.io/api/v3/openapi.json" \
deployment_type="remote" \
server_port="9090"
使用这些经过验证的API测试您的MCP Cookie Cutter模板,它们具有OpenAPI 3.0规范:
使用命令行工具(推荐):
# 如果尚未安装,请安装
pip install mcp-cookie-cutter
# 使用Petstore测试(只需运行并输入OpenAPI URL)
mcp-cookie-cutter
# 或使用--no-input进行自动化测试
mcp-cookie-cutter --no-input \
project_name="petstore_server" \
openapi_spec_path="https://petstore3.swagger.io/api/v3/openapi.json" \
deployment_type="remote" \
server_port="9090" \
auth_mechanism="none"
或者直接使用cookiecutter:
# 使用Petstore测试
cookiecutter gh:maheshmahadevan/mcp-cookie-cutter \
project_name="petstore_server" \
openapi_spec_path="https://petstore3.swagger.io/api/v3/openapi.json" \
deployment_type="remote" \
server_port="9090" \
auth_mechanism="none"
# 使用JSONPlaceholder测试
cookiecutter gh:maheshmahadevan/mcp-cookie-cutter \
project_name="jsonplaceholder_server" \
openapi_spec_path="https://gist.githubusercontent.com/oshevtsov/7d17f88f74730ce9c95b6d7bb3e03c3d/raw/jsonplaceholder-openapi-3.0.yaml" \
deployment_type="remote" \
server_port="9090" \
auth_mechanism="none"
# 使用GitHub API测试(注意:非常大的规范,可能需要一分钟)
cookiecutter gh:maheshmahadevan/mcp-cookie-cutter \
project_name="github_server" \
openapi_spec_path="https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.json" \
deployment_type="remote" \
server_port="9090" \
auth_mechanism="api_key"
快速Docker部署 - Petstore:
docker run -d -p 8080:8080 swaggerapi/petstore3:unstable
# OpenAPI规范可在:http://localhost:8080/api/v3/openapi.json
Prism Mock Server(模拟任何OpenAPI规范):
npm install -g @stoplight/prism-cli
prism mock https://petstore3.swagger.io/api/v3/openapi.json
# 创建一个模拟API服务器在http://localhost:4010
最简单的使用方式是通过PyPI:
# 安装命令行工具
pip install mcp-cookie-cutter
# 在任何地方使用
mcp-cookie-cutter
通过PyPI分享(推荐):
# 团队成员只需安装并使用
pip install mcp-cookie-cutter
mcp-cookie-cutter
或者通过GitHub分享:
# 团队成员直接从GitHub使用
cookiecutter gh:maheshmahadevan/mcp-cookie-cutter
如果您想本地修改模板:
# 克隆仓库
git clone https://github.com/maheshmahadevan/mcp-cookie-cutter.git
cd mcp-cookie-cutter
# 以编辑模式安装
pip install -e .
# 现在命令行使用的是您的本地版本
mcp-cookie-cutter
欢迎贡献!请:
MIT许可 - 查看LICENSE文件了解详情
对于问题和疑问:
几秒钟内生成生产就绪的MCP服务器!