generated from coulomb/repo-seed
Introduce canonical MCP_SERVER_NAME constants, shared registration helpers, and a migrate_mcp_config.py script for ~/.claude.json upgrades. Registration, patch, and custodian CLI checks accept both dev-hub and legacy state-hub during transition. API root metadata and session-protocol template reflect the new name.
30 lines
911 B
Python
30 lines
911 B
Python
"""Helpers for ~/.claude.json MCP server registration checks."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from mcp_server.constants import LEGACY_MCP_SERVER_NAME, MCP_SERVER_NAME
|
|
|
|
|
|
def load_claude_json(path: Path | None = None) -> dict | None:
|
|
claude_json = path or Path.home() / ".claude.json"
|
|
if not claude_json.exists():
|
|
return None
|
|
return json.loads(claude_json.read_text())
|
|
|
|
|
|
def mcp_server_registered(config: dict | None) -> bool:
|
|
if not config:
|
|
return False
|
|
servers = config.get("mcpServers", {})
|
|
return MCP_SERVER_NAME in servers or LEGACY_MCP_SERVER_NAME in servers
|
|
|
|
|
|
def resolve_mcp_server_name(config: dict) -> str | None:
|
|
servers = config.get("mcpServers", {})
|
|
if MCP_SERVER_NAME in servers:
|
|
return MCP_SERVER_NAME
|
|
if LEGACY_MCP_SERVER_NAME in servers:
|
|
return LEGACY_MCP_SERVER_NAME
|
|
return None |