Use Trackflow from an AI agent¶
Your agent asks the questions; Trackflow does the vision work on your machine. Trackflow detects and tracks people and objects, writes the results as tables, and serves them to the agent over MCP. The agent reads counts and rows instead of video frames: a question like "how many people came through the door between 9:00 and 10:00?" comes back as a few rows of counts. Reading the video itself would cost about 1,200 tokens per 1280×720 frame on Claude, and the model still could not tell whether the person in frame 900 is the one from frame 12.
1. Record runs¶
Every trackflow run writes a run folder the agent can query:
For a camera that runs all day, roll the output into segments so the agent can read it while Trackflow records. Keep the camera URL, which often contains a password, in an environment variable:
trackflow run "$DOOR_CAMERA_URL" --line "door=640,300,640,720" \
--roll-seconds 60 --max-segments 1440 --camera-id door
--roll-seconds 60 closes a segment every minute, and --max-segments 1440 keeps the last 24 hours on disk. Without -o, each start writes a fresh runs/run-N folder, so a restarted process never collides with the previous run (an -o folder must be empty). --camera-id door names the camera, so the runs from each restart can be told apart from other cameras' runs. Rolling runs save no annotated video and no raw person crops unless you ask for them (--save-video, --save-crops).
While it runs, the folder's status.json is rewritten about once a second. It holds whether the camera is online, how many people are in view, and the line totals since the run started, and it keeps updating while the camera sends nothing. manifest.json and status.json also record closed_through_utc: every row and event before that time is in a closed segment and won't change.
2. Connect your agent¶
The MCP server is in the [mcp] extra. Point it at the folder that holds your runs, as an absolute path.
Claude Code
Codex
Cursor (.cursor/mcp.json) and Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"trackflow": {
"command": "uvx",
"args": ["--from", "trackflow-python[mcp]", "trackflow", "mcp", "/path/to/runs"]
}
}
}
Runs on another machine. The server has to run where the run folders are. Start it over SSH:
claude mcp add trackflow -- ssh camera-box "uvx --from 'trackflow-python[mcp]' trackflow mcp /srv/trackflow/runs"
Keep the inner quotes: shells such as zsh otherwise read [mcp] as a file pattern. The server only reads run folders, so the CPU package is enough even when the runs come from trackflow-python-cuda or trackflow-python-tensorrt.
3. What the agent can ask¶
| Tool | Answers |
|---|---|
list_runs |
Which runs exist, whether each is live or finished, its camera, its privacy mode, and headline counts |
live_status |
Each camera right now: online, offline, unknown (no update for 5 s, so crashed or hung) or ended; people in view; line totals since its run started; and how its previous run ended |
query_line_counts |
In and out crossings per counting line, optionally per time bucket or within a UTC window such as 14:00 to 14:10 |
query_dwell |
Time spent and unique visitors per zone, for runs with floorplan zones (--homography or trackflow multi) |
query_sql |
Read-only DuckDB SQL over the run's tracks, events and track_cards views (plus world_tracks and camera_tracks for multi-camera runs). 200 rows by default, 2,000 at most, 5 s timeout |
search_tracks |
Natural-language search over the run's tracks, such as "person in a red jacket". Needs a run recorded with --query or --vlm |
export_clip |
Writes an MP4 of one track or a time window under <runs>/_mcp_clips and returns its path |
Questions that work well:
- "Is the door camera up, and how many people are in view?"
- "How many people crossed the door line in each 15-minute window today?"
- "Which tracks stayed in view longer than five minutes?"
- "Find the person in a red jacket and export a clip of them."
How fresh the answers are¶
Finished runs are complete. A running camera answers in two ways:
- Now:
live_statusreads the run'sstatus.json, which is about one second old. To count new crossings, read it twice and subtract the totals. Totals restart with each run, so only subtract readings with the samerun_id;previous_runholds the last run's final totals. - Exact windows:
query_line_countsand the other tools read closed segments, so they trail the camera by up to--roll-seconds. Everything beforeclosed_through_utcis final, so a window that ends at or before it returns the same counts every time. For agent setups,--roll-seconds 30keeps that lag short.
A restarted camera writes a new run folder with the same --camera-id; live_status shows the newest one.
Privacy¶
- Everything stays on your machine. The agent receives tables, counts, and search hits, not video.
query_sqlis read-only and cannot read other files, reach the network, or load extensions.export_clipblurs people by default. It writes raw video only when the server was started withtrackflow mcp --allow-raw-clipsand the run itself was not anonymized.