文本文件协议服务器

一个基于Go语言开发的MCP服务器,将文本文件目录作为工具和资源提供,支持HTTP/SSE和stdio两种传输方式。

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

使用说明

go mcp文本

用Go编写的MCP(模型上下文协议)服务器,它公开了一个文本文件目录作为工具和资源。支持HTTP/SSE和stdio传输。

工具

工具 说明
list_files 列出源目录中的所有文本文件
read_file 读取特定文件的内容
search_files 在所有文本文件中进行不区分大小写的关键字搜索

文件也可以作为MCP资源通过以下方式访问 file://{filename} URI模板。


运行服务器

先决条件

  • 转到1.25+

构建

make build

这产生了一个 go-mcp-text 项目根目录中的二进制文件。

HTTP/SSE模式(默认)

./go-mcp-text -source /path/to/your/docs

默认情况下,服务器在端口8080上启动。将您的MCP客户端连接到:

http://localhost:8080/mcp

使用 -port 要更改端口,请执行以下操作:

./go-mcp-text -source /path/to/your/docs -port 9090

stdio模式(克劳德桌面/CLI客户端)

./go-mcp-text -source /path/to/your/docs -stdio

选项

-source <dir>   Directory to serve text files from (default: ".")
-port <port>    Port to listen on in HTTP/SSE mode (default: "8080")
-stdio          Run as a stdio MCP server instead of HTTP/SSE
-help           Show help

Claude桌面集成

将以下内容添加到您的 claude_desktop_config.json:

{
  "mcpServers": {
    "go-mcp-text": {
      "command": "/path/to/go-mcp-text",
      "args": ["-source", "/path/to/your/docs", "-stdio"]
    }
  }
}

Claude代码集成

使用 claude mcp add 注册服务器的命令。更改已保存到 .mcp.json 使用时,在项目根目录中(与您的团队共享) --scope project,或 ~/.claude.json 供个人/本地使用(默认)。

stdio传输

claude mcp add --transport stdio go-mcp-text -- /path/to/go-mcp-text -source /path/to/your/docs -stdio

HTTP传输

首先以HTTP模式启动服务器:

./go-mcp-text -source /path/to/your/docs -port 8080

然后注册它:

claude mcp add --transport http go-mcp-text http://localhost:8080/mcp

结果 .mcp.json / .claude.json

标准 :

{
  "mcpServers": {
    "go-mcp-text": {
      "type": "stdio",
      "command": "/path/to/go-mcp-text",
      "args": ["-source", "/path/to/your/docs", "-stdio"]
    }
  }
}

HTTP:

{
  "mcpServers": {
    "go-mcp-text": {
      "type": "http",
      "url": "http://localhost:8080/mcp"
    }
  }
}

发展

先决条件

  • 转到1.25+

克隆并安装依赖项

git clone https://github.com/your-org/go-mcp-text.git
cd go-mcp-text
go mod download

构建

make build

兽医

make vet

清洁

make clean

快速测试

此命令发送MCP握手(initialize 和 initialized)然后列出MCP服务器提供的工具。需要 jq 为了更好地打印结果:

{ echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"0"}}}'; \
echo '{"jsonrpc":"2.0","method":"notifications/initialized","params":{}}'; \
echo '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}'; } \
| ./go-mcp-text --stdio | jq .

依赖项