2026-02-24 22:22:53 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
"""
|
2026-06-22 20:46:14 +02:00
|
|
|
Patch ~/.claude.json to add the cwd field to the dev-hub MCP entry.
|
2026-02-24 22:22:53 +01:00
|
|
|
|
|
|
|
|
claude mcp add-json silently drops the cwd field. Run this script after
|
|
|
|
|
any claude mcp add-json call to restore it.
|
|
|
|
|
|
|
|
|
|
Usage: python3 scripts/patch_mcp_cwd.py
|
|
|
|
|
"""
|
|
|
|
|
import json
|
|
|
|
|
import os
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
2026-06-22 20:46:14 +02:00
|
|
|
from mcp_server.constants import LEGACY_MCP_SERVER_NAME, MCP_SERVER_NAME
|
|
|
|
|
from scripts.mcp_registration import load_claude_json, resolve_mcp_server_name
|
|
|
|
|
|
2026-02-24 22:22:53 +01:00
|
|
|
CLAUDE_JSON = Path.home() / ".claude.json"
|
2026-06-22 20:46:14 +02:00
|
|
|
STATE_HUB_DIR = Path(__file__).resolve().parent.parent
|
|
|
|
|
|
2026-02-24 22:22:53 +01:00
|
|
|
|
|
|
|
|
def main() -> None:
|
2026-06-22 20:46:14 +02:00
|
|
|
config = load_claude_json(CLAUDE_JSON)
|
|
|
|
|
if config is None:
|
2026-02-24 22:22:53 +01:00
|
|
|
print(f"ERROR: {CLAUDE_JSON} not found. Run 'claude mcp add-json' first.")
|
|
|
|
|
raise SystemExit(1)
|
|
|
|
|
|
|
|
|
|
servers = config.setdefault("mcpServers", {})
|
2026-06-22 20:46:14 +02:00
|
|
|
server_name = resolve_mcp_server_name(config)
|
|
|
|
|
if server_name is None:
|
|
|
|
|
print(
|
|
|
|
|
f"ERROR: neither '{MCP_SERVER_NAME}' nor '{LEGACY_MCP_SERVER_NAME}' "
|
|
|
|
|
f"found in ~/.claude.json. Run 'claude mcp add-json' first."
|
|
|
|
|
)
|
2026-02-24 22:22:53 +01:00
|
|
|
raise SystemExit(1)
|
|
|
|
|
|
2026-06-22 20:46:14 +02:00
|
|
|
if server_name == LEGACY_MCP_SERVER_NAME:
|
|
|
|
|
print(
|
|
|
|
|
f"NOTE: patching legacy '{LEGACY_MCP_SERVER_NAME}' entry. "
|
|
|
|
|
"Run scripts/migrate_mcp_config.py to rename to dev-hub."
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
entry = servers[server_name]
|
2026-02-24 22:22:53 +01:00
|
|
|
cwd_str = str(STATE_HUB_DIR)
|
|
|
|
|
|
|
|
|
|
if entry.get("cwd") == cwd_str:
|
|
|
|
|
print(f"OK: cwd already set to {cwd_str}")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
entry["cwd"] = cwd_str
|
|
|
|
|
CLAUDE_JSON.write_text(json.dumps(config, indent=2) + "\n")
|
2026-06-22 20:46:14 +02:00
|
|
|
print(f"Patched: ~/.claude.json {server_name}.cwd = {cwd_str}")
|
2026-02-24 22:22:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2026-06-22 20:46:14 +02:00
|
|
|
main()
|