
mcp-go-starter

Overview
基本能力
产品定位
mcp-go-starter 是一个用于快速构建 Go 语言 MCP 服务器的启动模板,适用于开发需要 MCP 协议支持的工具和服务。
核心功能
- Hello World 工具:接收一个
name
参数并返回问候语。 - Markdown 资源服务:提供
pkg/example/resources/example.md
作为 MCP 资源。 - 提示功能:提供简单的提示功能,可以根据用户输入生成友好的问候。
适用场景
- 快速开发基于 MCP 协议的工具和服务。
- 集成到 VS Code 或其他支持 MCP 协议的开发环境中。
- 为 LLM 代理提供工具和资源调用能力。
工具列表
- hello_world:根据输入的
name
参数返回问候语。 - choose_color:允许用户从红色、绿色或蓝色中选择颜色。
- docs://example:提供 Markdown 资源内容。
常见问题解答
- 如何确保 VS Code 可以正确运行服务器?
确保在
.vscode/mcp.json
中设置了完整的脚本路径。 - 如何调用工具? 可以通过 JSON-RPC 请求调用工具,如示例所示。
使用教程
使用依赖
- 确保已安装 Go 环境。
- 克隆项目到本地。
安装教程
-
设置 VS Code 配置:
sh pwd
将输出路径更新到.vscode/mcp.json
的command
字段。 -
运行服务器(开发模式):
sh ./script/go-run
-
手动构建和运行服务器:
sh go build -o mcp-server ./cmd/mcp && ./mcp-server stdio
调试方式
-
调用 hello_world 工具:
json { "method": "call_tool", "params": { "tool": "hello_world", "arguments": { "name": "Sam" } }, "id": 1, "jsonrpc": "2.0" }
-
调用 choose_color 工具:
json { "method": "call_tool", "params": { "tool": "choose_color", "arguments": { "color": "green" } }, "id": 2, "jsonrpc": "2.0" }
-
获取提示:
json { "method": "get_prompt", "params": { "prompt": "hello_prompt", "arguments": { "name": "Sam" } }, "id": 3, "jsonrpc": "2.0" }
-
获取 Markdown 资源:
json { "method": "read_resource", "params": { "resource": "docs://example" }, "id": 4, "jsonrpc": "2.0" }