Normalize stored MCP CLI JSON (#1554)

This commit is contained in:
red person
2026-06-03 08:11:35 +03:00
committed by GitHub
parent 38bfa85ad0
commit f549058369
2 changed files with 51 additions and 8 deletions

View File

@@ -33,15 +33,25 @@ except ModuleNotFoundError as e:
sys.exit(2)
def _json_list(raw) -> list:
try:
value = json.loads(raw) if raw else []
except (TypeError, json.JSONDecodeError):
return []
return value if isinstance(value, list) else []
def _json_dict(raw) -> dict:
try:
value = json.loads(raw) if raw else {}
except (TypeError, json.JSONDecodeError):
return {}
return value if isinstance(value, dict) else {}
def _serialize(s: "McpServer", redact_env: bool = True) -> dict:
try:
args_arr = json.loads(s.args) if s.args else []
except json.JSONDecodeError:
args_arr = []
try:
env_obj = json.loads(s.env) if s.env else {}
except json.JSONDecodeError:
env_obj = {}
args_arr = _json_list(s.args)
env_obj = _json_dict(s.env)
if redact_env and isinstance(env_obj, dict):
env_obj = {k: ("***" if v else "") for k, v in env_obj.items()}
return {