使用说明
代码执行器MCP
模型上下文协议(MCP)服务器,允许AI模型运行代码。用户用指定语言的代码提示模型,模型将执行它,显示stdout、stderr和退出代码。
实施
服务器使用 活塞 api在安全的远程环境中执行代码,然后将输出返回给AI模型。
可以找到有关MCP服务器以及如何实现它们的信息 这里.
安装
该MCP使用并测试了 Claude桌面版,但它应该适用于其他LLM和AI工具。本指南仅涵盖Claude Desktop。
-
克隆仓库
-
安装依赖项
npm i
- 跑
npm run build
-
安装Claude for Desktop后,打开文件
~/Library/Application Support/Claude/claude_desktop_config.json -
粘贴以下JSON
{
"mcpServers": {
"code_execution": {
"command": "node",
"args": ["/ABSOLUTE/PATH/TO/PARENT/FOLDER/code-execution-mcp/build/index.js"]
}
}
}
- 保存文件并启动Claude。
提示栏下应该有一个滑块图标。单击时,代码执行MCP应该是可切换的。
用法
尝试使用MCP,并给出以下提示
run this python code:
import random
print("Random Numbers:", [random.randint(1, 100) for _ in range(5)])
print("Random Choice:", random.choice(['apple', 'banana', 'cherry', 'date']))
print("Random Float:", round(random.random() * 100, 2))
for i in range(3):
print(f"Line {i+1}: {'*' * random.randint(3, 10)}")
print("Done!")
或
Generate random C code (that prints to the stdout) and run it