Last active
December 5, 2025 15:39
-
-
Save mohemohe/69c0946b89b04621e02232aec6f5e0fa to your computer and use it in GitHub Desktop.
.claude.jsonが破損した時に .claude/mcp.json を .claude.json にマージするやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.