Skip to content

Instantly share code, notes, and snippets.

@mohemohe
Last active December 5, 2025 15:39
Show Gist options
  • Select an option

  • Save mohemohe/69c0946b89b04621e02232aec6f5e0fa to your computer and use it in GitHub Desktop.

Select an option

Save mohemohe/69c0946b89b04621e02232aec6f5e0fa to your computer and use it in GitHub Desktop.
.claude.jsonが破損した時に .claude/mcp.json を .claude.json にマージするやつ
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const home = process.env.HOME || process.env.USERPROFILE || '';
const mcpPath = path.join(home, '.claude', 'mcp.json');
const claudePath = path.join(home, '.claude.json');
let originalMcpJson = null;
try {
const raw = fs.readFileSync(mcpPath, 'utf8');
originalMcpJson = JSON.parse(raw);
} catch (err) {
console.error(`Failed to load ${mcpPath}: ${err.message}`);
process.exit(1);
}
originalMcpJson = {
mcpServers: Object.fromEntries(
Object.entries(originalMcpJson.mcpServers).filter(([, value]) => !value.disabled)
),
};
let claudeMcpJson = null;
try {
const raw = fs.readFileSync(claudePath, 'utf8');
claudeMcpJson = JSON.parse(raw);
} catch (err) {
console.error(`Failed to load ${claudePath}: ${err.message}`);
process.exit(2);
}
const mergedMcpJson = {
...claudeMcpJson,
mcpServers: originalMcpJson.mcpServers,
};
const result = JSON.stringify(mergedMcpJson, null, 2);
fs.writeFileSync(claudePath, result);
@mohemohe
Copy link
Author

mohemohe commented Nov 21, 2025

curl -o claude-sync-mcp https://gist.githubusercontent.com/mohemohe/69c0946b89b04621e02232aec6f5e0fa/raw/5db3570d98b951e10d4a3da8d22a9e41639db236/claude-sync-mcp
sudo mv claude-sync-mcp /usr/local/bin/claude-sync-mcp
sudo chmod a+x /usr/local/bin/claude-sync-mcp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment