[docs]defget_default_claude_desktop_config_path()->Path:# pragma: no cover""" See https://modelcontextprotocol.io/quickstart/user - macOS: ~/Library/Application Support/Claude/claude_desktop_config.json - Windows: %APPDATA%\Claude\claude_desktop_config.json """ifIS_MACOS:return(Path.home()/"Library"/"Application Support"/"Claude"/"claude_desktop_config.json")elifIS_WINDOWS:importosappdata=os.environ.get("APPDATA")ifappdata:returnPath(appdata)/"Claude"/"claude_desktop_config.json"else:# Fallback to typical Windows path if APPDATA is not setreturn(Path.home()/"AppData"/"Roaming"/"Claude"/"claude_desktop_config.json")elifIS_LINUX:# pragma: no coverreturnPath.home()/".config"/"Claude"/"claude_desktop_config.json"else:# pragma: no coverraiseOSError("Unsupported operating system")
[docs]defread(self)->dict[str,T.Any]:""" Read the configuration from the file. """returnjson.loads(self.path.read_text(encoding="utf-8"))
[docs]defwrite(self,config:dict[str,T.Any]):""" Write the configuration to the file. """self.path.write_text(json.dumps(config,indent=4),encoding="utf-8")
[docs]defdel_mcp_server(self,name:str):""" Remove an MCP server from the configuration. This is an idempotent operation - no error if the server doesn't exist. """config=self.read()is_changed=Falseif"mcpServers"inconfigandnameinconfig["mcpServers"]:delconfig["mcpServers"][name]is_changed=True# Remove empty mcpServers key to keep config cleanifnotconfig["mcpServers"]:delconfig["mcpServers"]ifis_changed:self.write(config)