MCP协议主机

一个基于Go的MCP协议主机,连接Ollama LLMs和MCP服务器工具,提供ChatGPT风格的Web界面。

  • by aravindanugonda
  • Go
  • 本地部署
  • 更新于
在 GitHub 查看 aravindanugonda/mcp-go

使用说明

mcp走

基于Go的 MCP主机 --连接的聊天机器人应用程序 奥拉玛 LLM暴露于以下工具 模型上下文协议(MCP) 服务器,具有ChatGPT风格的web界面。


特性

  • Ollama集成 --适用于Ollama提供的任何支持工具调用的模型
  • MCP服务器支持 --通过以下方式连接到任何MCP服务器 stdio (子流程)或 http 运输
  • 工具调用循环 --自动调用工具并将结果反馈给模型,最多5次迭代
  • ChatGPT风格的用户界面 --深色主题,带有markdown渲染和语法高亮显示,可复制代码块
  • 实时聊天 --具有自动REST回退功能的WebSocket
  • 外壳脚本 --主机的启动、停止、重启、状态和日志跟踪命令 和 当地的重新登录者

先决条件

要求 注意事项
转到1.21+ 构建服务器
奥拉玛 在端口上本地运行 11434
Node.js/npx stdio MCP服务器需要(例如。 @modelcontextprotocol/server-filesystem)
Python 3+ python3-venv 可选--仅在使用本地重新登录时需要

快速开始

1.克隆

git clone https://github.com/aravindanugonda/mcp-go.git
cd mcp-go

2.配置

编辑 config.yaml 指向Ollama模型并设置文件系统MCP服务器可以访问的目录:

host: "0.0.0.0"
port: 8080

ollama:
  base_url: "http://localhost:11434"
  model: "minimax-m2.5:cloud"   # any tool-capable Ollama model

mcp_servers:
  - name: "filesystem"
    type: "stdio"
    command: "npx"
    args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp", "/home/user/projects"]
    env: {}

3.开始

chmod +x mcp-host.sh
./mcp-host.sh start

打开 http://localhost:8080 在您的浏览器中。


外壳脚本

./mcp-host.sh start              # Build and start host + reranker (if configured)
./mcp-host.sh stop               # Stop host + reranker
./mcp-host.sh restart            # Stop then start
./mcp-host.sh status             # Show host, MCP connection state, and reranker health
./mcp-host.sh logs               # Tail host log (last 50 lines, follow mode)
./mcp-host.sh logs 100           # Tail last 100 lines of host log
./mcp-host.sh logs reranker      # Tail reranker log
./mcp-host.sh logs reranker 100  # Tail last 100 lines of reranker log

环境覆盖:

GO_BIN=/usr/local/go/bin/go CONFIG=/path/to/config.yaml ./mcp-host.sh start
RERANKER_SCRIPT=/path/to/reranker.py RERANKER_PORT=8090 ./mcp-host.sh start

项目结构

.
├── cmd/
│   └── main.go                  # Entry point
├── internal/
│   ├── chat/
│   │   └── handler.go           # Tool-calling loop, Ollama orchestration, system prompt
│   ├── config/
│   │   └── config.go            # YAML config loader
│   ├── mcp/
│   │   ├── client.go            # MCP client (tool discovery + invocation)
│   │   ├── protocol.go          # MCP JSON-RPC types
│   │   ├── stdio.go             # Stdio transport (subprocess)
│   │   ├── http.go              # HTTP transport
│   │   └── transport.go         # Transport interface
│   ├── ollama/
│   │   └── client.go            # Ollama REST client + tool conversion
│   └── server/
│       └── http.go              # HTTP + WebSocket server
├── web/
│   └── index.html               # Single-page chat UI
├── config.yaml.example          # Configuration template (copy to config.yaml)
├── mcp-host.sh                  # Start/stop/status script (manages host + reranker)
├── go.mod
└── go.sum

运作原理

  1. 启动时,主机连接到每个配置的MCP服务器并发现其工具。
  2. 当用户发送消息时,主机会将其与工具定义一起转发给Ollama。
  3. 如果Ollama请求工具调用,主机将在相应的MCP服务器上执行该调用并反馈结果。
  4. 重复步骤2-3(最多5次),直到Ollama返回纯文本响应。
  5. 如果模型返回空内容(常见于大型工具结果上的小型模型),则直接格式化并显示原始工具输出。

系统提示

系统提示(in internal/chat/handler.go)指示模型:

  • 呼叫 rag_query 最多一两次,然后综合一个完整的答案——不要重复查询同一主题
  • 始终从检索到的上下文中生成格式化的markdown答案,从不输出原始工具结果
  • 使用带有正确语言标签的围栏代码块(```jcl, ```cobol等等)

这可以防止常见的故障模式,在这种模式下,模型会循环执行多个工具调用,并积累足够的上下文以溢出其响应窗口。


推荐型号

工具调用在更大、指令调优的模型中效果最佳。测试方法:

型号 备注
minimax-m2.5:cloud 推荐使用强大的工具,通过Ollama托管云

小型模型(< 1B params)在收到大型工具结果后,通常会返回空响应。


MCP服务器:松果RAG

对于基于文档的问答,请将此主持人与同伴配对 mcp松果抹布 服务器。它暴露了一个 rag_query 由a支持的工具 三层检索管道:

  1. 语义搜索 --通过Google Vertex AI嵌入查询 text-embedding-005,从Pinecone检索到的前20名候选人
  2. 关键字提升 --排名中提升的域标记(模块名称、错误代码、ALL-CAPS缩写)的精确匹配
  3. 交叉编码器重定器 --可选的本地Python服务(reranker.py)使用完全上下文相关性对候选人进行重新排序 BAAI/bge-reranker-base 通过 快速嵌入 (不需要PyTorch)

重新分级设置

此脚本会自动启动和停止重新登录程序。它在端口上作为本地Flask服务器运行 8090.

首次设置 --该脚本创建一个Python venv并安装 fastembed + flask 自动:

# Debian/Ubuntu: ensure venv support is available
apt install python3-venv

./mcp-host.sh start   # venv + deps installed on first run, ~150 MB

注: 第一次运行时,fastembed会下载重新登录的模型权重(约280 MB)。这需要30-60秒。主机会立即启动,但在下载完成之前,重新登录程序不会准备就绪——检查 ./mcp-host.sh logs reranker 等待 [reranker] Ready on port 8090 在发送依赖于重新排名的查询之前。在后续启动时,模型将在几秒钟内从缓存加载。

在 config.yaml,添加 RERANKER_URL 并且可选 TRAJECTORY_LOG_FILE 到 pinecone-rag 服务器环境:

  - name: "pinecone-rag"
    type: "stdio"
    command: "/path/to/mcp-pinecone-rag/mcp-pinecone-rag"
    args: []
    env:
      PINECONE_API_KEY: "..."
      GOOGLE_CLOUD_PROJECT: "..."
      GOOGLE_APPLICATION_CREDENTIALS: "/path/to/service-account.json"
      VERTEX_AI_LOCATION: "us-central1"
      PINECONE_INDEX_HOST: "..."
      RAG_TOP_K: "5"
      RERANKER_URL: "http://localhost:8090"
      TRAJECTORY_LOG_FILE: "/tmp/trajectory.jsonl"

如果 RERANKER_URL 如果未设置或重新登录服务不可用,RAG服务器将优雅地回退到混合关键字增强的结果。

看 mcp松果抹布 有关完整的设置说明、轨迹日志格式和重新登录延迟说明。


许可证

麻省理工学院