Created
November 4, 2025 19:42
-
-
Save akostadinov/c32f0939edbd80edb5b4bafafaa9e5bd to your computer and use it in GitHub Desktop.
claude_json_disable_mcps.rb
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 ruby | |
| # LICENSE: MIT | |
| # ASSITED_BY: CLAUDE CODE | |
| require 'json' | |
| require 'tempfile' | |
| # Read the claude.json file | |
| claude_json_path = File.expand_path('~/.claude.json') | |
| unless File.exist?(claude_json_path) | |
| warn "Error: #{claude_json_path} not found" | |
| exit 1 | |
| end | |
| # Parse the JSON | |
| config = JSON.parse(File.read(claude_json_path)) | |
| # Extract MCP server names | |
| mcp_servers = config['mcpServers']&.keys | |
| unless mcp_servers.is_a? Array | |
| warn "No MCP servers found" | |
| exit 0 | |
| end | |
| # Get all projects | |
| projects = config['projects'] | |
| unless projects.is_a? Hash | |
| warn "No projects found" | |
| exit 0 | |
| end | |
| warn "MCP servers: #{mcp_servers.join(', ')}" | |
| warn | |
| # Update projects | |
| projects.each do |_project_path, project_config| | |
| project_config['disabledMcpServers'] = mcp_servers | |
| end | |
| # Generate new content | |
| new_content = JSON.pretty_generate(config) | |
| # Create temp files for diff | |
| Tempfile.create('claude-new') do |updated| | |
| updated.write(new_content) | |
| updated.flush | |
| # Show colored diff | |
| if system("diff -u --color=always #{claude_json_path} #{updated.path}") | |
| warn "No changes done" | |
| exit | |
| end | |
| end | |
| warn | |
| # Ask to update | |
| print "Update #{claude_json_path}? (y/N) " | |
| response = gets.chomp.downcase | |
| if response == 'y' | |
| File.write(claude_json_path, new_content) | |
| warn "✓ Updated" | |
| else | |
| warn "No changes made" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment