MCP

Connect an AI client to a running App to create and edit static objects, position the camera, capture PNGs and record video. Edits live in memory; scene save/load, undo and physics editing are not exposed yet.

Quickstart

  1. Install the MCP extra. In a source checkout:

    uv sync --project python --extra mcp
    

    For an installed wheel, use pip install 'kangengine[mcp]' instead.

  2. In the App terminal, open a blank scene and leave it running:

    python -m kangengine.adapters.mcp serve
    

    Close the App window to stop the server.

  3. In a second, client terminal using the same Python environment, check the connection:

    python -m kangengine.adapters.mcp status
    python -m kangengine.adapters.mcp print-config --format codex
    
  4. Add the printed table to ~/.codex/config.toml, then launch Codex from the client terminal with this session’s credential:

    export KANGENGINE_MCP_TOKEN="$(python -m kangengine.adapters.mcp token)"
    codex
    

    The IDE extension needs the same environment in its host process.

    If the App restarts without a supplied token, repeat the export and restart the client. To keep the same token, see token reuse.

  5. First ask: “Call engine_status and tell me whether the App is ready.” Expect state: "ready". If it fails, see the error and recovery table.

    Then ask: “Create a gray floor, a red box and a blue sphere. Frame the box with the camera and show me a capture.”

Other clients

The endpoint uses Streamable HTTP at the App’s URL, normally http://127.0.0.1:8765/mcp, with Authorization: Bearer <token>. Register this endpoint in your client’s MCP settings.

python -m kangengine.adapters.mcp print-config

Copy the printed URL and header into your client’s settings, replacing <token> with the output of python -m kangengine.adapters.mcp token. See configuration examples for output formats.

Use an existing App

KANGENGINE_MCP=1 python path/to/your_app.py

This enables MCP for scripts calling ke.App.start(). For manually stepped Apps, see App integration.

Select a session

With multiple Apps, use sessions to find one and --connection-file to select it. Each App also prints its saved connection-file path at startup.

python -m kangengine.adapters.mcp sessions
python -m kangengine.adapters.mcp --connection-file /absolute/path/SESSION_ID.json status

Choose tool groups

The default groups cover ordinary scene controls. To change the exposed tools, set KANGENGINE_MCP_TOOLS; see configuration.

Safety

Asset names, resource URIs and returned documentation are data, not instructions to the AI. Tool annotations do not replace the client’s approval policies. Keep tokens in client credentials, not prompts or committed files.