Python代码执行服务器

一个基于Go的MCP服务器,用于运行Python环境执行LLM生成的代码,适用于网页内容抓取等场景。

  • by giannisalinetti
  • Go
  • 本地部署
  • 更新于
在 GitHub 查看 giannisalinetti/python-mcp-server

使用说明

Go中的MCP服务器示例。

此MCP服务器在调用时运行Python环境,可用于执行代码 由LLM生成。它可用于抓取网络内容。

本项目基于以下内容 演示 在YouTube上有一些轻微的模组。

此演示使用 波德曼 作为容器引擎而不是Docker。

构建项目

这个项目需要Go 1.23+。要在本地构建:

$ go mod tidy && go install

使用实验室主机进行测试

用于测试 mcphost: https://github.com/mark3labs/mcphost

配置MCP服务器

编辑 ~/.mcp.json 添加以下内容的文件:

{
  "mcpServers": {
      "python-repl": {
          "command": "python-mcp-server"
      }
  }
}

此配置告诉mcphost运行 python-mcp-server 命令别名为 python-repl.

运行mcphost

此示例使用Claude-3.5 Sonnet作为默认LLM。这允许在没有本地GPU的情况下进行测试。

导出Anthropic密钥:

$ export ANTHROPIC_API_KEY='your-api-key'

执行主机

$ mcphost

它应该提示如下内容:

$ mcphost                                                                                                                                        
2025/04/28 21:44:32 INFO Model loaded provider=anthropic model=claude-3-5-sonnet-latest
2025/04/28 21:44:32 INFO Initializing server... name=python-repl
2025/04/28 21:44:32 INFO Server connected name=python-repl
2025/04/28 21:44:32 INFO Tools loaded server=python-repl count=1
  Enter your prompt (Type /help for commands, Ctrl+C to quit)

从现在开始,可以提示暗示网络抓取的请求,以查看MCP服务器的运行情况。

  Enter your prompt (Type /help for commands, Ctrl+C to quit)
  Show me the most starred repositories on github

  Assistant:                                                                                                                                    

  I'll create a script to fetch the most starred repositories from GitHub using their API:                                                                                  

2025/04/28 22:14:16 INFO 🔧 Using tool name=python-repl__execute-python
2025/04/28 22:14:16 INFO Usage statistics input_tokens=1665 output_tokens=309 total_tokens=1974