配置同步工具

sync-mcp 是一个基于 Node.js 的命令行工具,用于一键同步多个 IDE、代码编辑器和 CLI 工具的 MCP 配置文件,实现统一和自动化的配置管理。

  • by william-garden
  • JavaScript
  • 本地部署
  • 54 星标
  • 更新于
在 GitHub 查看 william-garden/sync-mcp

使用说明

# 同步mcp

一键式MCP配置同步工具。 中文

1.概述

sync-mcp是一个基于Node.js的命令行工具,旨在解决在多个IDE、代码编辑器和CLI工具之间手动同步通用mcp配置的痛点。用户可以使用简单的命令将一个工具(源)的配置文件安全地同步到另一个工具的配置文件(目标),从而实现统一和自动化的配置管理。

2.技术规格

  • 环境:Node.js 18+(需要ESM支持和现代API)。
  • 分发:通过npm分发,支持使用npx sync mcp直接执行或使用npm i-g sync mcp全局安装。
  • 运行时依赖性:仅依赖于跨平台文件系统和CLI交互库;不需要本机编译环境。
  • 支持的平台:在Linux、Windows和macOS上稳定运行。

3.使用方法

3.1.直接同步

通过为源和目标工具提供关键字直接执行同步。

npx -y sync-mcp <source_keyword> <target_keyword>

3.2.交互式同步

当命令在没有任何参数的情况下执行时,它将进入交互模式。

npx -y sync-mcp

操作流程:

  1. 选择来源:
    ? Select the configuration source file: (Use arrow keys)  
    > 1. VS Code (~/.vscode/mcp.json)  
        2. Cursor (~/.cursor/mcp.json)  
        3. GitHub Copilot CLI (~/.copilot/mcp-config.json)  
        4. Customize
    
  2. 选择目标:
    ? Select the configuration target file: (Use arrow keys)  
    > 1. VS Code (~/.vscode/mcp.json)  
        2. Cursor (~/.cursor/mcp.json)  
        3. GitHub Copilot CLI (~/.copilot/mcp-config.json)  
        4. Customize (Select a target tool or create a new configuration)
    

4.刀具匹配关键字

|工具名称|支持的关键字|
| :--- | :--- | |食品法典委员会| codex, openai, codex cli |
|克劳德代码| claude, claude-code, claude code, anthropic |
|光标| cursor, cursor ide |
|Gemini CLI| gemini, gemini cli, google, gcloud |
|GitHub Copilot命令行界面| copilot, copilot cli, github, gh |
|Visual Studio代码| vscode, vs code, vs-code, code | |OpenCode| opencode, open code, anomaly |

5.支持的工具和配置路径

|工具名称| Linux路径| macOS路径| Windows路径|文档URL|
| :--- | :--- | :--- | :--- | :--- | |食品法典委员会| ~/.codex/config.toml | ~/.codex/config.toml | %USERPROFILE%\.codex\config.toml | 食品法典委员会MCP指南 | |克劳德代码| ~/.claude.json | ~/.claude.json | %USERPROFILE%\.claude.json | 克劳德代码MCP指南 | |光标| ~/.cursor/mcp.json | ~/.cursor/mcp.json | %USERPROFILE%\.cursor\mcp.json | 光标MCP指南 | |Gemini CLI| ~/.gemini/settings.json | ~/.gemini/settings.json | %USERPROFILE%\.gemini\settings.json | Gemini CLI MCP服务器 | |GitHub Copilot命令行界面| ~/.copilot/mcp-config.json | ~/.copilot/mcp-config.json | %USERPROFILE%\.copilot\mcp-config.json | Copilot CLI MCP指南 | |Visual Studio代码| ~/.config/Code/User/mcp.json | ~/Library/Application Support/Code/User/mcp.json | %APPDATA%\Code\User\mcp.json | VS代码MCP服务器 | |OpenCode| ~/.config/opencode/opencode.json | ~/.config/opencode/opencode.json | %LOCALAPPDATA%\opencode\opencode.json | OpenCode MCP指南 |

5.1.法典

默认配置文件: ~/.codex/config.toml

[mcp_servers.context7]
command = "npx"
args = [
    "-y",
    "@upstash/context7-mcp",
    "--api-key",
    "YOUR_API_KEY"
]
env = {}
startup_timeout_sec = 60

备选方案-远程HTTP服务器:

[mcp_servers.context7]
url = "https://mcp.context7.com/mcp"
bearer_token_env_var = "CONTEXT7_API_KEY"
startup_timeout_sec = 60

5.2.克劳德代码

默认配置文件: ~/.claude.json

{  
  "mcpServers": {  
    "context7": {  
        "type": "stdio",  
        "command": "npx",  
        "args": [  
            "-y",  
            "@upstash/context7-mcp",  
            "--api-key",  
            "YOUR_API_KEY"  
        ],  
        "env": {}  
    }  
  }  
}

5.3.光标

默认配置文件: ~/.cursor/mcp.json

{  
    "mcpServers": {  
        "context7": {  
            "command": "npx",  
            "args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]  
        }  
    }  
}

5.4.Gemini CLI(gcloud)

默认配置文件:~/.ggemini/settings.json

{  
    "mcpServers": {  
        "context7": {  
            "command": "npx",  
            "args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]  
        }  
    }  
}

5.5.GitHub Copilot 命令行界面

默认配置文件: ~/.copilot/mcp-config.json

{
  "mcpServers": {
    "context7": {
      "type": "local",
      "command": "npx",
      "args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"],
      "env": {}
    }
  }
}

5.6.Visual Studio Code

默认配置文件:

  • macOS: ~/Library/Application Support/Code/User/mcp.json
  • Linux: ~/.config/Code/User/mcp.json
  • 视窗: %APPDATA%\Code\User\mcp.json
{
    "servers": {
        "context7": {
            "type": "stdio",
            "command": "npx",
            "args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
        }
    }
}

5.7.OpenCode

默认配置文件:

  • macOS/Linux: ~/.config/opencode/opencode.json
  • 视窗: %LOCALAPPDATA%\opencode\opencode.json

本地MCP服务器:

{
    "mcp": {
        "context7": {
            "type": "local",
            "command": ["npx", "-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"],
            "environment": {}
        }
    }
}

远程MCP服务器:

{
    "mcp": {
        "context7": {
            "type": "remote",
            "url": "https://mcp.context7.com/mcp",
            "timeout": 5000
        }
    }
}

6.核心特征

  • 双模式操作:支持快速、直接的单行命令同步和引导式交互模式。
  • 模糊参数匹配:用户不需要记住确切的工具名称;该工具自动匹配常用关键字。
  • 跨平台兼容性:完美支持Linux、Windows和macOS环境,自动处理不同的操作系统路径格式。
  • 自动路径检测:内置主流开发工具的默认配置路径,自动发现本地现有的配置文件。
  • 安全备份机制:在执行任何覆盖操作之前,自动备份目标配置文件,确保操作可逆,防止意外数据丢失。
  • 定制和扩展:支持手动指定配置文件路径,如果目标文件不存在,可以自动创建目标文件。

7.文件备份机制

安全是该工具的核心原则之一。在执行任何同步操作(即覆盖目标文件)之前,请执行以下备份过程 必须 执行:

  1. 安全原则:在任何操作写入目标文件之前,必须完成备份以确保操作可逆。
  2. 默认位置:创建 ~/.sync-mcp/backup/ 用户主目录中的目录。如果它不存在,它会自动创建。
  3. 备份内容:完整的副本 当前目标文件.
  4. 备份路径:
    • 根目录: ~/.sync-mcp/backup/
    • 子目录结构: /<timestamp>/<original_directory_structure>/<original_filename>
    • <timestamp>:执行同步操作时的Unix时间戳(以毫秒为单位)。, 1677619200000
  5. 示例:
    • 操作: npx sync-mcp vscode cursor
    • 时间: 2025-10-24 18:00:00 (假设时间戳 1761319200000)
    • 目标文件: ~/.cursor/mcp.json 在Linux上
    • 行动:程序复制 ~/.cursor/mcp.json 到 ~/.sync-mcp/backup/1761319200000/.cursor/mcp.json
    • 这可以防止备份文件被覆盖,并保留原始文件的路径结构,使其易于查找和还原。

8.平台兼容性

  • 操作系统:必须在主流Linux发行版(Ubuntu、CentOS等)以及Windows 10/11和macOS上稳定运行。
  • 路径处理:内部逻辑必须使用Node.js path 模块功能如下 path.join() 和 path.resolve() 以处理文件路径。硬编码 / 或 \ 被禁止。