Skip to main content
Glama
apitrace-mcp

apitrace-mcp

by phunkaeg

apitrace-mcp

An MCP server wrapping apitrace, aimed at reverse-engineering older games: DirectDraw/D3D7, D3D8, D3D9 and legacy OpenGL — the APIs RenderDoc will not open.

It is not a thin CLI wrapper. On top of capture and replay it adds an analysis layer that answers the questions that actually come up when you are trying to understand an old renderer:

  • Where is the camera? find_matrices scans candidate 4×4 matrices the game hands the driver — fixed-function SetTransform, glLoadMatrixf, shader constants, and resource-qualified uniform/constant-buffer uploads — and ranks likely projection, view, and combined view-projection slots. Legacy OpenGL matrix stacks are reconstructed per context when make-current calls identify it, with a conservative per-trace-thread fallback when they do not.

  • What is the FOV, near and far? decode_matrix / find_matrices decode them, in both D3D and OpenGL conventions, and in both storage orders (D3D9 shader constants usually hold the transpose).

  • Is that really the view matrix? track_camera extracts the world-space eye and view-Z axis per frame. It reports both handedness-dependent forward-vector candidates, so the trace is not made to claim an orientation it cannot prove.

  • Which register would a VR patch rewrite? Matrix slots are reported as register ranges — vs_c[8..11] — not just call numbers. Both float4x4 (4-register) and float4x3 (3-register) uploads are recognised, and windows are only taken at whole-matrix offsets from the upload that wrote them, so a large packed bone-matrix block does not bury the camera in overlapping candidates.

Validated against a real Direct3D 9 / Unreal Engine 3 capture: from a 786-frame Dishonored trace it recovers the float4x3 view matrix (world-space eye, cross-checked against the camera-position constant the engine uploads separately) and the projection scales giving 58.08° vertical / 89.25° horizontal FOV at 16:9.

Why apitrace and not RenderDoc

RenderDoc captures D3D11/12, OpenGL (modern) and Vulkan. It cannot capture D3D9, D3D8, DirectDraw, or the legacy GL that pre-2010 games use. apitrace can, and it records the full API call stream with argument values rather than a single frame.

apitrace

RenderDoc

DirectDraw / D3D7

trace only

no

D3D8 / D3D9

trace + replay/inspect

no

Legacy OpenGL (1.x–2.x, ARB programs)

yes

no

D3D11, modern GL, Vulkan

yes (D3D11/GL)

yes, and better

D3D12

no

yes

Captures

whole run, all frames

one frame

Per-draw pipeline state

via replay (dump_state)

first-class

Use both: apitrace for old APIs and whole-run call streams, RenderDoc for modern APIs and deep single-frame inspection.

Related MCP server: Universal Game Modder

Requirements

  • An unpacked apitrace release. The server auto-discovers builds unpacked next to this clone (inside it, or in a sibling directory such as ..\apitrace\) plus the standard locations (C:\apitrace, Program Files, ~\apitrace), or set APITRACE_MCP_ROOT_WIN64 / APITRACE_MCP_ROOT_WIN32 explicitly.

  • Both the win64 and the win32 build if you trace 32-bit games. A win64 apitrace cannot trace a 32-bit process — the wrapper DLL has to load into the target's address space. Most pre-2012 games are 32-bit.

  • Windows and Python 3.11+. Core tools need only the MCP SDK; diff_images additionally needs Pillow because upstream snapdiff.py imports PIL: uv pip install -e ".[images]".

APITRACE_MCP_TRACE_DIR sets where traces, logs and extracted files go (default %LOCALAPPDATA%\apitrace-mcp\traces). Traces are large — point this at a drive with room.

Install

uv venv --python 3.13
uv pip install -e .

Register it (Claude Code, from the clone directory):

claude mcp add apitrace -e APITRACE_MCP_TRACE_DIR=<where-traces-should-go> -- "<path-to-clone>/.venv/Scripts/apitrace-mcp.exe"

Or add to claude_desktop_config.json / .claude.json:

"apitrace": {
  "command": "<path-to-clone>\\.venv\\Scripts\\apitrace-mcp.exe",
  "args": [],
  "env": { "APITRACE_MCP_TRACE_DIR": "<where-traces-should-go>" }
}

(The env block is optional — without it traces land in %LOCALAPPDATA%\apitrace-mcp\traces.)

python register.py can register the editable install with Claude Desktop and Codex after backing up their configuration files.

Tools

Environment — apitrace_status (preflight), list_traces, detect_target

Capture — trace_launch, trace_status, trace_stop, list_sessions, install_wrapper, uninstall_wrapper

Inspect — trace_info, list_frames, dump_calls, get_calls, search_calls, call_histogram, frame_summary

Analyse — find_matrices, decode_matrix, track_camera, list_shaders, extract_blobs

Replay — dump_state, dump_images, replay_trace

Maintain — trim_trace (raw slice), gltrim_trace (replayable GL subset), leak_report, repack_trace, sed_trace (stream edit into a new trace)

Compare — diff_traces (semantic call streams), diff_state (complete retracer state at two calls), diff_images (HTML image report and sidecars)

Most read tools take apitrace's callset syntax in calls=: 42, 0,2,4, 100-2000, 0-1000/2, 0-1000/draw, 0-1000/fbo, frame, @file.txt.

Typical session

apitrace_status()                                  # which builds are installed
detect_target("D:/Games/Foo/Foo.exe")              # 32-bit? D3D9? 
trace_launch(game_exe=..., api="d3d9")             # play the scene
trace_stop("trace-1")
list_frames(trace)                                 # find a frame's call range
find_matrices(trace, calls="120000-125000")        # projection / view / viewproj
track_camera(trace, calls="100000-200000")         # confirm the eye moves
small = gltrim_trace(trace, frames="40-42")        # replayable GL subset
dump_images(small["output"], calls="*/draw")       # see what each draw contributes

Then take the finding into Ghidra (find the code that writes that matrix) or ReGenny (rebuild the struct it lives in).

Notes and limits

  • Tracing is invasive and slow. Old games can drop to single-digit FPS under a wrapper. Capture a few seconds, not a level.

  • Quit the game normally before trace_stop. A forced kill can lose the tail of the trace.

  • Empty trace? Usually launcher indirection — the exe you launched spawned the real game, so the injection landed in the wrong process. Use install_wrapper and start the game yourself (this also works for Steam).

  • install_wrapper backs up existing DLLs. ENB, ReShade, dgVoodoo and DXVK all install as d3d9.dll/dxgi.dll/opengl32.dll. Existing files are backed up and restored on uninstall_wrapper — but those mods are inactive while the apitrace wrapper is in place. Its generated launcher refuses to overwrite an earlier capture; uninstall and reinstall to allocate a fresh default trace. Always uninstall when done.

  • D3D10/11 must use trace_launch, not install_wrapper: those DLLs load each other by name, so a DLL drop traces the wrong calls. apitrace's injector handles it.

  • D3D12 and Vulkan are not supported by apitrace at all — use RenderDoc.

  • Traces are untrusted binary input. The pickle reader is restricted to apitrace's own Pointer class and runs in a disposable decoder worker with a 512 MiB memory limit, wall-clock timeout, and length-framed output. Per-call decoding is capped at 1,000,000 value nodes, depth 64, 4,000,000 floats, 48 MiB of blobs, and a 64 MiB return frame. An individual call whose payload exceeds those limits is rejected rather than returned or extracted; narrow calls= when a trace contains unusually large resource uploads. A plain pickle.load on a hostile trace would be an arbitrary-code-execution hole.

  • trim_trace is a raw slice. For a replayable mid-run OpenGL subset, use gltrim_trace, which preserves setup state. DirectDraw/D3D7 captures cannot be replayed upstream.

  • diff_images writes thumbnails and diff PNGs beside its input prefixes. The MCP wrapper never enables upstream overwrite mode and rejects existing or concurrently reserved sidecars; use fresh image prefixes for each comparison.

  • Generated file outputs are UUID-backed. The actual path is returned in the structured result, and an existing requested path is never overwritten. This remains safe when Claude and Codex use separate MCP server processes.

  • diff_state accepts a trace and two call numbers. It captures complete retracer JSON at both calls, canonicalises apitrace's JSON dialect, then runs upstream jsondiff; it does not require hand-created state files.

  • Tools return native structured MCP data, advertise read/write/destructive annotations, and report operational failures through the MCP error channel.

  • Cancelling an MCP request cannot yet interrupt a synchronous apitrace command already running in a worker thread. Foreground work is limited to two commands, remains bounded by each tool's timeout, and timeout cleanup terminates the complete child-process tree.

Tests

The suite uses the standard library and needs no test dependency:

.venv/Scripts/python -m unittest discover -s tests -v

For pytest-based development tooling, install the optional extra with uv pip install -e ".[dev]".

Available Tools

32 tools
apitrace_statusA
Read-onlyIdempotent

Preflight: which apitrace builds are installed, where traces go, what is running.

Call this before anything else. Unlike the GUI-backed RE servers, apitrace needs no host application running -- but it does need the build whose bitness matches the game you intend to trace.

Inputs: no named parameters. Returns: object

call_histogramB
Read-onlyIdempotent

Function-frequency profile over a call range -- the fastest way to see what a game does.

Scanning the whole of a large trace is slow; limit caps how many calls are read (default 200k).

Inputs: trace (required), top, calls, limit. Returns: object

decode_matrixA
Read-onlyIdempotent

Decode 16 floats as a 4x4 matrix: FOV, near/far, handedness, camera position.

Accepts whitespace-, comma- or newline-separated numbers -- paste them straight out of a memory dump, a Cheat Engine watch, or a shader constant. Both storage orders are tried, so you do not need to know whether the source was row- or column-major.

Inputs: values (required), label. Returns: object

detect_targetA
Read-onlyIdempotent

Inspect a game executable: bitness, graphics API, and how to trace it.

Reads the PE import table, so it answers "is this D3D8 or D3D9, and is it 32-bit" without launching anything. Delay-loaded imports are included -- older games often delay-load d3d9 behind a video-detection step.

Inputs: game_exe (required). Returns: object

diff_imagesA

Compare image sets and create an HTML report plus new diff/thumbnail sidecars.

Upstream writes sidecars beside the source prefixes. This wrapper refuses to run if any potential sidecar already exists and never enables --overwrite.

Inputs: source_prefix (required), reference_prefix (required), fuzz, alpha, +6 more. Returns: object

diff_stateB
Read-onlyIdempotent

Capture and compare complete retracer state at two calls.

Inputs: trace (required), source_call (required), reference_call (required), api, +7 more. Returns: object

diff_tracesA
Read-onlyIdempotent

Compare two traces with apitrace's semantic call-stream differ.

Inputs: source_trace (required), reference_trace (required), tool, calls, +8 more. Returns: object

dump_callsA
Read-onlyIdempotent

Human-readable call dump, exactly as apitrace dump writes it. Good for eyeballing a stretch of a frame; use get_calls for numeric arguments. Calls: apitrace callset syntax: '42' one call, '0,2,4' a set, '100-2000' a range, '0-1000/2' every 2nd, '0-1000/draw' draw calls only, '0-1000/fbo' render-target changes, 'frame' the end-of-frame calls, '@file.txt' read from a file.

Inputs: trace (required), grep, calls, timeout, +1 more. Returns: object

dump_imagesB

Replay the trace and write PNG images (per frame, or per specified call).

Useful for finding which draw call produces the HUD, the world, or the problem you are chasing -- dump images at every draw in a frame and look.

Inputs: trace (required), mrt, calls, timeout, +1 more. Returns: object

dump_stateA
Read-onlyIdempotent

Replay up to a call and dump the full pipeline/device state as JSON.

The apitrace equivalent of RenderDoc's pipeline view for OpenGL and D3D8/D3D9. DirectDraw and D3D7 traces are capture-only upstream and cannot be replayed for state inspection.

Replay has to run the trace on this machine's GPU up to that call, so it is slow and it can fail on very old games whose resources the driver no longer likes. If it fails, trim_trace to a short range first.

Inputs: call (required), trace (required), api, timeout. Returns: object

extract_blobsA

Write binary arguments (shader bytecode, vertex/index/constant buffers) to files.

Scope tightly with calls -- buffer uploads are large and there are many. The scan walks at most max(limit*500, 20000) calls of the callset, so blobs beyond that walk cap are not found; narrow calls if the result looks short.

Inputs: calls (required), trace (required), limit, out_dir. Returns: object

find_matricesA
Read-onlyIdempotent

Find and classify every 4x4 matrix the game sends to the driver.

This is the core VR/camera-hacking tool. It covers:

  • fixed-function transforms -- SetTransform(D3DTS_VIEW/PROJECTION/WORLD), glLoadMatrixf/glMultMatrixf, glFrustum/glOrtho;

  • shader constants -- SetVertexShaderConstantF and friends, tracked through a shadow register file so matrices uploaded piecemeal still resolve, and reported as the register range that holds them (e.g. vs_c[8..11]);

  • uniform/constant buffer uploads -- glBufferData, UpdateSubresource and the memcpy calls apitrace records for writes to mapped memory, reported as a byte offset into the buffer (set scan_buffers=false to skip);

  • both storage orders, since D3D9 shader constants usually hold the transpose.

Results are grouped by slot. Read them as: kind=projection -> the game's FOV, near and far planes kind=rigid + changes_per_frame -> camera candidate; confirm with track_camera kind=viewproj in vs_c[...] -> the register range a VR patch rewrites kind=viewproj at a buffer offset -> the bytes a VR patch rewrites kind=ortho -> HUD/UI or shadow pass

Scope with calls (a single frame is usually enough and far faster).

Inputs: trace (required), calls, kinds, limit, +3 more. Returns: object

frame_summaryA
Read-onlyIdempotent

Break a frame down: draw calls, render-target switches, shader binds.

Pass a callset covering one frame, e.g. calls='120000-125000'. Use trace_info(per_frame=True) or list_frames to find the boundaries.

Inputs: calls (required), trace (required), limit. Returns: object

get_callsA
Read-onlyIdempotent

Structured calls with real argument values via apitrace pickle. Long arrays and blobs are summarized. Calls: apitrace callset syntax: '42' one call, '0,2,4' a set, '100-2000' a range, '0-1000/2' every 2nd, '0-1000/draw' draw calls only, '0-1000/fbo' render-target changes, 'frame' the end-of-frame calls, '@file.txt' read from a file.

Inputs: trace (required), calls, limit, max_list, +1 more. Returns: object

gltrim_traceC

OpenGL-specific frame trim that preserves replay setup state.

Inputs: trace (required), frames (required), output, timeout, +4 more. Returns: object

install_wrapperA
Destructive

Drop apitrace's wrapper DLL next to a game exe (the manual tracing route).

Use this when trace_launch produces nothing -- typically because the exe you launched is a launcher that spawns the real game, or the game re-launches itself for DRM. The wrapper then loads whenever the game starts, however it was started (including from Steam).

Any existing DLL of the same name -- ENB, ReShade, dgVoodoo, DXVK all use these filenames -- is backed up and restored by uninstall_wrapper. Always uninstall when you are done; a left-behind wrapper keeps tracing every run.

Inputs: game_exe (required), api, force, trace_file. Returns: object

leak_reportA
Read-onlyIdempotent

Run apitrace's object-leak checker against a trace.

Inputs: trace (required), timeout, max_bytes. Returns: object

list_framesB
Read-onlyIdempotent

Frame boundaries as call numbers, so you can scope other queries to one frame.

Inputs: trace (required), count, start. Returns: object

list_sessionsA
Read-onlyIdempotent

All trace/replay sessions, including any still running from a previous server run.

Inputs: no named parameters. Returns: object

list_shadersB
Read-onlyIdempotent

List shader creation calls with a source preview or bytecode size.

Use extract_blobs to write D3D shader bytecode out for disassembly.

Inputs: trace (required), calls, limit, max_shaders. Returns: object

list_tracesA
Read-onlyIdempotent

List trace files in the trace directory.

Inputs: no named parameters. Returns: object

repack_traceC

Repack a trace with Snappy, Brotli, Zstandard, or zlib compression.

Inputs: trace (required), output, quality, timeout, +1 more. Returns: object

replay_traceB

Replay a trace in the background (session-based). Returns a session id.

profile: '', 'cpu', 'gpu', 'frames', 'pixels', 'memory', 'calls', 'frame_metrics', or 'draw_metrics'. Profiling output lands in the session log -- poll it with trace_status.

Inputs: trace (required), api, profile, headless, +1 more. Returns: object

search_callsA
Read-onlyIdempotent

Regex search over function names across the trace; returns counts and call numbers.

The cheapest way to find out whether a game uses fixed-function transforms or shader constants: search 'SetTransform|SetVertexShaderConstant'.

Inputs: trace (required), pattern (required), calls, timeout, +1 more. Returns: object

sed_traceC

Stream-edit trace enum/string symbols or trace properties into a new trace.

Inputs: trace (required), calls, output, timeout, +3 more. Returns: object

trace_infoB
Read-onlyIdempotent

Summary of a trace file: API, call count, frame count (JSON from apitrace info).

Inputs: trace (required), per_frame. Returns: object

trace_launchA

Launch a game under apitrace and start capturing. Returns a session id.

This runs the game -- it does not block. Let the user play the part they want captured, then call trace_stop (ideally after they quit the game normally, so the trace is flushed cleanly).

api: gl, d3d7, d3d8, d3d9, or dxgi (D3D10/11). Empty auto-detects from the PE. method: 'iat' (default) or 'mhook'. Try mhook when a game loads the graphics DLL dynamically and IAT patching misses it.

Inputs: game_exe (required), api, args, method, +2 more. Returns: object

trace_statusA
Read-onlyIdempotent

Poll a trace or replay session: still running, trace size so far, log tail.

Inputs: session (required). Returns: object

trace_stopA
Destructive

Stop a session and report the resulting trace.

Prefer quitting the game in-game first: a forced kill can lose the tail of the trace because apitrace never gets to flush.

Inputs: session (required), force. Returns: object

track_cameraA
Read-onlyIdempotent

Follow the camera across frames: world position, forward vector and FOV.

Picks the most view-like matrix slot automatically, or pass source with a slot name from find_matrices. If the eye position changes as the player moved during the capture, you have found the real view matrix -- that is the confirmation step before taking the offset into Ghidra or ReGenny.

Inputs: trace (required), calls, limit, source, +1 more. Returns: object

trim_traceA

Make a raw call/frame slice of a trace.

A slice beginning at call/frame zero often remains replayable and makes every downstream tool faster. A mid-run OpenGL slice can omit setup/resources; use gltrim_trace when replayability matters.

Inputs: trace (required), calls, frames, output. Returns: object

uninstall_wrapperB
Destructive

Remove wrapper DLLs installed by install_wrapper and restore any backups.

Inputs: game_exe_or_dir (required). Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 32 tools

    Disambiguation5/5

    Every tool targets a distinct operation: capture, replay, status, session listing, call dumping, call searching, histogramming, frame analysis, matrix finding, state dumps, and diffing are all cleanly separated. Even close neighbors like dump_calls/get_calls and diff_traces/diff_state are explicitly differentiated by their descriptions.

    Naming Consistency4/5

    The set predominantly follows snake_case verb_noun naming, e.g., list_traces, replay_trace, trace_stop, dump_state, extract_blobs, trim_trace. Minor deviations like apitrace_status, call_histogram, frame_summary, leak_report, and sed_trace break the pattern but remain readable and predictable.

    Tool Count2/5

    32 tools is a heavy surface for an agent to reason over, and several could plausibly be consolidated, such as trace_status/list_sessions, list_frames/frame_summary, and trim_trace/gltrim_trace. While the tool count reflects the breadth of apitrace, it exceeds the practical range for a coherent MCP server.

    Completeness5/5

    The toolset covers the full apitrace workflow: preflight checks, capture methods, session control, replay, inspection, frame and matrix analysis, shader/blob extraction, state dumping, trimming, compression, leak detection, and diffing. There are no obvious dead ends—install_wrapper has uninstall_wrapper, trace_launch has trace_stop, and replay_trace has trace_status.

    Maintenance

    ActivityInactive
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      C
      quality
      C
      maintenance
      Enables an AI agent to auto-detect a game's engine (Unity, Unreal, Godot, Java, or native) from its files and then inspect, search, and patch the underlying binaries with in-process PE analysis, hex editing, pattern scanning, string extraction, checksums, diffing, and disassembly. Everything runs locally and offline with no cloud dependency or telemetry.
      100
      56 npm
      5
      MIT
    • A
      license
      B
      quality
      C
      maintenance
      Enables agents to explore a static RTTI, call, and cross-reference graph of a game executable, querying functions, classes, vtables, strings, globals and memory through search, disassembly, signature and SQL tools. It also supports a provenance-tracked naming lifecycle where labels are proposed with evidence, reviewed, and ported across game patches.
      18
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Gives MCP clients tools to inspect RenderDoc .rdc captures — listing and opening frames, querying draws, pipelines, shaders, bindings, textures, buffers and pixel history, reading GPU performance counters, and exporting buffer, texture, mesh, draw-call and Unity import packages. Multiple clients can share one local GUI or headless playback backend on Windows.
      2
      MIT