使用说明
多存储库MCP服务器
一种模型上下文协议(MCP)服务器,允许您在不更改当前工作目录的情况下访问多个存储库中的文件。
使用Go构建,简单高效。
特性
- 访问多个存储库 从一个位置
- 四个强大的工具:
list_repos:列出所有已配置的存储库及其路径list_files:列出任何已配置存储库中的文件read_file:从任何存储库读取文件search_files:使用通配符(*和?)搜索文件
- 资源协议:通过访问文件
repo://repo-name/path/to/fileURI - 载入:配置在以下情况下自动重新加载
config.json更改-无需重新启动! - 内置安全功能:
- 路径遍历保护
- 自动跳过隐藏文件(以.开头)
- 自动跳过node_modules目录
安装
-
安装二进制文件:
go install github.com/vimalk78/fs-mcp@latest或者在本地构建:
go build -o fs-mcp sudo mv fs-mcp /usr/local/bin/ # Optional: install to system path -
创建配置目录和文件:
# Create config directory mkdir -p ~/.config/fs-mcp # Copy the example config cp config.example.json ~/.config/fs-mcp/config.json # Edit with your actual repository paths vim ~/.config/fs-mcp/config.json示例
~/.config/fs-mcp/config.json:{ "repositories": { "frontend": "/home/yourusername/projects/frontend", "backend": "/home/yourusername/projects/backend", "infrastructure": "/home/yourusername/projects/infrastructure" } }重要:
- 为您的存储库使用绝对路径
- 默认配置位置为
~/.config/fs-mcp/config.json(自动检测) - 您可以随时更改存储库路径,而无需重新构建-更改会自动重新加载!
就是这样!现在,您有一个具有可配置存储库的可执行文件。
配置
适用于克劳德桌面
将此添加到您的Claude Desktop配置文件中:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
视窗: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"multi-repo": {
"command": "fs-mcp"
}
}
}
或者,如果您需要指定自定义配置位置:
{
"mcpServers": {
"multi-repo": {
"command": "fs-mcp",
"args": ["-config", "/path/to/your/config.json"]
}
}
}
备注:
- 如果使用
go install,确保$GOPATH/bin或$GOBIN在你的路径中 - 在以下位置自动检测到配置
~/.config/fs-mcp/config.json如果-config未指定
克劳德代码
将此添加到MCP设置文件中:
macOS/Linux: ~/.config/claude-code/mcp_settings.json
视窗: %APPDATA%\claude-code\mcp_settings.json
{
"mcpServers": {
"multi-repo": {
"command": "fs-mcp"
}
}
}
或者,如果您需要指定自定义配置位置:
{
"mcpServers": {
"multi-repo": {
"command": "fs-mcp",
"args": ["-config", "/path/to/your/config.json"]
}
}
}
备注:
- 如果使用
go install,确保$GOPATH/bin或$GOBIN在你的路径中 - 在以下位置自动检测到配置
~/.config/fs-mcp/config.json如果-config未指定 - 适用于Claude CLI:使用
claude --mcp-config ~/.config/claude-code/mcp_settings.json加载MCP服务器
重要:
- 配置文件默认位置:
~/.config/fs-mcp/config.json(自动检测) - 在配置文件中为存储库位置使用绝对路径
- 如果
fs-mcp找不到命令,请确保Go的bin目录在PATH中
用法
配置后,您可以通过Claude使用MCP服务器:
列出存储库
What repositories do you have access to?
克劳德将致电:
list_repos()
列出文件
Show me the files in the backend repository
克劳德将致电:
list_files(repo="backend", path=".", recursive=False)
读取文件
Show me the file backend/src/api.py
克劳德将致电:
read_file(repo="backend", file="src/api.py")
搜索文件
List all TypeScript files in the frontend repository
克劳德将致电:
search_files(repo="frontend", pattern="*.ts")
使用资源
您还可以使用资源URI格式访问文件:
Read the file at repo://backend/src/api.py
工具参考
list_repos
列出所有已配置的存储库及其路径。
参数:无
退货:带有存储库列表和计数的JSON对象
示例:
{
"repositories": [
{
"name": "frontend",
"path": "/home/user/projects/frontend"
},
{
"name": "backend",
"path": "/home/user/projects/backend"
}
],
"count": 2
}
列表文件
列出存储库目录中的文件。
参数:
repo(必填):REPOS配置中的存储库名称path(可选):存储库中的路径(默认值:“.”)recursive(可选):是否递归列出文件(默认值:false)
退货:带有存储库、路径和文件列表的JSON对象
示例:
{
"repository": "frontend",
"path": "src",
"files": [
"App.tsx",
"index.ts",
"components/"
]
}
read_file
从存储库读取文件。
参数:
repo(必填):存储库名称file(必需):存储库中文件的路径
退货:带标题的纯文本,显示文件位置和内容
示例:
File: backend/src/api.py
from flask import Flask
app = Flask(__name__)
...
搜索文件
搜索与模式匹配的文件。
参数:
repo(必填):存储库名称pattern(必填):带通配符(*和?)的文件名模式
退货:带有存储库、模式和匹配文件的JSON对象
示例:
{
"repository": "frontend",
"pattern": "*.ts",
"matches": [
"src/index.ts",
"src/types/user.ts",
"src/utils/helper.ts"
]
}
安全
服务器实施了多种安全措施:
- 路径横向保护:所有路径都经过验证,以确保它们保持在配置的存储库边界内
- 隐藏文件筛选:以开头的文件和目录
.自动跳过 - node_modules筛选:The
node_modules目录会自动跳过 - 只读访问:服务器仅提供对文件的读取权限
故障排除
服务器未出现在Claude中
- 检查配置文件是否在正确的位置
- 验证
fs-mcp二进制文件是可访问的(检查PATH或使用绝对路径) - 对于Claude CLI:确保您正在使用
--mcp-config旗帜 - 配置更改后重新启动克劳德桌面/代码
- 检查日志中的错误消息
未找到存储库路径
- 确保配置文件中的路径是绝对路径
- 验证目录是否存在并且可以访问
- 检查文件权限
- 确保
-config标志指向正确的配置文件路径(如果指定)
文件不可读
- 确保文件是文本文件(不支持二进制文件)
- 检查文件是否不在隐藏目录或node_modules中
- 验证文件路径相对于存储库根是否正确
发展
要修改或扩展服务器,请执行以下操作:
- 编辑
multi_repo_server.py - 在中添加或修改工具
@app.call_tool()处理器 - 更新中的工具架构
@app.list_tools() - 通过重新启动Claude来测试您的更改
许可证
此项目按原样提供,供Claude使用。
