Econometrics with AI agents: Claude Code, Cursor and MCP¶
Short answer. Install StatsPAI, run statspai mcp config --client
claude-code (or cursor, claude-desktop, vscode, windsurf, codex) to
get the exact registration command for your client, then statspai mcp doctor
to confirm the client launches the StatsPAI you just installed. The agent can
then discover estimators, fit models on your local files and read structured
results (estimate, SE, CI, diagnostics, failed assumption checks, suggested
next steps, citations) instead of parsing printed tables. Agents that write
Python can skip MCP and call the same functions directly; AGENTS.md and
llms.txt describe how.
1. Install and register¶
The second command prints the registration line for this interpreter, e.g.
It names the interpreter by absolute path on purpose. A client that starts
the bare statspai-mcp command runs whichever environment comes first on its
PATH, which can be an old StatsPAI from another project. Then check:
doctor lists every configured client, which StatsPAI version each one
actually imports, and runs a self-test (tool listing plus one regression).
For JSON-config clients, statspai mcp config --client cursor --write edits
the file in place and keeps a timestamped backup.
2. Verify from the client¶
Ask the agent something concrete, for example: "Using the StatsPAI tools, run
2SLS of lwage on educ instrumented by nearc4 with controls exper, expersq,
black, south, smsa on /data/card.csv, and report the first-stage F." The
agent should call the ivreg tool and report an estimate of 0.132 (SE 0.049)
on the Card (1995) data. Restrict the folders the server may read with
STATSPAI_MCP_DATA_ROOTS in the client's env block; remote URLs stay off
unless you set STATSPAI_MCP_ALLOW_REMOTE=1.
3. The same thing from Python¶
Agents that write and run code use the registry directly:
import statspai as sp
hits = sp.search_functions("staggered adoption event study")
print([h["name"] for h in hits[:3]])
card = sp.describe_function("callaway_santanna") # assumptions, failure modes, alternatives
print(card["alternatives"][:3])
r = sp.ivreg("lwage ~ (educ ~ nearc4) + exper + expersq + black + south + smsa",
data=sp.datasets.card_1995())
print({k: v for k, v in r.to_dict(detail="minimal").items() if k == "n_obs"})
['event_study', 'sun_abraham', 'callaway_santanna']
['sun_abraham', 'did_imputation', 'sdid']
{'n_obs': 3010}
r.violations() lists failed assumption checks, r.next_steps() suggests
follow-ups, and r.cite() returns verified BibTeX. The
agent API guide and the
MCP workflow for economists cover the
full loop (detect design → estimate → audit → sensitivity → export).
Compatibility¶
| Client | Status on 2026-11-12 | How |
|---|---|---|
| Claude Code (VS Code extension) | tested: tools listed and ivreg called on a local CSV |
statspai mcp config --client claude-code |
| Any stdio MCP client (protocol 2025-06-18 handshake) | tested with StatsPAI 1.43.0 from PyPI in a fresh environment: initialize, tools/list (45 tools in the default profile), tools/call ivreg → 0.13229 (SE 0.04923) |
statspai-mcp or python -m statspai.agent.mcp_server |
| Claude Desktop, Cursor, Windsurf, VS Code, Codex | configuration generated by statspai mcp config; not re-tested end to end on this date |
statspai mcp config --client <name> [--write] |
The server speaks MCP revisions 2024-11-05 through 2026-07-28
(statspai-mcp --version prints them).
Ground rules for agent-run analyses¶
- Data stays local. The MCP server reads files on your machine; what the
agent sends to its model provider is the tool output, which you can keep
small with
detail="minimal". Do not point it at data you may not share with that provider. - Simulated example data is labelled. Some bundled datasets are
simulated replicas with real-study names; every frame carries
attrs["simulated"], and results on them say nothing about the real study. - Check the evidence grade.
sp.parity_status(name)tells the agent whether a function's numbers have been compared with Stata or R. An agent should say so when it uses one that has not. - Ask for the code. A good agent answer includes the calls it ran, the
StatsPAI version and the data hash (
data_provenancein every MCP result), so a person can rerun it.
Tested on 2026-11-12 (StatsPAI 1.43.0 from PyPI for the MCP checks, 1.43.1
for the Python block, which tests/test_docs_task_pages.py runs).
Report a problem.