mcp-stata

Runs Stata code, reads datasets, stored results and graphs in a local Stata install over MCP

By Thomas Monk (individual) Python Local · stdio Data and analytics

46 popularity score ★ 92 ↓ 2.4k/mo

Connect your client

Local (PyPI)

Add in one click

Opens the app, which asks before it adds the server.

Or add it by command or config

Claude CodeTerminal
claude mcp add stata -- uvx --refresh --refresh-package mcp-stata --from mcp-stata@latest mcp-stata
Claude Desktopclaude_desktop_config.json
{
  "mcpServers": {
    "stata": {
      "command": "uvx",
      "args": [
        "--refresh",
        "--refresh-package",
        "mcp-stata",
        "--from",
        "mcp-stata@latest",
        "mcp-stata"
      ]
    }
  }
}
Cursor~/.cursor/mcp.json
{
  "mcpServers": {
    "stata": {
      "command": "uvx",
      "args": [
        "--refresh",
        "--refresh-package",
        "mcp-stata",
        "--from",
        "mcp-stata@latest",
        "mcp-stata"
      ]
    }
  }
}
VS Code.vscode/mcp.json
{
  "servers": {
    "stata": {
      "type": "stdio",
      "command": "uvx",
      "args": [
        "--refresh",
        "--refresh-package",
        "mcp-stata",
        "--from",
        "mcp-stata@latest",
        "mcp-stata"
      ]
    }
  }
}
Codex~/.codex/config.toml
[mcp_servers.stata]
command = "uvx"
args = ["--refresh", "--refresh-package", "mcp-stata", "--from", "mcp-stata@latest", "mcp-stata"]
Gemini CLITerminal
gemini mcp add --scope user stata uvx -- --refresh --refresh-package mcp-stata --from mcp-stata@latest mcp-stata

Settings 6

STATA_PATH Optional: Path to the Stata executable, needed only when automatic discovery fails.
MCP_STATA_TEMP Optional: Writable folder for temporary files, for permission problems (common on Windows).
MCP_STATA_STARTUP_DO_FILE Optional: One or more do-files run when a session starts, separated by : (Unix) or ; (Windows).
MCP_STATA_NO_RELOAD_ON_CLEAR Optional: Set to 1 to stop startup files re-running after clear all.
MCP_STATA_ALLOWED_ROOTS Optional: Extra folders, path-separator delimited, where do-files and datasets may be read without allow_unsafe_paths.
MCP_STATA_LOGLEVEL Optional: Server log level, DEBUG by default in server.py.

What it does

mcp-stata connects an assistant to a copy of Stata installed on your own computer. It loads Stata through pystata, the Python bridge that ships with Stata, and keeps one or more named Stata sessions open, so commands run one after another against the same data in memory, as they would in the Stata window.

Through it an assistant can run commands or whole do-files (in the foreground or as background jobs it can poll, interrupt or cancel), load datasets, describe and list variables, read r(), e() and s() stored results as structured data, export graphs, read Stata help and search the log files each run writes. On top of that sit research helpers written by Thomas Monk at the London School of Economics for empirical economics: a dataset audit, an estimation plan, side-by-side comparison of model specifications, a publication check of tables and graphs, a reproducibility report, and a runner for test_*.do files. It also offers prompts, a set of stata:// resources and a catalogue of skill files.

The README's tool section lists 10 tools; the server.py of release 3.3.0 registers 20, adding stata_research_audit, stata_estimation_plan, stata_compare_specs, stata_publication_check, stata_project_reproducibility_report, stata_doctor and four test tools. A side HTTP API for a VS Code data browser starts with it on 127.0.0.1.

What it needs

RuntimePython 3.11+

A licensed local install of Stata 17 or later (MP, SE or BE, StataNow supported) on macOS, Windows or Linux; Python 3.11+; uv for the uvx launch command. The server finds Stata itself in standard locations; set STATA_PATH to the Stata executable when it does not. It uses the pystata module inside the Stata install: do not install the unrelated pystata package from PyPI.

Limits

A synchronous stata_run returns only the last 5,000 characters of output (server.py, v3.3.0); the full output is in the log file, read with stata_read_log. With default settings, a do-file path or double-quoted path in a command that lies outside the working directory, the system temp folder, ~/.mcp-stata/temp and the package's own folder is refused unless the call sets allow_unsafe_paths or the folder is added in MCP_STATA_ALLOWED_ROOTS, a setting the README does not mention. Cancelling a running command is best-effort and can leave partial output. The data-browser API caps a page at 500 rows.

Who it suits

Economists and other researchers who already hold a Stata licence and want an assistant to run regressions, check data and rerun do-files against their real Stata, with the session kept between calls. It is no use without Stata on the same machine, and it cannot reach a Stata on a server you only log into remotely. Because it runs whatever Stata code it is given, people who only want an assistant to read data can use the read_only option on stata_run, which refuses commands it classes as writing, deleting, installing or fetching URLs.

Tools 20

stata_run
Runs Stata commands or a .do file in a session, optionally as a background job
stata_task_status
Reports on or waits for a background job
stata_control
Interrupts a running session or cancels a background job
stata_read_log
Reads, tails or searches a run's log file
stata_load_data
Loads a dataset via sysuse, webuse, use, a file path or a URL
stata_inspect_data
Describes, summarises, lists or searches variables, or lints .do/.ado files
stata_manage_graphs
Lists graphs in memory and exports one or all of them
stata_get_results
Returns r(), e() and s() stored results, with optional Mata state
stata_get_help
Fetches Stata help for a topic as Markdown or plain text
stata_manage_session
Creates, lists and stops sessions, shows history and detects the Stata install
stata_research_audit
Runs a structured check of the dataset for research use
stata_estimation_plan
Builds an estimation plan and a suggested Stata command
stata_compare_specs
Runs several estimation commands and compares their results
stata_publication_check
Reviews current estimates and graphs for paper readiness
stata_project_reproducibility_report
Summarises environment, settings and recent jobs for reproducibility
stata_doctor
Runs an environment check and smoke test of the server
stata_run_tests
Finds and runs all test_*.do files under a folder
stata_run_test
Runs one test_*.do file
stata_discover_tests
Lists test files under a folder without running them
stata_get_test_results
Returns full results of the last test run in a session

Similar servers