interplane.Get Omega
Read in your language

omega-mcp

aien-dev/omega-mcp

Brought by drakestapleton

branch main Branches Tags History

omega-mcp / tools / register_merge.py

62 lines · 2321 bytes Raw Blame History
1#!/usr/bin/env python3
2"""Write an MCP client file that names the two agent servers.
3
4The current file, when given, must be a JSON object. mcpServers.agent-maintenance and
5mcpServers.agent-qa are set to the stdio entries for this prefix. Every other key is left
6as it was. The result is written only to --out, which the caller stages outside the lock.
7Prints `unchanged` when --out would match the current bytes, otherwise `changed`.
8Exit 2 when the current file is not a JSON object or mcpServers is not an object.
9"""
10import argparse, json, os, sys
11
12
13def load(path):
14 if path is None:
15 return {}
16 with open(path, "r", encoding="utf-8") as f:
17 data = json.load(f)
18 if not isinstance(data, dict):
19 raise SystemExit(f"register_merge: {path} is not a JSON object")
20 return data
21
22
23def main():
24 ap = argparse.ArgumentParser()
25 ap.add_argument("--current")
26 ap.add_argument("--out", required=True)
27 ap.add_argument("--root", required=True)
28 ap.add_argument("--prefix", required=True)
29 ap.add_argument("--store", required=True)
30 ap.add_argument("--consent", required=True)
31 ap.add_argument("--agent", required=True)
32 a = ap.parse_args()
33 for p in (a.root, a.prefix, a.store, a.consent):
34 if not p.startswith("/"):
35 raise SystemExit(f"register_merge: {p} is not absolute")
36 data = load(a.current)
37 servers = data.get("mcpServers", {})
38 if not isinstance(servers, dict):
39 raise SystemExit("register_merge: mcpServers is not a JSON object")
40 servers["agent-maintenance"] = {
41 "type": "stdio",
42 "command": os.path.join(a.prefix, "agent-maintenance-mcp"),
43 "args": ["--root", a.root],
44 }
45 servers["agent-qa"] = {
46 "type": "stdio",
47 "command": os.path.join(a.prefix, "agent-qa-mcp"),
48 "args": ["--store", a.store, "--agent", a.agent, "--consent", a.consent],
49 }
50 data["mcpServers"] = servers
51 raw = json.dumps(data, indent=2) + "\n"
52 current = ""
53 if a.current is not None and os.path.exists(a.current):
54 with open(a.current, "r", encoding="utf-8") as f:
55 current = f.read()
56 with open(a.out, "w", encoding="utf-8") as f:
57 f.write(raw)
58 print("unchanged" if raw == current else "changed")
59
60
61if __name__ == "__main__":
62 sys.exit(main())