ueagentdevkit 0.3.0__py3-none-any.whl → 0.3.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. Tools/connect_editor.py +351 -159
  2. Tools/mcp_readback.py +61 -13
  3. Tools/media.py +115 -10
  4. Tools/provider/capabilities.json +12 -12
  5. Tools/provider/scripts/connect.py +3 -2
  6. Tools/provider/scripts/launch_editor.py +25 -8
  7. Tools/provider_install.py +170 -0
  8. Tools/setup.py +17 -0
  9. {ueagentdevkit-0.3.0.data → ueagentdevkit-0.3.1.data}/data/share/ueagentdevkit/skills/ue-editor-connection/SKILL.md +1 -1
  10. ueagentdevkit-0.3.1.dist-info/METADATA +71 -0
  11. {ueagentdevkit-0.3.0.dist-info → ueagentdevkit-0.3.1.dist-info}/RECORD +24 -23
  12. ueagentdevkit-0.3.0.dist-info/METADATA +0 -61
  13. {ueagentdevkit-0.3.0.data → ueagentdevkit-0.3.1.data}/data/Scripts/Connect-UE.cmd +0 -0
  14. {ueagentdevkit-0.3.0.data → ueagentdevkit-0.3.1.data}/data/Scripts/Connect-UE.ps1 +0 -0
  15. {ueagentdevkit-0.3.0.data → ueagentdevkit-0.3.1.data}/data/Scripts/Install-Shortcut.ps1 +0 -0
  16. {ueagentdevkit-0.3.0.data → ueagentdevkit-0.3.1.data}/data/Scripts/Test-Play.cmd +0 -0
  17. {ueagentdevkit-0.3.0.data → ueagentdevkit-0.3.1.data}/data/share/ueagentdevkit/association/LICENSE +0 -0
  18. {ueagentdevkit-0.3.0.data → ueagentdevkit-0.3.1.data}/data/share/ueagentdevkit/association/Repair-UnrealAssociation.ps1 +0 -0
  19. {ueagentdevkit-0.3.0.data → ueagentdevkit-0.3.1.data}/data/share/ueagentdevkit/association/Start-Doctor.ps1 +0 -0
  20. {ueagentdevkit-0.3.0.data → ueagentdevkit-0.3.1.data}/data/share/ueagentdevkit/skills/ue-automation-evidence/SKILL.md +0 -0
  21. {ueagentdevkit-0.3.0.data → ueagentdevkit-0.3.1.data}/data/share/ueagentdevkit/skills/ue-project-hygiene/SKILL.md +0 -0
  22. {ueagentdevkit-0.3.0.dist-info → ueagentdevkit-0.3.1.dist-info}/WHEEL +0 -0
  23. {ueagentdevkit-0.3.0.dist-info → ueagentdevkit-0.3.1.dist-info}/entry_points.txt +0 -0
  24. {ueagentdevkit-0.3.0.dist-info → ueagentdevkit-0.3.1.dist-info}/licenses/LICENSE +0 -0
  25. {ueagentdevkit-0.3.0.dist-info → ueagentdevkit-0.3.1.dist-info}/top_level.txt +0 -0
Tools/connect_editor.py CHANGED
@@ -14,6 +14,7 @@ import time
14
14
  from urllib.parse import urlsplit
15
15
 
16
16
  from environment import find_engine, read_json
17
+ from provider_install import install, package_for
17
18
 
18
19
  ROOT = Path(__file__).resolve().parents[1]
19
20
  SCRIPTS = Path(__file__).resolve().parent / "provider/scripts"
@@ -105,15 +106,6 @@ def register_codex(report):
105
106
 
106
107
  def connect_one(args, expected=None):
107
108
  project = args.project.resolve()
108
- if args.capability == "umg":
109
- sys.path.insert(0, str(SCRIPTS))
110
- import launch_editor
111
- import routing
112
- engine = find_engine(read_json(project)["EngineAssociation"], args.engine)
113
- v = launch_editor.engine_version(engine)
114
- version = ".".join(str(v[key]) for key in ("MajorVersion", "MinorVersion", "PatchVersion"))
115
- if routing.route(routing.load(), version, "umg")["selected"] == "umgmcp":
116
- return connect_umg(args, project, engine)
117
109
  cmd = [sys.executable, "-X", "utf8", str(SCRIPTS / "connect.py"), "--json", "--project", str(project),
118
110
  "--client", args.client, "--capability", args.capability, "--engine",
119
111
  str(find_engine(read_json(project)["EngineAssociation"], args.engine))]
@@ -135,37 +127,6 @@ def connect_one(args, expected=None):
135
127
  return verify_and_register(args, report, env)
136
128
 
137
129
 
138
- def connect_umg(args, project, engine):
139
- import connect
140
- import launch_editor
141
- import routing
142
- if args.provider not in ("auto", "umgmcp") or args.client != "codex":
143
- raise ValueError("This UMG stdio adapter uses the configured Codex bridge")
144
- plugins = connect.plugin_state(project, engine, "umgmcp", routing.load())
145
- if not plugins:
146
- raise ValueError("Install the licensed UmgMcp plugin for this engine, then run setup --umg-plugin")
147
- if (not any(p["enabled"] for p in plugins) and not (args.auto_enable or args.dry_run)
148
- and not launch_editor.running_editors(project)):
149
- raise ValueError("Enable the installed UMG plugin with --auto-enable")
150
- if not any(p["enabled"] for p in plugins) and (args.auto_enable or args.dry_run):
151
- command = [sys.executable, str(SCRIPTS / "enable_plugins.py"), "--project", str(project),
152
- "--engine", str(engine), "--plugin", plugins[0]["plugin"]]
153
- plan = json.loads(subprocess.check_output(command, timeout=90))
154
- if not args.dry_run:
155
- subprocess.check_output([*command, "--apply", "--expect-sha", plan["before_sha256"]], timeout=180)
156
- if args.dry_run:
157
- return dict(ok=True, project=str(project), provider="umgmcp", plugins=plugins, dry_run=True)
158
- report = launch_editor.prepare(project, engine, require_http=False)
159
- deadline = time.monotonic() + (90 if report["action"] == "launched" else 0)
160
- while True:
161
- detail = read_umg(project, report["pid"], args)
162
- if detail.get("verified") or time.monotonic() >= deadline:
163
- return dict(ok=detail.get("verified", False), launch=report["action"], project=str(project),
164
- identity=dict(verified=detail.get("verified", False), pid=report["pid"]),
165
- readback=detail, provider="umgmcp")
166
- time.sleep(1)
167
-
168
-
169
130
  def read_umg(project, pid, args):
170
131
  probe = subprocess.run([sys.executable, str(ROOT / "Tools/umg_readback.py"), str(project),
171
132
  str(pid), args.umg_alias, *(["--widget", args.widget] if args.widget else [])],
@@ -185,19 +146,29 @@ def verify_and_register(args, report, env, check_identity=None):
185
146
  else:
186
147
  transform = json.loads(camera.stdout.strip().splitlines()[-1])["GetCameraTransform"]
187
148
  report["viewport"] = {"verified": True, "transform": transform}
188
- if report.get("ok") and not args.dry_run and report["provider"] in ("nwiro", "monolith"):
149
+ proof_role = "blueprint" if args.capability == "editor" else args.capability
150
+ if (report.get("ok") and not args.dry_run and
151
+ (report["provider"], proof_role) in {
152
+ ("nwiro", "blueprint"), ("monolith", "animgraph"), ("monolith", "blueprint"),
153
+ ("pinwright", "blueprint"), ("pinwright", "animgraph")}):
189
154
  sys.path.insert(0, str(SCRIPTS))
190
155
  from connect import probe_command
191
- probe = subprocess.run([*probe_command(), str(ROOT / "Tools/mcp_readback.py"), report["endpoint"],
192
- report["provider"]], capture_output=True, encoding="utf-8", timeout=50, env=env)
156
+ command = [*probe_command(), str(ROOT / "Tools/mcp_readback.py"), report["endpoint"],
157
+ report["provider"], "--capability", proof_role]
158
+ if asset := getattr(args, "asset", None):
159
+ command.extend(["--asset", asset])
160
+ if report["provider"] == "pinwright":
161
+ command.extend(["--token-file", str(Path(report["project"]).parent / "Saved/PinWright/gateway-token")])
162
+ probe = subprocess.run(command, capture_output=True, encoding="utf-8", timeout=50, env=env)
193
163
  evidence = json.loads(probe.stdout) if probe.returncode == 0 else {}
194
164
  data = evidence.get("data", {})
195
165
  nodes = data.get("nodes", []) if isinstance(data, dict) else []
196
166
  report["graph"] = dict(verified=evidence.get("verified", False), asset=evidence.get("asset"), nodes=len(nodes),
197
- classes=[n.get("class") for n in nodes[:8]])
167
+ role=args.capability, classes=[n.get("class", n.get("nodeType")) for n in nodes[:8]])
198
168
  if check_identity:
199
169
  check_identity()
200
- if report.get("ok") and args.client == "codex" and not (args.dry_run or args.no_register):
170
+ if (report.get("ok") and args.client == "codex" and not (args.dry_run or args.no_register)
171
+ and capability_verified(args.capability, report)):
201
172
  try:
202
173
  report["registration"] = register_codex(report)
203
174
  except (OSError, ValueError, subprocess.SubprocessError) as exc:
@@ -205,6 +176,41 @@ def verify_and_register(args, report, env, check_identity=None):
205
176
  return report
206
177
 
207
178
 
179
+ def capability_verified(role, details):
180
+ if role == "editor" and details.get("viewport", {}).get("verified"):
181
+ return True
182
+ if role == "umg":
183
+ return bool(details.get("readback", {}).get("root_widget"))
184
+ graph = details.get("graph") or {}
185
+ return graph.get("role") == role and bool(graph.get("verified"))
186
+
187
+
188
+ def register_blueprint_bridge(project, executable, client):
189
+ if client != "codex" or not (cli := shutil.which("codex")):
190
+ raise ValueError("BlueprintMCP stdio registration requires Codex CLI or --no-register")
191
+ name = "ue-blueprint-" + sha256(os.path.normcase(str(project)).encode()).hexdigest()[:12]
192
+
193
+ def inspect():
194
+ result = subprocess.run([cli, "mcp", "get", name, "--json"], capture_output=True,
195
+ encoding="utf-8", timeout=30)
196
+ if not result.returncode:
197
+ return json.loads(result.stdout)
198
+ if "No MCP server" in result.stderr and name in result.stderr:
199
+ return None
200
+ raise ValueError(f"Cannot inspect Codex entry {name}")
201
+
202
+ config = inspect()
203
+ if config is None:
204
+ subprocess.run([cli, "mcp", "add", name, "--", str(executable)], check=True,
205
+ capture_output=True, timeout=30)
206
+ config = inspect()
207
+ transport = (config or {}).get("transport", {})
208
+ if (not config or not config.get("enabled") or transport.get("type") != "stdio"
209
+ or Path(transport.get("command", "")) != executable or transport.get("args")):
210
+ raise ValueError(f"Existing Codex entry {name} differs from the verified bridge")
211
+ return {"name": name, "client": client, "verified": "CLI configuration readback"}
212
+
213
+
208
214
  def auto(args):
209
215
  """Plan once from descriptors, then attach only to attributed listeners."""
210
216
  from copy import copy
@@ -224,63 +230,145 @@ def auto(args):
224
230
  v = snapshot["build_version"]
225
231
  version = ".".join(str(v[k]) for k in ("MajorVersion", "MinorVersion", "PatchVersion"))
226
232
  model = routing.load()
227
- installed = snapshot["plugins_not_load_verified"]
228
- if args.auto_enable:
229
- names = set()
230
- for role in ("editor", "blueprint", "animgraph", "umg"):
231
- name = routing.route(model, version, role)["selected"]
232
- if name:
233
- names.update(p["plugin"] for p in connect.plugin_state(project, engine, name, model)
234
- if not p["enabled"])
235
- if names:
236
- command = [sys.executable, str(SCRIPTS / "enable_plugins.py"), "--project", str(project),
237
- "--engine", str(engine)]
238
- for name in sorted(names):
239
- command.extend(["--plugin", name])
240
- plan = json.loads(subprocess.check_output(command, timeout=90))
241
- if args.dry_run:
242
- return dict(ok=True, project=str(project), dry_run=True, activation=plan)
243
- subprocess.run([*command, "--apply", "--expect-sha", plan["before_sha256"]], check=True,
244
- stdout=subprocess.PIPE, timeout=180)
245
- installed = discover.discover(project, engine)["plugins_not_load_verified"]
233
+ module_file = Path("Binaries/Win64/UnrealEditor.modules")
234
+ engine_modules = engine / "Engine" / module_file
235
+ engine_build = read_json(engine_modules).get("BuildId") if engine_modules.is_file() else None
236
+ def assert_closed():
237
+ if launch_editor.running_editors(project):
238
+ raise ValueError("Close the target editor before installing or enabling providers")
239
+
240
+ roles = ("editor", "blueprint", "animgraph", "umg") if args.capability == "auto" else (args.capability,)
241
+ choices = {}
242
+ changes = {}
243
+ local_plugins = {}
244
+ attempted_installs = {}
245
+ failed_installs = {}
246
246
  rows = []
247
- providers = {}
248
- for role in ("editor", "blueprint", "animgraph", "umg"):
249
- name = routing.route(model, version, role)["selected"]
250
- row = dict(role=role, provider=name, state="unavailable")
247
+ for role in roles:
248
+ route = routing.route(model, version, role)
249
+ names = [p["provider"] for p in route["candidates"] if p["in_declared_route"]]
250
+ if not names:
251
+ names = [p["provider"] for p in route["candidates"]]
252
+ # An upstream build can be tried before local compatibility history exists.
253
+ # Its Build ID and the same live readback gate still apply.
254
+ trial_monolith = (routing.engine_key(version) == "5.7" and
255
+ role in ("blueprint", "animgraph") and args.client == "codex"
256
+ and package_for("monolith", version) is not None)
257
+ if trial_monolith and "monolith" not in names:
258
+ names.append("monolith")
259
+ if args.provider != "auto":
260
+ if (args.provider not in {p["provider"] for p in route["candidates"]}
261
+ and not (trial_monolith and args.provider == "monolith")):
262
+ raise ValueError(f"{args.provider} is not verified for {role} on UE {version}")
263
+ names = [args.provider]
264
+ row = dict(role=role, provider=names[0] if names else None, state="unavailable", attempts=[])
251
265
  rows.append(row)
252
- if not name:
253
- continue
254
- if name == "umgmcp":
255
- row.update(state="external-stdio", detail="Use umg58.list_umg_mcp_servers and match the target PID")
256
- continue
257
- names = {s.lower() for s in routing.providers(model)[name]["pluginNames"]}
258
- descriptors = [p for p in installed if Path(p["descriptor"]).stem.lower() in names]
259
- def enabled(p):
260
- flag = p["project_explicit_enabled"]
261
- return flag if flag is not None else discover.read_json(Path(p["descriptor"])).get("EnabledByDefault", False)
262
- if descriptors and all(enabled(p) for p in descriptors):
263
- row["state"] = "eligible"
264
- elif descriptors:
265
- row["state"] = "disabled"
266
- providers.setdefault(name, []).append(row)
266
+ for name in names:
267
+ try:
268
+ if name not in local_plugins:
269
+ local_plugins[name] = connect.plugin_state(project, engine, name, model)
270
+ plugins = local_plugins[name]
271
+ mismatch = None
272
+ for p in plugins:
273
+ if p["declared_engine"] and routing.engine_key(p["declared_engine"]) != routing.engine_key(version):
274
+ mismatch = "Installed plugin declares a different UE minor version"
275
+ break
276
+ if not engine_build or not p.get("descriptor"):
277
+ continue
278
+ modules = Path(p["descriptor"]).parent / module_file
279
+ if modules.is_file() and read_json(modules).get("BuildId") != engine_build:
280
+ mismatch = "Installed plugin binaries do not match this engine Build ID"
281
+ break
282
+ if mismatch:
283
+ row["attempts"].append(dict(provider=name, state="incompatible",
284
+ error=mismatch))
285
+ continue
286
+ available = any(p["enabled"] for p in plugins)
287
+ package = package_for(name, version)
288
+ source_build = False
289
+ if package is None and getattr(args, "build_source", False):
290
+ package = package_for(name, version, source=True)
291
+ source_build = package is not None
292
+ if (not plugins and package and not getattr(args, "no_install", False)
293
+ and not any(a["state"] in ("eligible", "planned-install") for a in row["attempts"])
294
+ and not snapshot["editor_pids"]):
295
+ if name in failed_installs:
296
+ raise ValueError(failed_installs[name])
297
+ if name not in attempted_installs:
298
+ try:
299
+ attempted_installs[name] = None if args.dry_run else install(
300
+ project, engine, package, assert_closed, source=source_build)
301
+ except (OSError, ValueError) as exc:
302
+ failed_installs[name] = str(exc)
303
+ raise
304
+ if args.dry_run:
305
+ row["attempts"].append(dict(provider=name, state="planned-install",
306
+ version=package[1], source_build=source_build))
307
+ continue
308
+ plugins = connect.plugin_state(project, engine, name, model)
309
+ local_plugins[name] = plugins
310
+ available = any(p["enabled"] for p in plugins)
311
+ if plugins and not available and not snapshot["editor_pids"] and (
312
+ args.auto_enable or name in attempted_installs):
313
+ changes[name] = [p["plugin"] for p in plugins if not p["enabled"]]
314
+ available = True
315
+ state = "eligible" if available else "disabled" if plugins else "not-installed"
316
+ if name == "umgmcp" and not plugins:
317
+ state = "external-stdio"
318
+ attempt = dict(provider=name, state=state)
319
+ if not plugins:
320
+ attempt["source"] = routing.providers(model)[name]["source"]
321
+ row["attempts"].append(attempt)
322
+ if available or (plugins and snapshot["editor_pids"]):
323
+ choices.setdefault(role, []).append(name)
324
+ except (ValueError, RuntimeError, OSError, subprocess.SubprocessError) as exc:
325
+ row["attempts"].append(dict(provider=name, state="failed", error=str(exc)))
326
+ if row["attempts"]:
327
+ best = next((a for a in row["attempts"] if a["state"] in ("eligible", "planned-install")),
328
+ row["attempts"][0])
329
+ row.update(provider=best["provider"], state=best["state"])
330
+ if row["state"] == "not-installed":
331
+ row["state"] = "unavailable"
332
+ def activate(plugins):
333
+ command = [sys.executable, str(SCRIPTS / "enable_plugins.py"), "--project", str(project),
334
+ "--engine", str(engine)]
335
+ for plugin in sorted(set(plugins)):
336
+ command.extend(["--plugin", plugin])
337
+ plan = json.loads(subprocess.check_output(command, timeout=90))
338
+ if not args.dry_run:
339
+ assert_closed()
340
+ subprocess.run([*command, "--apply", "--expect-sha", plan["before_sha256"]],
341
+ check=True, stdout=subprocess.PIPE, timeout=180)
342
+ return plan
343
+
344
+ if changes:
345
+ try:
346
+ activation = activate(p for items in changes.values() for p in items)
347
+ except (OSError, ValueError, subprocess.SubprocessError):
348
+ activation = {}
349
+ for name, plugins in changes.items():
350
+ try:
351
+ activation[name] = activate(plugins)
352
+ except (OSError, ValueError, subprocess.SubprocessError) as exc:
353
+ for row in rows:
354
+ options = choices.get(row["role"], [])
355
+ if name in options:
356
+ options.remove(name)
357
+ row["attempts"].append(dict(provider=name, state="activation-failed",
358
+ error=str(exc)))
359
+ if row["provider"] == name:
360
+ row.update(provider=options[0] if options else name,
361
+ state="eligible" if options else "failed")
267
362
  def endpoints(inv, name):
268
363
  return [c for c in inv["http_candidates"] if c.get("listener_pids") == inv["editor_pids"]
269
364
  and len(inv["editor_pids"]) == 1 and connect.HINT_PREFIX[name] in
270
365
  str(c.get("provider_hint","")).lower()]
271
- ready = []
272
- for name, group in providers.items():
273
- live = endpoints(snapshot, name)
274
- if len(live) > 1:
275
- for row in group:
276
- row["state"] = "ambiguous-endpoint"
277
- elif live or (not snapshot["editor_pids"] and group[0]["state"] == "eligible"):
278
- ready.append(name)
279
- elif group[0]["state"] == "eligible":
280
- for row in group:
281
- row["state"] = "no-live-endpoint"
366
+ ready = list(dict.fromkeys(name for names in choices.values() for name in names))
282
367
  result = dict(project=str(project), engine_version=version, mode="auto", roles=rows,
283
- editor_pids=snapshot["editor_pids"], dry_run=args.dry_run)
368
+ editor_pids=snapshot["editor_pids"], dry_run=args.dry_run,
369
+ installations=[item for item in attempted_installs.values() if item])
370
+ if changes:
371
+ result["activation"] = activation
284
372
  result["playtest"] = {
285
373
  "fixture_command": "python ueagent.py uap-lab",
286
374
  "target_plugin_declared": any(p.get("Name") == "UnrealAgentPlayer" and p.get("Enabled")
@@ -289,43 +377,116 @@ def auto(args):
289
377
  }
290
378
  if args.dry_run:
291
379
  result["ok"] = True
380
+ if len(rows) == 1:
381
+ result.update(provider=rows[0]["provider"], capability=rows[0]["role"])
292
382
  return result
293
- if ready and not snapshot["editor_pids"]:
383
+ cold_start = bool(ready and not snapshot["editor_pids"])
384
+ if cold_start:
385
+ http_names = [n for n in ready if n not in ("umgmcp", "blueprintmcp")]
294
386
  flags = []
295
- if "epic-mcp" in ready:
387
+ if any(name in ready for name in ("epic-mcp", "generalblueprint")):
296
388
  with socket.socket() as sock:
297
389
  sock.bind(("127.0.0.1", 0))
298
390
  flags = [*connect.LAUNCH_ARGS["epic-mcp"], f"-ModelContextProtocolPort={sock.getsockname()[1]}"]
299
- launched = launch_editor.prepare(project, engine, flags, timeout=90)
300
- snapshot = launched["discover"]
391
+ if "monolith" in ready:
392
+ with socket.socket() as sock:
393
+ sock.bind(("127.0.0.1", 0))
394
+ flags.append(f"-ini:Monolith:[/Script/MonolithCore.MonolithSettings]:ServerPort={sock.getsockname()[1]}")
395
+ try:
396
+ launched = launch_editor.prepare(project, engine, flags, timeout=120,
397
+ require_http=bool(http_names))
398
+ except launch_editor.LaunchError as exc:
399
+ startup = {key: exc.details[key] for key in (
400
+ "pid", "launch_log", "editor_log", "turnkey_sdk_exit_code", "hint", "cache_hint"
401
+ ) if key in exc.details}
402
+ result.update(stage=exc.stage, error=str(exc), startup=startup)
403
+ pending = exc.details.get("discover", {})
404
+ if not pending.get("editor_pids"):
405
+ result["ok"] = False
406
+ return result
407
+ launched = {"discover": pending}
408
+ snapshot = launched.get("discover") or discover.discover(project, engine)
301
409
  result["editor_pids"] = snapshot["editor_pids"]
302
410
  deadline = time.monotonic() + 15
303
- while any(not endpoints(snapshot, name) for name in ready) and time.monotonic() < deadline:
411
+ while any(not endpoints(snapshot, name) for name in http_names) and time.monotonic() < deadline:
304
412
  time.sleep(.5)
305
413
  snapshot = discover.discover(project, engine)
306
- if not ready and not snapshot["editor_pids"] and any(r["state"] == "external-stdio" for r in rows):
307
- plugins = connect.plugin_state(project, engine, "umgmcp", model)
308
- if any(p["enabled"] for p in plugins):
309
- umg = connect_umg(args, project, engine)
310
- result["editor_pids"] = [umg["identity"]["pid"]]
311
- used = set()
312
- connected = 0
313
- for name in ready:
314
- matches = endpoints(snapshot, name)
315
- group = providers[name]
316
- if len(matches) != 1 or matches[0]["url"] in used:
317
- for row in group:
318
- row["state"] = "endpoint-missing-or-conflicting"
319
- continue
320
- used.add(matches[0]["url"])
414
+ connected = set()
415
+ results = {}
416
+
417
+ def attach(name, role):
321
418
  child = copy(args)
322
- child.capability = group[0]["role"]
323
- child.auto_enable = False
324
- try:
325
- candidate = matches[0]
326
- url = urlsplit(candidate["url"])
327
- if url.hostname not in {"127.0.0.1","localhost","::1"}:
328
- raise ValueError("Provider did not advertise a loopback URL")
419
+ child.provider, child.capability, child.auto_enable = name, role, False
420
+ if name == "umgmcp":
421
+ if args.client != "codex":
422
+ raise ValueError("The UMG stdio adapter uses the configured Codex bridge")
423
+ if not args.no_register and (client := shutil.which("codex")):
424
+ configured = subprocess.run([client, "mcp", "get", args.umg_alias, "--json"],
425
+ capture_output=True, encoding="utf-8", timeout=30)
426
+ if (configured.returncode and "No MCP server" in configured.stderr
427
+ and args.umg_alias in configured.stderr):
428
+ from setup import umg_bridge
429
+ umg_bridge(Path(local_plugins[name][0]["descriptor"]), args.umg_alias)
430
+ deadline = time.monotonic() + (90 if cold_start else 0)
431
+ while True:
432
+ detail = read_umg(project, result["editor_pids"][0], child)
433
+ if detail.get("verified") or time.monotonic() >= deadline:
434
+ break
435
+ time.sleep(1)
436
+ return dict(ok=detail.get("verified", False), readback=detail, provider=name,
437
+ identity=dict(verified=detail.get("verified", False), pid=result["editor_pids"][0]),
438
+ project=str(project), error=detail.get("error"))
439
+ if name == "blueprintmcp":
440
+ from setup import blueprint_bridge
441
+
442
+ pid = result["editor_pids"][0]
443
+ def verify_bridge_owner():
444
+ live = discover.snapshot()
445
+ editors = launch_editor.running_editors(project, live)
446
+ listeners = live["listeners"]
447
+ if ([p["pid"] for p in editors] != [pid]
448
+ or not editors[0]["exe"] or not Path(editors[0]["exe"]).resolve().is_relative_to(engine.resolve())
449
+ or discover.listener_owners(listeners, 55558) != [pid]
450
+ or any(l["LocalAddress"] not in {"127.0.0.1", "::1"} for l in listeners
451
+ if int(l["LocalPort"]) == 55558)):
452
+ raise ValueError("BlueprintMCP TCP port 55558 is not owned exclusively by the target editor on loopback")
453
+ deadline = time.monotonic() + (90 if cold_start else 0)
454
+ while True:
455
+ try:
456
+ verify_bridge_owner()
457
+ break
458
+ except ValueError:
459
+ if time.monotonic() >= deadline:
460
+ raise
461
+ time.sleep(1)
462
+ descriptor = next(p["descriptor"] for p in local_plugins[name]
463
+ if (Path(p["descriptor"]).parent / "Resources/BlueprintMCPServer/uv.lock").is_file())
464
+ executable = blueprint_bridge(Path(descriptor))
465
+ cmd = [*connect.probe_command(), str(ROOT / "Tools/mcp_readback.py"), str(executable), name]
466
+ if asset := getattr(args, "asset", None):
467
+ cmd.extend(["--asset", asset])
468
+ evidence = json.loads(subprocess.check_output(cmd, timeout=50))
469
+ verify_bridge_owner()
470
+ report = dict(ok=True, provider=name, identity=dict(verified=True, pid=pid),
471
+ graph=dict(verified=evidence["verified"], asset=evidence["asset"],
472
+ nodes=evidence["nodes"], role=role))
473
+ if evidence["verified"] and not args.no_register:
474
+ report["registration"] = register_blueprint_bridge(project, executable, args.client)
475
+ verify_bridge_owner()
476
+ return report
477
+ matches = endpoints(snapshot, name)
478
+ if len(matches) != 1:
479
+ raise ValueError("Provider endpoint missing or ambiguous for this editor")
480
+ candidate = matches[0]
481
+ url = urlsplit(candidate["url"])
482
+ if url.hostname not in {"127.0.0.1", "localhost", "::1"}:
483
+ raise ValueError("Provider did not advertise a loopback URL")
484
+ if name == "monolith" and any(
485
+ listener["LocalAddress"] not in {"127.0.0.1", "::1"}
486
+ for listener in snapshot["target_listeners"] if int(listener["LocalPort"]) == url.port
487
+ ):
488
+ raise ValueError("Monolith must listen on loopback only")
489
+ if args.client == "codex":
329
490
  pid = result["editor_pids"][0]
330
491
  def identity():
331
492
  live = discover.snapshot()
@@ -334,55 +495,83 @@ def auto(args):
334
495
  or not Path(editors[0]["exe"]).resolve().is_relative_to(engine.resolve())
335
496
  or discover.listener_owners(live["listeners"], url.port) != [pid]):
336
497
  raise ValueError("Live project path, executable or port owner changed")
498
+ if name == "monolith" and any(
499
+ str(listener.get("LocalAddress")) not in {"127.0.0.1", "::1"}
500
+ for listener in live["listeners"] if int(listener.get("LocalPort", 0)) == url.port
501
+ ):
502
+ raise ValueError("Monolith must listen on loopback only")
337
503
  identity()
338
- if args.client == "codex":
339
- handshake = connect.handshake(candidate, SCRIPTS, timeout=45)
340
- if not handshake["tool_count"]:
341
- raise ValueError("Empty provider tool list")
342
- details = dict(ok=True, project=str(project), provider=name, endpoint=candidate["url"],
343
- identity=dict(verified=True, pid=pid), tools=handshake["tool_count"],
344
- stages=[dict(stage="service",auth_scheme=(candidate.get("auth") or {}).get("scheme"))])
345
- verify_and_register(child, details, dict(os.environ, PYTHONIOENCODING="utf-8"), identity)
346
- else:
347
- details = connect_one(child, (candidate["url"], pid))
348
- valid = (details.get("ok") and details.get("endpoint") == matches[0]["url"]
349
- and [details["identity"]["pid"]] == result["editor_pids"])
350
- for row in group:
351
- proof = details.get("viewport", details.get("graph", {})).get("verified")
352
- proved_role = {"epic-mcp":"editor", "nwiro":"blueprint", "monolith":"animgraph"}.get(name)
353
- row.update(state=("verified" if proof and row["role"] == proved_role else "transport-only") if valid else "failed", connection=details)
354
- connected += bool(valid)
355
- except (ValueError, RuntimeError, OSError, subprocess.SubprocessError) as exc:
356
- for row in group:
357
- row.update(state="failed", error=str(exc))
504
+ handshake = connect.handshake(candidate, SCRIPTS, timeout=45)
505
+ if not handshake["tool_count"]:
506
+ raise ValueError("Empty provider tool list")
507
+ details = dict(ok=True, project=str(project), provider=name, endpoint=candidate["url"],
508
+ identity=dict(verified=True, pid=pid), tools=handshake["tool_count"],
509
+ stages=[dict(stage="service", auth_scheme=(candidate.get("auth") or {}).get("scheme"))])
510
+ return verify_and_register(child, details, dict(os.environ, PYTHONIOENCODING="utf-8"), identity)
511
+ return connect_one(child, (candidate["url"], result["editor_pids"][0]))
512
+
358
513
  for row in rows:
359
- if row["state"] != "external-stdio" or args.client != "codex" or len(result["editor_pids"]) != 1:
360
- continue
361
- try:
362
- detail = read_umg(project, result["editor_pids"][0], args)
363
- except (ValueError, RuntimeError, OSError, subprocess.SubprocessError) as exc:
364
- detail = {"verified":False, "error":str(exc)}
365
- row.update(state=("verified" if detail.get("root_widget") else "transport-only")
366
- if detail["verified"] else "external-stdio", readback=detail)
367
- connected += bool(detail["verified"])
514
+ first_transport = None
515
+ for name in choices.get(row["role"], []):
516
+ key = (name, row["role"])
517
+ if key not in results:
518
+ try:
519
+ results[key] = attach(name, row["role"])
520
+ except (ValueError, RuntimeError, OSError, IndexError, StopIteration, subprocess.SubprocessError) as exc:
521
+ results[key] = dict(ok=False, error=str(exc))
522
+ details = results[key]
523
+ if not details.get("ok"):
524
+ row["attempts"].append(dict(provider=name, state="failed", error=details.get("error")))
525
+ continue
526
+ if capability_verified(row["role"], details):
527
+ row.update(provider=name, state="verified", connection=details)
528
+ connected.add(name)
529
+ break
530
+ row["attempts"].append(dict(provider=name, state="capability-unverified"))
531
+ if first_transport is None:
532
+ first_transport = (name, details)
533
+ else:
534
+ if first_transport:
535
+ name, details = first_transport
536
+ row.update(provider=name, state="transport-only", connection=details)
537
+ connected.add(name)
538
+ elif choices.get(row["role"]):
539
+ row["state"] = "failed"
368
540
  if result["playtest"]["target_plugin_declared"] and len(result["editor_pids"]) == 1:
369
541
  try:
370
542
  result["playtest"].update(read_playtest_preset(project, engine, result["editor_pids"][0], discover, launch_editor))
371
543
  except (OSError, ValueError, http.client.HTTPException, RuntimeError) as exc:
372
544
  result["playtest"].update(state="unverified", error=str(exc))
373
545
  playable = result["playtest"].get("state") == "preset-discovered"
374
- result.update(ok=connected > 0 or playable, connected=connected)
375
- by_provider = {row["provider"]:row for row in rows if row["provider"]}
546
+ result["connected"] = len(connected)
547
+ if args.capability != "auto" and rows[0].get("connection"):
548
+ result.update(rows[0]["connection"])
549
+ verified_roles = [row["role"] for row in rows if row["state"] == "verified"]
550
+ result["verified_capabilities"] = verified_roles
551
+ result["ok"] = bool(verified_roles or (playable and args.capability == "auto"))
552
+ if result["ok"] and result.get("stage") == "wait":
553
+ result["startup_warning"] = result.pop("error")
554
+ result.pop("stage")
555
+ if args.capability != "auto" and not result["ok"]:
556
+ result.update(stage="capability", error=f"No provider verified {args.capability} on UE {version}")
557
+ by_role = {row["role"]: row for row in rows}
558
+ by_provider = {row["provider"]: row for row in rows if row["provider"]}
376
559
  result["task_routes"] = {}
377
560
  for capability in model["capabilities"]:
378
- provider = routing.route(model, version, capability)["selected"]
379
- row = by_provider.get(provider, {})
380
- result["task_routes"][capability] = dict(provider=provider, provider_state=row.get("state"),
561
+ row = by_role.get(capability)
562
+ provider = row["provider"] if row is not None else routing.route(model, version, capability)["selected"]
563
+ if row is None:
564
+ row = by_provider.get(provider, {})
565
+ state = row.get("state")
566
+ if state == "verified" and capability != row["role"]:
567
+ state = "connected"
568
+ result["task_routes"][capability] = dict(provider=provider, provider_state=state,
381
569
  readback_verified=(row.get("state") == "verified" and row.get("role") == capability))
382
570
  if result["playtest"]["target_plugin_declared"]:
383
571
  result["task_routes"]["playtest"] = dict(provider="unreal-agent-player",
384
572
  provider_state=result["playtest"].get("state","unverified"), preset_verified=playable)
385
- result["readiness"] = ("unavailable" if not result["ok"] else
573
+ result["readiness"] = ("transport-only" if not result["ok"] and connected else
574
+ "unavailable" if not result["ok"] else
386
575
  "partial" if any(r["state"] != "verified" for r in rows) else "ready")
387
576
  return result
388
577
 
@@ -394,11 +583,12 @@ def main():
394
583
  parser.add_argument("--project", type=Path)
395
584
  parser.add_argument("--provider", default="auto")
396
585
  parser.add_argument("--widget", help="Read a known /Game widget tree from the matched UMG instance")
586
+ parser.add_argument("--asset", help="Asset to read for --capability blueprint or animgraph")
397
587
  parser.add_argument("--client", default="codex")
398
588
  parser.add_argument("--capability", default="auto")
399
589
  parser.add_argument("--engine")
400
590
  parser.add_argument("--umg-alias", default="umg58", help="Existing Codex stdio registration for UMG")
401
- for flag in ("dry-run", "no-register", "auto-enable"):
591
+ for flag in ("dry-run", "no-register", "auto-enable", "no-install", "build-source"):
402
592
  parser.add_argument("--" + flag, action="store_true")
403
593
  args = parser.parse_args()
404
594
  if args.target and args.project:
@@ -417,7 +607,9 @@ def main():
417
607
  args.project = Path(selected)
418
608
  if args.capability == "auto" and args.provider != "auto":
419
609
  parser.error("Select --capability with an explicit provider")
420
- report = auto(args) if args.capability == "auto" else connect_one(args)
610
+ if args.asset and args.capability not in ("blueprint", "animgraph"):
611
+ parser.error("--asset requires --capability blueprint or animgraph")
612
+ report = auto(args)
421
613
  print(json.dumps(report, indent=2, ensure_ascii=False))
422
614
  return int(not report.get("ok"))
423
615