Skip to content

dse120071750/m8m-harness-builder / skills/m8m/m8m-mcp-connection-builder

m8m-mcp-connection-builder

Verified

Author reusable MCP connection context and usage guides locally, then deliver an authorized installation to the configured M8M tenant's persistent server installer. Use for new connections or explicit version changes.

scripts/m8m_deploy.py

View on GitHub
"""Local submission/status/continuation client for the durable server installer."""
import argparse
from io import BytesIO
import json
from pathlib import Path
import shlex
import subprocess
import sys
import uuid
import zipfile

sys.path.insert(0, str(Path(__file__).resolve().parent))
from m8m_delivery_common import collect, encoded, no_links, transfer_digest


def remote(target, *args, payload=None):
    argv = target["remote_entrypoint"] + list(args)
    if not isinstance(argv, list) or any(not isinstance(x, str) or "\x00" in x for x in argv):
        raise ValueError("Invalid configured server installer entry point.")
    result = subprocess.run(["ssh", "-o", "BatchMode=yes", "-o", "StrictHostKeyChecking=yes", target["ssh_alias"], shlex.join(argv)],
                            input=payload, capture_output=True, timeout=300 if payload else 60)
    if result.returncode:
        raise RuntimeError("Server installer entry failed: " + result.stderr[-4000:].decode(errors="replace"))
    return json.loads(result.stdout)


def main(argv=None):
    if hasattr(sys.stdout, "reconfigure"):
        sys.stdout.reconfigure(encoding="utf-8")
    parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog='Configured target JSON (values come from the approved server configuration):\n'
               '{"schema":"m8m.installer_target.v1","ssh_alias":"<approved alias>",\n'
               ' "tenant_id":"<canonical tenant>","environment":"<configured environment>",\n'
               ' "installation_owner":"<approved owner>",\n'
               ' "remote_entrypoint":["<trusted preconfigured tenant installer launcher>"]}\n'
               'The launcher supplies the tenant OS identity, environment and server settings.\n'
               'Target labels do not establish installation authority.')
    parser.add_argument("--target", type=Path, required=True, help="Local server alias/environment/tenant/entry-point configuration")
    commands = parser.add_subparsers(dest="command", required=True)
    submit = commands.add_parser("submit")
    submit.add_argument("--intake", type=Path, required=True)
    submit.add_argument("--brief", type=Path, required=True)
    submit.add_argument("--owner", help="Override the configured installation owner")
    submit.add_argument("--operation-id", required=True)
    submit.add_argument("--model", default="gpt-6-sol")
    submit.add_argument("--reasoning-effort", default="xhigh")
    status = commands.add_parser("status")
    status.add_argument("--operation-id", required=True)
    followup = commands.add_parser("continue")
    followup.add_argument("--operation-id", required=True)
    followup.add_argument("--message-id", required=True)
    followup.add_argument("--text", type=Path, required=True)
    args = parser.parse_args(argv)
    target = json.loads(args.target.read_bytes())
    if (not isinstance(target, dict) or not {"schema", "ssh_alias", "tenant_id", "environment", "remote_entrypoint"} <= set(target)
            or set(target) - {"schema", "ssh_alias", "tenant_id", "environment", "remote_entrypoint", "incoming_root", "installation_owner"}
            or target["schema"] != "m8m.installer_target.v1"):
        raise ValueError("Select an explicit configured server, environment and canonical tenant.")
    if (any(not isinstance(target[key], str) or not target[key] or "\x00" in target[key]
            for key in ("ssh_alias", "tenant_id", "environment"))
            or target["ssh_alias"].startswith("-")
            or not isinstance(target["remote_entrypoint"], list) or not target["remote_entrypoint"]
            or any(not isinstance(value, str) or not value or "\x00" in value for value in target["remote_entrypoint"])):
        raise ValueError("The configured target must contain an SSH alias and an argument-list entry point.")
    # The server resolves this target against its private policy. Client target
    # labels never establish tenant/application authority.
    if args.command == "status":
        result = remote(target, "status", "--operation-id", args.operation_id)
    elif args.command == "submit":
        uuid.UUID(args.operation_id)
        files = collect(args.intake)
        no_links(args.brief.absolute())
        owner = args.owner or target.get("installation_owner")
        if not isinstance(owner, str) or not owner:
            raise ValueError("Provide --owner or configure installation_owner in the target.")
        header = {"owner": owner, "client_operation_id": args.operation_id,
                  "brief": args.brief.read_text(encoding="utf-8"), "transfer_digest": transfer_digest(files),
                  "model": args.model, "reasoning_effort": args.reasoning_effort}
        archive = BytesIO()
        with zipfile.ZipFile(archive, "w", compression=zipfile.ZIP_DEFLATED) as transport:
            for name, data in files.items():
                transport.writestr(name, data)
        # SSH stdin carries the transfer directly to the authenticated server
        # entry point. It writes private staging as the installer identity.
        result = remote(target, "submit-stdin", payload=encoded(header) + b"\n" + archive.getvalue())
    else:
        uuid.UUID(args.message_id)
        no_links(args.text.absolute())
        result = remote(target, "continue-stdin", payload=encoded({"operation_id": args.operation_id,
            "client_message_id": args.message_id, "text": args.text.read_text(encoding="utf-8")}))
    if result["tenant_id"] != target["tenant_id"]:
        raise RuntimeError("The server installer receipt does not match the selected canonical tenant.")
    print(encoded(result).decode())
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall