Spartan Engine MCP

repository·master·Indexed 25 days ago

https://github.com/panosk92/spartanengine

A Node adapter and TCP bridge providing engine-aware tools to MCP clients like Cursor. It enables AI agents to inspect, manipulate, and automate tasks within the Spartan engine, including scene editing, resource management, and debugging. The package includes support for read-only mode, agent memory management via AGENT_MEMORY.md, and access to stable engine resources such as component schemas and console logs.

Tokens
9.5K
Snippets
6
Records
75
Agent score
83%

What's inside spartan-engine-mcp

  1. Manage Agent Memory with AGENT_MEMORY.md

    master

    The MCP server manages a curated markdown file named AGENT_MEMORY.md to provide durable context for future agent runs. Use agent_memory_append to add information to this file.

    Use cases for memory:

    • Engine facts learned from previous runs.
    • Successful strategies and known gotchas.
    • Advice for future agents or maintainers (e.g., reporting missing tools or architecture problems).
    • Problem reports for recurring friction.

    Best Practices:

    • Do not use it as a chat transcript.
    • Keep notes short and replace stale entries.
    • Avoid duplicate bullets.
  2. Set up Spartan Engine MCP in Cursor

    master

    To use Spartan Engine tools within Cursor, add the spartan_engine server to your Cursor MCP settings. You must ensure the MCP bridge is enabled in Spartan or the Spartan AI widget is open before starting the server. You can override default connection settings using --host, --port, or --timeout-ms flags.

    {
      "mcpServers": {
        "spartan_engine": {
          "type": "stdio",
          "command": "node",
          "args": [
            "C:/Users/panos/Desktop/spartan_engine/tools/mcp/spartan_engine/server.mjs"
          ],
          "cwd": "C:/Users/panos/Desktop/spartan_engine/tools/mcp/spartan_engine"
        }
      }
    }
  3. Validate a Car Preset

    master

    To validate a car preset, define a <validation> section in the .car file containing public evidence envelopes (e.g., zero_to_100_min, braking_distance_max, skidpad_g_min).

    Steps to run validation:

    1. Open a flat vehicle test world.
    2. Use the Run validation command in the telemetry window.
    3. Review the results in the generated car_validation_report.csv file.

    A preset is considered acceptable when it loads without validation errors and passes the following scenarios: settle acceleration, braking, coastdown, skidpad, step steer, and slalom.

  4. Create emissive white surfaces

    master

    To create a surface that appears emissive white, follow these steps using the material and component APIs:

    1. Create a material using material_create (this defaults to white albedo).
    2. Set the emissive_from_albedo property to 1 using material_set_property.
    3. Assign the material to the render component of an entity using the material property via component_set.

    The albedo color of the material will drive the color of the emission.

  5. Define a Car Preset (.car file) contract

    master
    A .car file contains data for shared vehicle assembly and simulation. When creating a new car, ensure you only provide data and do not add car-specific code. The file structure is divided into measured inputs, physical model inputs, engine acoustics, accessibility settings, and validation targets.
  6. Drive and inspect vehicles in play mode

    master

    To test or inspect a vehicle, follow this workflow:

    1. Set engine mode to play: engine_set_mode(mode='play').
    2. Enter the vehicle: vehicle_enter (requires MCP pedal ownership).
    3. Provide input: Hold vehicle_set_input for a duration.
    4. Inspect telemetry: Use vehicle_telemetry to view data (output is car_telemetry.csv in the working directory, not an Excel file).

    Available Vehicle Tools:

    • vehicle_list / vehicle_get
    • vehicle_set_input / vehicle_shift
    • vehicle_set_view / vehicle_reset / vehicle_exit
  7. Best practices for agent engine interaction

    master

    Follow these strategies when interacting with the Spartan Engine via MCP:

    • Initialization: Start tasks with spartan_status or context_snapshot to understand the current state.
    • Error Recovery: Use debug_log_read after a failure to inspect actual command inputs/outputs.
    • Discovery: Use search_capabilities and get_capability_details before attempting to use a tool.
    • Targeting: Always resolve targets with entity_resolve before mutating named or selected entities.
    • Batching: Use component_set_batch for multiple property edits on one component, and entity_set_transform_batch for repositioning many entities.
    • Visual Verification: Use screenshot_take when visual confirmation is required; it returns the saved PNG as image content.
  8. Configure Spartan MCP in Read-Only Mode

    master

    Use read-only mode when an agent needs to inspect the engine or source code without the ability to mutate the scene. In this mode, mutating tools are not registered by server.mjs. You can enable this via CLI arguments or environment variables.

    CLI Argument: Add --read-only to the args array in your MCP configuration.

    Environment Variables:

    • SPARTAN_MCP_READ_ONLY=1 (for server.mjs)
    • SPARTAN_ASSISTANT_READ_ONLY=1 (for assistant.mjs)
    {
      "mcpServers": {
        "spartan_engine": {
          "type": "stdio",
          "command": "node",
          "args": [
            "C:/Users/panos/Desktop/spartan_engine/tools/mcp/spartan_engine/server.mjs",
            "--read-only"
          ],
          "cwd": "C:/Users/panos/Desktop/spartan_engine/tools/mcp/spartan_engine"
        }
      }
    }
  9. Run the Spartan Engine MCP Server

    master

    The Spartan Engine MCP server can be executed via CLI to provide Model Context Protocol (MCP) capabilities to agents. You can configure the connection to the underlying engine using environment variables or command-line flags.

    Configuration Options

    FlagEnvironment VariableDefaultDescription
    --host=SPARTAN_ENGINE_HOST127.0.0.1The host address of the engine
    --port=SPARTAN_ENGINE_PORT47777The port of the engine
    --timeout-ms=SPARTAN_ENGINE_TOOL_TIMEOUT_MS30000Tool execution timeout in milliseconds
    --http-port=SPARTAN_MCP_HTTP_PORT8765Port for HTTP transport if enabled
    --read-onlySPARTAN_MCP_READ_ONLYfalseEnables read-only mode (accepts 1, true, yes, on)

    Transport Modes

    • stdio: The default mode. Enabled unless --no-stdio is passed and transport is set to http.
    • http: Enabled via --http or by specifying a --http-port=.
  10. Troubleshoot Spartan MCP Errors

    master

    Common error resolutions for the Spartan Engine MCP:

    • engine_timeout: Retry the operation once. If it fails again, reduce the operation size or switch to a batch/Lua path.
    • edit_mode_required: Switch the engine to edit mode before attempting mutations.
    • Assistant fails to start: Ensure Node.js is in your PATH and run npm install in the tools/mcp/spartan_engine directory.
    • Port binding failure: Check if another Spartan instance or a stale bridge process is already running.
    • Stale source search: The index refreshes on search, but you can restart the MCP server for a full rebuild.