MCP服务器Python项目模板
A. 厨师切菜机 用于在Python中创建模型上下文协议(MCP)服务器的模板。
特性
- 🚀 快速设置:使用合理的默认值快速构建一个完整的Python MCP服务器。
- 📦 现代包装管理:用途 紫外线 用于快速依赖管理。
- 🏢 Nexus发布就绪:简化了对打包和发布到公司私有Nexus存储库的支持。
- 🐳 集装箱友好:包括a
Dockerfile易于构建和部署Docker镜像。
先决条件
快速启动
1.安装先决条件
厨师切菜机
# Using pipx (recommended)
pipx install cookiecutter
# Or using pip
pip install cookiecutter紫外线
# Using the installer script for macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | sh2.生成您的项目
您可以通过多种方式从该模板生成新的MCP服务器项目。
选项1:来自GitHub(推荐)
cookiecutter git@github.com:AfterShip/boilerplate-python-mcp-server \
project_name="Your project name" \
author_name="Your name" \
author_email="Your email" \
--no-input \
--output-dir "Your output directory"选项2:从本地克隆
# Clone this template repository
git clone git@github.com:AfterShip/boilerplate-python-mcp-server.git
cd boilerplate-python-mcp-server
cookiecutter . \
project_name="your_project_name" \
author_name="your_name" \
author_email="your_email" \
--no-input \
--output-dir "your_output_directory"就是这样!现在,您已经准备好开始开发自定义MCP服务器了。
配置选项
生成项目时,系统将提示您输入以下信息(除非您使用 --no-input):
| 参数 | 说明 | 默认值 |
|---|---|---|
project_name | 项目名称(例如,“跟踪MCP服务器”) | my-mcp-server |
project_slug | 项目标识符(自动生成) | my_mcp_server |
package_name | Python包名称(自动生成) | my_mcp_server |
project_description | 项目的简短描述。 | A modern Python MCP server. |
author_name | 你的名字。 | your name |
author_email | 你的电子邮件。 | you@example.com |
version | 初始版本号。 | 0.1.0 |
python_version | 要使用的Python版本。 | 3.11 |
license | 项目的许可证。 | MIT |
include_tests | 包括测试?(是/否) | y |
include_docker | 是否包含Docker配置?(是/否) | y |
接下来会发生什么?
跑步之后 cookiecutter一 post_gen_project.py hook脚本会在新创建的项目目录中自动为您执行以下步骤:
- 初始化Git存储库:
git init - 安装依赖项:
uv sync --dev - 创建初始提交:
git add . && git commit -m "Initial commit"
开发您的MCP服务器
您生成的项目包括它自己的 README.md 包含服务器开发、测试和运行的详细说明。
以下是一些快速命令(从新项目的目录运行):
# Run the server (defaults to stdio transport)
uv run your_package_name
# Run tests
uv run pytest请参阅 README.md 在你的新项目中了解更多细节。
自定义此模板
您可以分叉此存储库并根据需要进行自定义:
- 修改默认值:编辑
cookiecutter.json文件。 - 添加或删除文件:在中添加/删除文件
{{cookiecutter.project_slug}}/目录。 - 更改文件内容:编辑模板文件。他们使用 Jinja2 模板语法。
Jinja2语法示例:
{% if cookiecutter.include_docker == 'y' -%}
# This content will only be included if the user chooses to include Docker support.
{% endif -%}
Project Name: {{ cookiecutter.project_name }}贡献
欢迎为改进此模板做出贡献!请随时提交问题和拉取请求。
