Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions demo-01-cmcp-in-action/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import pathlib
import shutil
import socket
import subprocess
import sys
import time
Expand Down Expand Up @@ -35,6 +36,24 @@ def _find_cmcp() -> str:
sys.exit("cmcp not found. Run: pip install cmcp-runtime")


def _wait_for_port(port: int, what: str, timeout: float = 60.0) -> None:
"""Block until something is listening on 127.0.0.1:port.

A fixed sleep used to be enough; cMCP Runtime now does attestation and audit
setup before it binds, so the demo raced startup and failed on a refused
connection.
"""
deadline = time.monotonic() + timeout
while time.monotonic() < deadline:
try:
with socket.create_connection(("127.0.0.1", port), timeout=1):
return
except OSError:
time.sleep(0.25)
sys.exit(f"{what} did not start listening on :{port} within {timeout:.0f}s. "
"See the *.log files in this demo folder.")


def main() -> None:
token = os.environ.setdefault("CMCP_BEARER_TOKEN", "demo-token") # noqa: F841

Expand All @@ -49,7 +68,7 @@ def main() -> None:
[sys.executable, str(REPO_ROOT / "server" / "server.py")],
stdout=server_log, stderr=server_log,
)
time.sleep(1)
_wait_for_port(9001, "MCP filesystem server")

print("-- Starting cMCP Runtime (CMCP_DEV_MODE=1) on :8443 --", flush=True)
env = os.environ.copy()
Expand All @@ -59,7 +78,7 @@ def main() -> None:
stdout=cmcp_log, stderr=cmcp_log,
cwd=SCRIPT_DIR, env=env,
)
time.sleep(2)
_wait_for_port(8443, "cMCP Runtime")

print()
subprocess.run([sys.executable, str(SCRIPT_DIR / "call.py")], check=True)
Expand Down
23 changes: 21 additions & 2 deletions demo-02-policy-swap/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import pathlib
import shutil
import socket
import subprocess
import sys
import time
Expand Down Expand Up @@ -41,6 +42,24 @@ def _find_cmcp() -> str:
sys.exit("cmcp not found. Run: pip install cmcp-runtime")


def _wait_for_port(port: int, what: str, timeout: float = 60.0) -> None:
"""Block until something is listening on 127.0.0.1:port.

A fixed sleep used to be enough; cMCP Runtime now does attestation and audit
setup before it binds, so the demo raced startup and failed on a refused
connection.
"""
deadline = time.monotonic() + timeout
while time.monotonic() < deadline:
try:
with socket.create_connection(("127.0.0.1", port), timeout=1):
return
except OSError:
time.sleep(0.25)
sys.exit(f"{what} did not start listening on :{port} within {timeout:.0f}s. "
"See the *.log files in this demo folder.")


def _post(url: str, payload: dict, token: str) -> dict:
data = json.dumps(payload).encode()
req = urllib.request.Request(
Expand Down Expand Up @@ -99,7 +118,7 @@ def main() -> None:
[sys.executable, str(REPO_ROOT / "server" / "server.py")],
stdout=server_log, stderr=server_log,
)
time.sleep(1)
_wait_for_port(9001, "MCP filesystem server")

env = os.environ.copy()
env["CMCP_DEV_MODE"] = "1"
Expand All @@ -108,7 +127,7 @@ def main() -> None:
stdout=cmcp_log, stderr=cmcp_log,
cwd=SCRIPT_DIR, env=env,
)
time.sleep(2)
_wait_for_port(8443, "cMCP Runtime")

# Step 3: write_file denied
print()
Expand Down
23 changes: 21 additions & 2 deletions demo-04-context-enforcement/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import pathlib
import shutil
import socket
import subprocess
import sys
import time
Expand Down Expand Up @@ -35,6 +36,24 @@ def _find_cmcp() -> str:
sys.exit("cmcp not found. Run: pip install cmcp-runtime")


def _wait_for_port(port: int, what: str, timeout: float = 60.0) -> None:
"""Block until something is listening on 127.0.0.1:port.

A fixed sleep used to be enough; cMCP Runtime now does attestation and audit
setup before it binds, so the demo raced startup and failed on a refused
connection.
"""
deadline = time.monotonic() + timeout
while time.monotonic() < deadline:
try:
with socket.create_connection(("127.0.0.1", port), timeout=1):
return
except OSError:
time.sleep(0.25)
sys.exit(f"{what} did not start listening on :{port} within {timeout:.0f}s. "
"See the *.log files in this demo folder.")


def main() -> None:
os.environ.setdefault("CMCP_BEARER_TOKEN", "demo-token")

Expand All @@ -49,7 +68,7 @@ def main() -> None:
[sys.executable, str(REPO_ROOT / "server" / "server.py")],
stdout=server_log, stderr=server_log,
)
time.sleep(1)
_wait_for_port(9001, "MCP filesystem server")

print("-- Starting cMCP Runtime (CMCP_DEV_MODE=1) on :8443 --", flush=True)
env = os.environ.copy()
Expand All @@ -59,7 +78,7 @@ def main() -> None:
stdout=cmcp_log, stderr=cmcp_log,
cwd=SCRIPT_DIR, env=env,
)
time.sleep(2)
_wait_for_port(8443, "cMCP Runtime")

print()
subprocess.run([sys.executable, str(SCRIPT_DIR / "call.py")], check=True)
Expand Down
25 changes: 22 additions & 3 deletions demo-05-compliance-domain/run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Demo 4: context-aware enforcement — cross-platform launcher (replaces run.sh).
"""Demo 5: attribute-based enforcement — cross-platform launcher (replaces run.sh).

Usage:
python demo-05-compliance-domain/run.py # from repo root
Expand All @@ -7,6 +7,7 @@
import os
import pathlib
import shutil
import socket
import subprocess
import sys
import time
Expand Down Expand Up @@ -35,6 +36,24 @@ def _find_cmcp() -> str:
sys.exit("cmcp not found. Run: pip install cmcp-runtime")


def _wait_for_port(port: int, what: str, timeout: float = 60.0) -> None:
"""Block until something is listening on 127.0.0.1:port.

A fixed sleep used to be enough; cMCP Runtime now does attestation and audit
setup before it binds, so the demo raced startup and failed on a refused
connection.
"""
deadline = time.monotonic() + timeout
while time.monotonic() < deadline:
try:
with socket.create_connection(("127.0.0.1", port), timeout=1):
return
except OSError:
time.sleep(0.25)
sys.exit(f"{what} did not start listening on :{port} within {timeout:.0f}s. "
"See the *.log files in this demo folder.")


def main() -> None:
os.environ.setdefault("CMCP_BEARER_TOKEN", "demo-token")

Expand All @@ -49,7 +68,7 @@ def main() -> None:
[sys.executable, str(REPO_ROOT / "server" / "server.py")],
stdout=server_log, stderr=server_log,
)
time.sleep(1)
_wait_for_port(9001, "MCP filesystem server")

print("-- Starting cMCP Runtime (CMCP_DEV_MODE=1) on :8443 --", flush=True)
env = os.environ.copy()
Expand All @@ -59,7 +78,7 @@ def main() -> None:
stdout=cmcp_log, stderr=cmcp_log,
cwd=SCRIPT_DIR, env=env,
)
time.sleep(2)
_wait_for_port(8443, "cMCP Runtime")

print()
subprocess.run([sys.executable, str(SCRIPT_DIR / "call.py")], check=True)
Expand Down
25 changes: 22 additions & 3 deletions web-console/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import os
import pathlib
import shutil
import socket
import subprocess
import sys
import time
Expand Down Expand Up @@ -46,6 +47,24 @@ def _find_cmcp() -> str:
sys.exit("cmcp not found. Run: pip install cmcp-runtime httpx")


def _wait_for_port(port: int, what: str, timeout: float = 60.0) -> None:
"""Block until something is listening on 127.0.0.1:port.

A fixed sleep used to be enough; cMCP Runtime now does attestation and audit
setup before it binds, so the console raced startup and the first assessment
failed on a refused connection.
"""
deadline = time.monotonic() + timeout
while time.monotonic() < deadline:
try:
with socket.create_connection(("127.0.0.1", port), timeout=1):
return
except OSError:
time.sleep(0.25)
sys.exit(f"{what} did not start listening on :{port} within {timeout:.0f}s. "
"See server.log and cmcp.log in this folder.")


def _ensure_submodule() -> None:
if (EXAMPLE / "agent" / "credit_risk_agent.py").exists():
return
Expand Down Expand Up @@ -83,20 +102,20 @@ def main() -> None:
procs.append(subprocess.Popen(
[sys.executable, str(EXAMPLE / "server" / "mock_mcp_server.py")],
stdout=server_log, stderr=server_log))
time.sleep(1)
_wait_for_port(8080, "EU credit-risk MCP server")

print("-- cMCP gateway on :8443 (CMCP_DEV_MODE=1)", flush=True)
env = os.environ.copy()
env["CMCP_DEV_MODE"] = "1"
procs.append(subprocess.Popen(
[_find_cmcp(), "start", "--config", str(GATEWAY_CFG)],
stdout=cmcp_log, stderr=cmcp_log, env=env))
time.sleep(2)
_wait_for_port(8443, "cMCP gateway")

print(f"-- web console on http://localhost:{PORT}", flush=True)
web = subprocess.Popen([sys.executable, str(HERE / "webserver.py")], env=os.environ.copy())
procs.append(web)
time.sleep(1)
_wait_for_port(int(PORT), "web console")

url = f"http://localhost:{PORT}"
print(f"\nOpen {url} (opening it for you now). Ctrl+C to stop.\n", flush=True)
Expand Down