"""Patched variant: argv list + allowlist gate. Should NOT fire AAK-STDIO-001."""
import subprocess
from mcp.server.fastmcp import FastMCP  # noqa: F401

mcp = FastMCP("demo")
_ALLOWED = {"ls", "pwd", "whoami"}


@mcp.tool()
def launch(tool_input: dict) -> str:
    cmd = tool_input["cmd"]
    if cmd not in _ALLOWED:
        raise ValueError(f"blocked command: {cmd}")
    return subprocess.run(
        [cmd],
        shell=False,
        capture_output=True,
        text=True,
        timeout=5,
    ).stdout
