Skip to content

cosmotron_mcp.replay

generate_replay_script

generate_replay_script(session_dir: str, output_name: str | None = None) -> dict

Generate a self-contained Python replay script from this session's tool-call log.

Reads {session_dir}/tool_call_log.jsonl (written automatically as pipeline tools execute) and emits a Python script that calls the same cosmotron_mcp.tools functions in order — no MCP server required, run from the repo root with python workspace/.../scripts/replay_YYYY-MM-DD.py.

This is a HUMAN reproducibility artefact, generated for someone to run outside of an agent session. No agent ever executes it or invokes python via bash to run it — that is exactly the raw-script escape hatch every other tool in this server closes (run_analysis_script rejects it outright). Calling this tool only writes the file; agents' own work continues through the MCP tools as normal.

If the log does not yet exist (session predates this feature), falls back to a best-effort reconstruction from artefact_registry.json.

Parameters:

Name Type Description Default
session_dir str

Session workspace directory.

required
output_name str | None

Override the output filename (default: replay_YYYY-MM-DD.py).

None

Returns:

Type Description
dict

dict with keys: script_path, n_steps, source

dict

("tool_call_log" or "artefact_registry"), status.

Source code in cosmotron_mcp/server.py
@mcp.tool()
@sync_budget_guard
def generate_replay_script(
    session_dir: str, output_name: str | None = None
) -> dict:
    """Generate a self-contained Python replay script from this session's tool-call log.

    Reads {session_dir}/tool_call_log.jsonl (written automatically as pipeline
    tools execute) and emits a Python script that calls the same
    cosmotron_mcp.tools functions in order — no MCP server required, run from
    the repo root with ``python workspace/.../scripts/replay_YYYY-MM-DD.py``.

    This is a HUMAN reproducibility artefact, generated for someone to run
    outside of an agent session. No agent ever executes it or invokes
    `python` via bash to run it — that is exactly the raw-script escape hatch
    every other tool in this server closes (`run_analysis_script` rejects
    it outright). Calling this tool only writes the file; agents' own work
    continues through the MCP tools as normal.

    If the log does not yet exist (session predates this feature), falls back to
    a best-effort reconstruction from artefact_registry.json.

    Args:
        session_dir: Session workspace directory.
        output_name: Override the output filename (default:
            ``replay_YYYY-MM-DD.py``).

    Returns:
        ``dict`` with keys: ``script_path``, ``n_steps``, ``source``
        (``"tool_call_log"`` or ``"artefact_registry"``), ``status``.
    """
    return _generate_replay_script(session_dir, output_name=output_name)