mcpField
S
Sample MCP Server in Go.

Sample MCP Server in Go.

本地服务
github.com/giannisalinetti开发工具078 周前更新

关于 Sample MCP Server in Go.

这是一个 Go 编写的 MCP 服务,在工具调用时运行 Python 环境,以执行大模型生成的代码,包括网页抓取代码。它面向使用 MCP 主机测试工具调用的开发者,并使用 Podman 作为容器引擎。

主要功能

  1. 01在工具调用时运行 Python 环境
  2. 02执行大模型生成的代码
  3. 03支持网页抓取任务
  4. 04使用 Podman 作为容器引擎
  5. 05使用 Go 1.23+ 构建

适用场景

  1. 01通过 MCP 主机运行生成的 Python 代码
  2. 02使用大模型生成的脚本抓取网页内容

MCP 相关

该服务向 MCP 客户端提供 Python 代码执行工具。README 展示了在 `mcphost` 中将其配置为 `python-repl`。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

暂未收录安装方式

我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。

代码仓库

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

Go 语言版示例 MCP 服务。

此 MCP 服务在被调用时会运行 Python 环境,可用于执行大模型生成的代码。它可用于抓取网页内容。

本项目基于 YouTube 上的这个演示,并进行了一些小幅修改。

此演示使用 Podman 作为容器引擎,而不是 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 作为默认大模型,无需本地 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

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。