内容
# Hello MCP Go 👋
欢迎来到 **Hello MCP Go** 仓库!🚀 这个项目展示了如何在 Go 中构建一个 MCP(模型上下文协议)服务器。无论你是 Go 爱好者还是对 MCP 感到好奇,你都来对地方了!🛠️
<div>
<img src="./gopher.jpeg" alt="背景中的 Gopher 在胡萝卜田里" width="600">
</div>
## 这是什么? 🤔
这个仓库展示了:
- 如何使用 Go 🐹 构建一个 MCP 服务器。
- 一种简单有趣的方式来探索 MCP 协议 🎮。
- 你自己定制的 MCP 服务器冒险的起点!🌟
## 工具 🌟
- hello,接受参数 Submitter 和 Content。
- calculate,接受参数 A 和 B。示例用法是 "calculate 2 and 4"。
## 快速开始 🚀
- 克隆
- 安装
- 构建
- 运行
1. 克隆仓库:
```bash
git clone https://github.com/your-username/hello-mcp-go.git
cd hello-mcp
```
2. 安装依赖:
```bash
go mod tidy
```
3. 构建项目:
```bash
go build -ldflags="-s -w" -o server.exe main.go
```
或者对于 Linux:
```bash
go build -ldflags="-s -w" -o server main.go
```
你稍后将在 Visual Studio Code 中使用这个。
1. 运行服务器:
```bash
./server
```
### 使用 GitHub Copilot Agent 模式消费服务器 🍴
1. 将自己放置在 *mcp.json* 中,确保服务器已经构建(现在已经调整好)。
1. 调整 "command" 指向你的可执行文件的绝对路径。
```json
{
"servers": {
"my-mcp-server-d73c20f3": {
"type": "stdio",
"command": "/path/to/your/executable"
}
}
}
```
1. 打开 Copilot 并在下拉菜单中选择 Agent。
1. 选择播放图标。
你应该看到工具图标显示两个工具。
1. 用短语测试,例如 "calculate 2 and 4"。这应该会显示一个按钮,调用服务器上的工具。

## 玩得开心! 🎉
这个项目的核心是学习和享受乐趣。随意实验、破坏东西,并创造一些惊人的东西!🌈
祝编码愉快! 💻