"""Treat agent and MCP config files in a cloned repo as untrusted: list them, show the commands they would run, and fail unless the file's SHA-256 is in the reviewed list. usage: python scan_repo_config.py [reviewed.json]""" import hashlib, json, os, sys NAMES = {".mcp.json", "mcp.json", "AGENTS.md"} repo = sys.argv[1]; reviewed = json.load(open(sys.argv[2])) if len(sys.argv) > 2 else {} bad = 0 for root, dirs, files in os.walk(repo): dirs[:] = [d for d in dirs if d not in (".git", "node_modules")] for f in files: if f in NAMES: p = os.path.join(root, f); rel = os.path.relpath(p, repo); h = hashlib.sha256(open(p, "rb").read()).hexdigest() ok = reviewed.get(rel) == h cmds = [] if f.endswith(".json"): servers = json.load(open(p)).get("mcpServers", json.load(open(p)).get("servers", {})) cmds = [" ".join([s.get("command", s.get("url", "?"))] + s.get("args", [])) for s in servers.values()] print(json.dumps({"file": rel, "sha256": h[:16], "decision": "allow" if ok else "block", "would_run": cmds})) bad += 0 if ok else 1 sys.exit(1 if bad else 0)