Cookiecutter MCP服务器
一个模型上下文协议(MCP)服务器,提供与Cookiecutter模板的无缝集成,用于快速构建项目框架。此服务器使您能够通过标准化的JSON-RPC 2.0接口从本地和远程Cookiecutter模板管理、测试和生成项目。
灵感与归因
特性
- 🚀 模板管理 -列出、发现和管理Cookiecutter模板
- 🌐 远程和本地支持 -使用GitHub存储库和本地模板目录
- 📋 模板验证 -项目生成前测试模板可访问性
- 🛠️ 灵活的配置 -通过JSON文件轻松配置模板
- 📊 综合录井 -详细的日志记录和调试功能
- ⚡ MCP协议 -完全符合JSON-RPC 2.0和MCP协议
- 🎯 模板值 -支持自定义模板参数值
Claude desktop using cookiecutter mcp server
先决条件
- 猛击 4.0+(macOS/Linux)
- jq公司 -JSON处理器(
brew install jq或apt-get install jq) - 炊具切割器 -模板引擎(
pip install cookiecutter) - Git -用于远程模板访问
安装
- 克隆存储库:
git clone
cd cookiecutter-mcp-server- 安装依赖项:
# Install jq (if not already installed)
brew install jq # macOS
# or
sudo apt-get install jq # Ubuntu/Debian
# Install cookiecutter
pip install cookiecutter注: 此项目包括来自 MCP服务器Bash SDK。由于必要的文件已与此存储库捆绑在一起,因此不需要安装额外的SDK。
建筑
该项目建立在 MCP服务器Bash SDK 架构:
┌─────────────────────┐
│ MCP Client │
└─────────┬───────────┘
│ JSON-RPC 2.0
┌─────────▼──────────────────┐
│ cookiecutter_mcp_server.sh │ ← Custom Cookiecutter Implementation
│ ┌─────────────────┐ │
│ │ Tool Functions | │
│ │ - list_templates│ │
│ │ - generate_proj │ │
│ │ - test_access │ │
│ └─────────────────┘ │
└────────────┬───────────────┘
│
┌────────────▼──────────┐
│ mcpserver_core.sh │ ← From MCP Server Bash SDK
│ ┌─────────────────┐ │
│ │ JSON-RPC Handler│ │
│ │ Protocol Logic │ │
│ │ Error Handling │ │
│ └─────────────────┘ │
└───────────────────────┘配置
模板配置
编辑 assets/cookiecutter_mcp_config.json 要添加模板,请执行以下操作:
{
"protocolVersion": "2024-11-05",
"serverInfo": {
"name": "CookieCutterPythonServer",
"version": "0.1.0"
},
"templates": {
"pypackage": {
"name": "pypackage",
"url": "https://github.com/audreyfeldroy/cookiecutter-pypackage",
"description": "Cookiecutter template for a Python package with best practices",
"category": "library",
"language": "python"
},
"simple-test": {
"name": "simple-test",
"url": "./simple-test",
"description": "Local test cookiecutter template",
"category": "custom",
"language": "python"
}
}
}Git配置(可选)
如果您遇到公共存储库的Git身份验证提示:
# Disable credential helper for public repos
git config --global credential.helper ""用法
启动服务器
# Run the MCP server
./cookiecutter_mcp_server.sh服务器将在stdin上监听JSON-RPC 2.0消息,并在stdout上做出响应。
可用工具
1.列出模板
echo '{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "list_templates"}, "id": 1}' | ./cookiecutter_mcp_server.sh2.获取模板信息
echo '{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "get_template_info", "arguments": {"templateName": "pypackage"}}, "id": 2}' | ./cookiecutter_mcp_server.sh3.测试模板访问
echo '{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "test_template_access", "arguments": {"templateName": "pypackage"}}, "id": 3}' | ./cookiecutter_mcp_server.sh4.生成项目(基础)
echo '{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "generate_project", "arguments": {"templateName": "simple-test", "outputDir": "./my-new-project"}}, "id": 4}' | ./cookiecutter_mcp_server.sh5.使用模板值生成项目
echo '{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "generate_project", "arguments": {"templateName": "simple-test", "outputDir": "./my-custom-project", "templateValues": {"project_name": "awesome-project", "author_name": "Your Name", "author_email": "you@example.com"}}}, "id": 5}' | ./cookiecutter_mcp_server.sh6.使用ZIP下载生成项目(仅限GitHub)
echo '{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "generate_project_zip", "arguments": {"templateName": "pypackage", "outputDir": "./zip-project"}}, "id": 6}' | ./cookiecutter_mcp_server.sh模板类型
远程模板(GitHub)
{
"template-name": {
"name": "template-name",
"url": "https://github.com/user/cookiecutter-template",
"description": "Description of the template",
"category": "web-framework",
"language": "python"
}
}本地模板
{
"local-template": {
"name": "local-template",
"url": "./path/to/template/directory",
"description": "Local cookiecutter template",
"category": "custom",
"language": "python"
}
}本地模板要求:
- 必须包含
cookiecutter.json根目录下的文件 - 遵循标准Cookiecutter目录结构
- 使用MCP服务器目录中的相对路径或绝对路径
模板值
您可以使用以下命令为模板变量提供自定义值 templateValues 参数:
{
"templateValues": {
"project_name": "my-awesome-project",
"author_name": "John Doe",
"author_email": "john@example.com",
"python_version": "3.11",
"additional_tools": "requests,pandas"
}
}密钥必须与模板中定义的完全匹配 cookiecutter.json 文件。
高级用法
调试模式
通过设置启用调试日志记录 DEBUG_MODE=1 在……里面 cookiecutter_mcp_server.sh:
# Edit cookiecutter_mcp_server.sh
DEBUG_MODE=1测试
运行测试套件以验证核心MCP服务器功能:
./test_mcpserver_core.sh这将测试:
- MCP协议合规性
- 工具功能执行
- 错误处理
- JSON-RPC 2.0消息传递
许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
