stata-copilot
Server Configuration
Describes the environment variables required to run the server.
| Name | Required | Description | Default |
|---|---|---|---|
| STATA_COPILOT_LOG | No | Log level for stderr output. | info |
| STATA_COPILOT_MODE | No | Safety mode: open, guarded, or readonly. | guarded |
| STATA_COPILOT_ROOTS | No | Path-separator separated working-directory allow-list. No cwd restriction when unset. | |
| STATA_COPILOT_DRIVER | No | Driver selection: auto picks pystata when Stata and Python are found, else http. | auto |
| STATA_COPILOT_PYTHON | No | Python interpreter that can import pystata. Defaults to python on PATH. | |
| STATA_COPILOT_EDITION | No | Stata edition: mp, se, or be. | mp |
| STATA_COPILOT_TIMEOUT | No | Per-call timeout in seconds. | 120 |
| STATA_COPILOT_ENDPOINT | No | Endpoint for the optional HTTP driver. | http://127.0.0.1:19522 |
| STATA_COPILOT_NO_LEDGER | No | Disable the run ledger. Ledger is on by default. | |
| STATA_COPILOT_STATA_EXE | No | Stata executable used by background jobs. | D:\StataMP-64.exe |
| STATA_COPILOT_MAX_OUTPUT | No | Maximum number of transcript characters returned. | 20000 |
| STATA_COPILOT_STATA_HOME | No | The folder holding mp-64.dll (e.g. D:/). Auto-detected when not set. | |
| STATA_COPILOT_JOB_TIMEOUT | No | Timeout in seconds per background job. | 1800 |
Instructions
Guidance the server publishes about itself, which clients place ahead of the tool catalog so the model reads it before choosing anything.
Stata analysis over MCP.
Call stata_status first; it tells you whether Stata is reachable and ready.
Prefer stata_run_do over stata_run for anything longer than a couple of lines: write a numbered .do file, run it, keep it.
Use stata_model for regressions; it returns b/se/t/p per term instead of a transcript to read.
Use stata_profile_data before modelling to learn types, labels and missingness.
Call stata_graphs after a run that exported a PNG: the image comes back as an attachment.
Raise timeout for bootstrap/simulation loops; call stata_break if a run hangs.
Every run is appended to /.stata-copilot/runs.jsonl; stata_history reads it back.
Capabilities
Features and capabilities supported by this server
Protocol revision2025-11-25
| Capability | Details |
|---|---|
| tools | {
"listChanged": false
} |
Tools
Functions exposed to the LLM to take actions
| Name | Description |
|---|---|
| stata_statusA | Report the Stata session state: service reachability, Stata path/version/edition, licence, whether a command is running, and the active policy mode. Call this first when a Stata tool fails. |
| stata_runA | Execute a block of Stata commands in the live session and return structured results: success, return code, output transcript (truncated), generated graphs, and policy warnings. Set |
| stata_run_doA | Execute an existing do-file. The file must already exist on disk (agents should write the file, not push a giant string through stata_run). cwd defaults to the do-file's folder. Set background:true to run it as a separate Stata process and get a job id back instead of waiting. |
| stata_resultsA | Return the macros left behind by the last command: r() from |
| stata_profile_dataA | Describe the data the session is holding: source file, observations, variables, and for each variable its type, display format, variable label and number of missing values. Optionally load a dataset first (Stata |
| stata_modelA | Run one estimation command (e.g. "regress price mpg weight" or "xtreg y x, fe vce(cluster id)") and return a structured coefficient table — b, se, t/z, two-sided p per term — plus fit statistics. Use this instead of reading a regression table out of the transcript. |
| stata_graphsA | Return Stata graphs as images the agent can actually look at. Defaults to the graphs produced by the most recent run; pass explicit file paths to fetch older ones. PNG/JPEG are returned as image content; SVG-only output is reported by path. |
| stata_breakA | Send a break signal to Stata. Use after a timeout or runaway loop; then verify with stata_status that |
| stata_historyA | List commands executed through this server (newest last), with success, return code, duration and cwd. The same rows are appended to |
| stata_lintA | Check Stata code for constructs that run without an error yet do the wrong thing: the |
| stata_signatureA | Read the |
| stata_job_submitA | Run a do-file as its own Stata process and return a job id immediately. Use this for analyses that take longer than a couple of minutes: the HTTP service is single-threaded (it answers 409 while busy) and caps each call, while a job has no ceiling and leaves the interactive session free. Poll with stata_job_status. |
| stata_job_statusA | Report one background Stata job: state (running/ok/failed/timedout/killed), elapsed time, return code, the first Stata error if the do-file aborted, and the tail of its log. Call it in a loop with a pause between calls instead of blocking on a long run. |
| stata_job_logA | Return the tail of the log a background job is writing (Stata batch writes .log next to the do-file). Use it to see progress —counts, the current table, a long imputation step —while the job is still running. |
| stata_job_killA | Terminate a background Stata job by its id and return the final state. Prefer this over guessing: a stuck imputation or an accidental |
| stata_job_listA | List the background Stata jobs recorded under the given working directory, newest first, with their state and duration. Use it after a restart to find a job whose id you no longer have. |
Prompts
Interactive templates invoked by user choice
| Name | Description |
|---|---|
No prompts | |
Resources
Contextual data attached and managed by the client
| Name | Description |
|---|---|
No resources | |
TDQS
Scored across 16 tools
Most tools have crisp, distinct roles (run code, fetch results, inspect graphs, break, lint, fingerprint), and descriptions explicitly steer away from each other. A few boundaries blur: stata_run_do with background:true overlaps stata_job_submit, and stata_job_status already returns the log tail that stata_job_log also returns; stata_results (e() macros) and stata_model (structured coefficient table) also partly overlap for estimation output.
Every tool uses the same stata_ prefix followed by a snake_case noun or verb_noun form (stata_run_do, stata_job_status, stata_profile_data), with the job family nested consistently under stata_job_*. No casing or verb-style drift anywhere in the set.
16 tools is at the upper edge but each earns its place: execution, introspection, diagnostics, and a coherent background-job lifecycle. The job family (list/submit/status/log/kill) accounts for five tools and is arguably a bit granular, but nothing is trivial or redundant enough to cut.
The domain is a live Stata session, and the surface covers it end to end: status/health, foreground and background execution, do-files, macro results, data profiling and fingerprinting, graphs as images, estimation tables, linting, history/reproducibility, interrupt, and job management. Only marginal gaps remain (e.g. explicit data load/clear or session restart helpers), which arbitrary code execution and stata_profile_data's optional load largely absorb.