MCPMake
一个用于管理并运行带有LLM(大型语言模型)提取的模式的Python脚本的MCP(模型上下文协议)服务器——类似于 make,但更聪明。
特点/功能
- 自动模式提取使用大型语言模型(Claude Sonnet 4 或 GPT-4.1)来分析Python脚本并提取参数模式
- 脚本注册表存储和管理带有元数据的多个脚本
- 输入验证在执行前,根据JSON Schema验证参数
- 执行历史追踪所有脚本运行,并记录完整输出日志
- 环境变量每次执行时传递自定义环境变量
- 灵活执行自定义Python解释器、超时设置和输出截断
- 更新并重新分析当代码发生变化时,刷新脚本模式
安装
# Clone or navigate to the project directory
cd mcpmake
# Install in development mode
pip install -e .配置
设置API密钥
您需要一个Anthropic或OpenAI(或两者都)的API密钥:
export ANTHROPIC_API_KEY="your-key-here"
# or
export OPENAI_API_KEY="your-key-here"添加到MCP设置中
将服务器添加到您的MCP客户端配置中(例如,Claude Desktop):
{
"mcpServers": {
"mcpmake": {
"command": "python",
"args": ["-m", "mcpmake.server"],
"env": {
"ANTHROPIC_API_KEY": "your-key-here"
}
}
}
}使用方法
1. 注册脚本
# Register a Python script with automatic schema extraction
register_script(
name="data_processor",
path="/path/to/script.py",
description="Processes data files", # optional, auto-generated if omitted
python_path="/usr/bin/python3", # optional
timeout_seconds=240, # optional, default 240
min_lines=1, # optional, default 1
llm_provider="anthropic" # optional, "anthropic" or "openai"
)2. 列出脚本
list_scripts()
# Shows all registered scripts with descriptions3. 获取脚本信息
get_script_info(name="data_processor")
# Shows detailed schema, path, recent runs, etc.4. 运行脚本
run_script(
name="data_processor",
args={
"input_file": "data.csv",
"output_dir": "/tmp/output",
"verbose": true
},
env_vars={ # optional
"API_KEY": "secret123"
},
python_path="/usr/bin/python3", # optional, overrides default
timeout=300, # optional, overrides default
output_lines=100 # optional, default 100
)5. 查看运行历史
get_run_history(
name="data_processor", # optional, shows all scripts if omitted
limit=10 # optional, default 10
)6. 更新脚本模式
# Re-analyze script after code changes
update_script(
name="data_processor",
llm_provider="anthropic" # optional
)7. 删除脚本
delete_script(name="data_processor")数据存储
MCPMake 将数据存储在 ~/.mcpmake/:
~/.mcpmake/
├── scripts.json # Script registry and metadata
├── history.jsonl # Execution history log
└── outputs/ # Full script outputs
├── script1_timestamp.log
└── script2_timestamp.log它是如何工作的
- 注册当你注册一个脚本时,MCPMake:
- 读取脚本文件 - 将其发送给一个大型语言模型(如Claude Sonnet 4或GPT-4.1) - 提取描述脚本参数的JSON Schema - 从文档字符串/注释中提取描述 - 存储所有内容于 scripts.json
- 执行当你运行一个脚本时:
- 验证您的参数是否符合存储的JSON Schema - 检查脚本文件是否仍然存在 - 从您的输入中构建命令行参数 - 使用指定的Python解释器和环境变量运行脚本 - 捕获标准输出/标准错误,并带有超时保护 - 将完整输出保存到日志文件中 - 返回截断的输出(前N行) - 将执行详情记录到历史中
- 历史所有运行记录均使用:
- 时间戳、参数、退出代码 - 执行时间 - 完整的输出文件路径 - 使用的环境变量
示例Python脚本
MCPMake 与使用以下内容的脚本配合效果最佳:
argparse
import argparse
parser = argparse.ArgumentParser(description="Process data files")
parser.add_argument("--input-file", required=True, help="Input CSV file")
parser.add_argument("--output-dir", required=True, help="Output directory")
parser.add_argument("--verbose", action="store_true", help="Verbose output")
args = parser.parse_args()点击
import click
@click.command()
@click.option("--input-file", required=True, help="Input CSV file")
@click.option("--output-dir", required=True, help="Output directory")
@click.option("--verbose", is_flag=True, help="Verbose output")
def main(input_file, output_dir, verbose):
pass简单函数
def main(input_file: str, output_dir: str, verbose: bool = False):
"""
Process data files.
Args:
input_file: Path to input CSV file
output_dir: Output directory path
verbose: Enable verbose logging
"""
pass要求
- Python 3.10及以上版本
- MCP SDK(MCP软件开发工具包)
- Anthropic SDK(用于Claude)
- OpenAI SDK(用于GPT)
- jsonschema(JSON模式)
许可证
麻省理工学院(MIT)
