claude桌面配置
使用每台服务器的启用/禁用标志管理多个Claude Desktop MCP服务器配置。
克劳德桌面 claude_desktop_config.json 是纯JSON——你不能把东西注释掉。此工具可让您维护 源文件 您可以随意添加多个服务器条目,每个条目都有一个 "_enabled" 标志,并从中生成真正的配置。
安装
go install github.com/damianoneill/claude-desktop-config@latest或者从以下网址下载二进制文件 发布页面.
macOS注意事项: 从发布页面下载的二进制文件没有经过代码签名或公证。macOS Gatekeeper将在首次运行时阻止二进制文件。要删除隔离属性,请执行以下操作: ``bash xattr -d com.apple.quarantine ./claude-desktop-config ``快速开始
# 1. Create source file from the committed example
claude-desktop-config init
# 2. Edit it — add your real credentials and set _enabled flags as needed
$EDITOR claude_desktop_config.source.json
# 3. Launch the interactive TUI — toggle servers, then press 'a' to apply
claude-desktop-config
# Or skip the TUI and apply directly:
claude-desktop-config apply
# 4. Restart Claude Desktop用法
无参数运行以启动交互式TUI:
claude-desktop-config或者直接使用子命令:
claude-desktop-config [--source PATH] [--keep-backups N] | 命令 | 描述 |
|---|---|
tui | 启动交互式TUI(未给出命令时的默认设置) |
init | 从创建源文件 .example (如果已存在,则跳过) |
apply | 从源文件生成并写入Claude Desktop配置 |
dry-run | 预览生成的配置,无需写入磁盘 |
version | 打印版本 |
全球旗帜:
--source PATH Path to source JSON file (default: ./claude_desktop_config.source.json)
--keep-backups N Number of backup files to retain (default: 3)交互式TUI
跑步 claude-desktop-config (或 claude-desktop-config tui)打开全屏终端UI:
Claude Desktop MCP Servers 3 enabled / 15 total
────────────────────────────────────────────────────────────────────────
NAME URL
● local-server-a http://localhost:8080/mcp/server-a
○ local-server-b http://localhost:8080/mcp/server-b
○ prod-server-a https://api.example.com/mcp/server-a
●~ staging-server-a https://staging.example.com/mcp/server-a
────────────────────────────────────────────────────────────────────────
↑↓/jk navigate space toggle s save a apply d dry-run q quit| 符号 | 含义 |
|---|---|
● | 已启用 |
○ | 残疾人 |
●~ | 已分段启用(未保存) |
○~ | 已分段禁用(未保存) |
变化是 分阶段的 直到明确承诺:
space--切换所选服务器(已暂存,尚未写入)s--将阶段性更改保存到源文件a--保存阶段性更改并应用于Claude Desktop配置d--当前启用的服务器的模拟运行预览(显示在状态栏中)q--退出(丢弃任何未保存的阶段性更改)
源文件格式
claude_desktop_config.source.json 反映了真实的Claude Desktop配置结构, 每个服务器条目有两个额外字段:
"_enabled"—true包括,false从生成的配置中排除"_comment"--可选的自由形式描述,显示在TUI中并从输出中删除
前缀为的字段 _ 仅限于meta——它们仅存在于源文件中,并且是 从未复制到生成的Claude Desktop配置。
{
"mcpServers": {
"local-server-a": {
"_enabled": true,
"_comment": "Local dev instance — enabled for day-to-day testing",
"command": "npx",
"args": [
"mcp-remote",
"http://localhost:8080/mcp/server-a",
"--header",
"Authorization:Bearer YOUR_API_TOKEN"
],
"env": {
"NODE_OPTIONS": "--use-system-ca",
"NODE_TLS_REJECT_UNAUTHORIZED": "0"
}
},
"prod-server-a": {
"_enabled": false,
"_comment": "Production — keep disabled unless explicitly testing prod",
"command": "npx",
"args": [
"mcp-remote",
"https://api.example.com/mcp/server-a",
"--header",
"Authorization:Bearer YOUR_PROD_API_TOKEN"
],
"env": {
"NODE_OPTIONS": "--use-system-ca"
}
}
}
}claude_desktop_config.source.json 是 被忽视 --它永远不应该被承诺,因为它 包含真实的API令牌。承诺 .example 文件使用占位符值,可以安全共享。
配置文件位置
操作系统会自动检测正确的路径:
| 操作系统 | 路径 |
|---|---|
| macOS | ~/Library/Application Support/Claude/claude_desktop_config.json |
| Linux | ~/.config/Claude/claude_desktop_config.json |
| 窗户 | %APPDATA%/Claude/claude_desktop_config.json |
应用程序如何工作
- 读取源文件
- 仅筛选到
"_enabled": true服务器(不存在_enabled被视为已启用) - 全部脱衣
_前缀字段(_enabled,_comment)从输出 - 使用时间戳后缀备份现有的Claude Desktop配置(
.YYYYMMDD-HHMMSS.bak) - 修剪旧备份,保留最新的N(默认值3,可通过配置
--keep-backups) - 合并新
mcpServers将块插入到现有配置中,保留Claude Desktop可能编写的任何其他顶级密钥 - 写入结果
发展
make setup # install pre-commit hooks
make build # build ./claude-desktop-config binary
make test # run all tests
make lint # run golangci-lint
make fmt # format source code
make release-dry # local goreleaser snapshot