Stata MCP Server
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Stata MCP ServerLoad the auto dataset and regress price on mpg"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Stata MCP Server
A Model Context Protocol (MCP) server that connects AI agents to a local Stata installation.
If you'd like a fully integrated VS Code extension to run Stata code without leaving your IDE, and also allow AI agent interaction, check out my other project: Stata Workbench.
Built by Thomas Monk, London School of Economics.
This server enables LLMs to:
Execute Stata code: run any Stata command (e.g.
sysuse auto,regress price mpg).Inspect data: retrieve dataset summaries and variable codebooks.
Export graphics: generate and view Stata graphs (histograms, scatterplots).
Verify results: programmatically check stored results (
r(),e()) for accurate validation.
Prerequisites
Stata 17+ (required for
pystataintegration)Python 3.11+ (recommended)
uv (recommended for install/run)
Related MCP server: Stata MCP Server
Installation
Run as a published tool with uvx
uvx --from mcp-stata mcp-statauvx is an alias for uv tool run and runs the tool in an isolated, cached environment.
Configuration
This server attempts to automatically discover your Stata installation (supporting standard paths and StataNow).
If auto-discovery fails, set the STATA_PATH environment variable to your Stata executable:
# macOS example
export STATA_PATH="/Applications/StataNow/StataMP.app/Contents/MacOS/stata-mp"
# Windows example (cmd.exe)
set STATA_PATH="C:\Program Files\Stata18\StataMP-64.exe"If you prefer, add STATA_PATH to your MCP config's env for any IDE shown below. It's optional and only needed when discovery cannot find Stata.
Optional env example (add inside your MCP server entry):
"env": {
"STATA_PATH": "/Applications/StataNow/StataMP.app/Contents/MacOS/stata-mp"
}IDE Setup (MCP)
This MCP server uses the stdio transport (the IDE launches the process and communicates over stdin/stdout).
Claude Desktop
Open Claude Desktop → Settings → Developer → Edit Config. Config file locations include:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json
Published tool (uvx)
{
"mcpServers": {
"mcp-stata": {
"command": "uvx",
"args": ["--from", "mcp-stata", "mcp-stata"]
}
}
}After editing, fully quit and restart Claude Desktop to reload MCP servers.
Cursor
Cursor supports MCP config at:
Global:
~/.cursor/mcp.jsonProject:
.cursor/mcp.json
Published tool (uvx)
{
"mcpServers": {
"mcp-stata": {
"command": "uvx",
"args": ["--from", "mcp-stata", "mcp-stata"]
}
}
}Windsurf
Windsurf supports MCP plugins and also allows manual editing of mcp_config.json. After adding/editing a server, use the UI’s refresh so it re-reads the config.
A common location is ~/.codeium/windsurf/mcp_config.json.
Published tool (uvx)
{
"mcpServers": {
"mcp-stata": {
"command": "uvx",
"args": ["--from", "mcp-stata", "mcp-stata"]
}
}
}Google Antigravity
In Antigravity, MCP servers are managed from the MCP store/menu; you can open Manage MCP Servers and then View raw config to edit mcp_config.json.
Published tool (uvx)
{
"mcpServers": {
"mcp-stata": {
"command": "uvx",
"args": ["--from", "mcp-stata", "mcp-stata"]
}
}
}Visual Studio Code
VS Code supports MCP servers via a .vscode/mcp.json file. The top-level key is servers (not mcpServers).
Create .vscode/mcp.json:
Published tool (uvx)
{
"servers": {
"mcp-stata": {
"type": "stdio",
"command": "uvx",
"args": ["--from", "mcp-stata", "mcp-stata"],
}
}
}VS Code documents .vscode/mcp.json and the servers schema, including type and command/args.
Skills
Skill file (for Claude/Codex): skill/SKILL.md
Tools Available
run_command(code, raw=false): Execute Stata syntax. Returns a structured JSON envelope by default; setraw=truefor plain stdout/stderr.trace=truetemporarily enablesset trace on.load_data(source, clear=True, raw=false): Heuristic loader (sysuse/webuse/use/path/URL) with JSON envelope.get_data(start, count): View dataset rows (JSON response, capped to 500 rows).describe(): View dataset structure.codebook(variable, raw=false): Variable-level metadata (JSON envelope by default).run_do_file(path, trace=false, raw=false): Execute a .do file with rich error capture (JSON by default).export_graph(name, format="pdf"): Export a graph to a file path (default PDF; useformat="png"for PNG).export_graphs_all(): Export all in-memory graphs as base64-encoded PNGs (JSON response).list_graphs(): See available graphs in memory (JSON list with anactiveflag).get_stored_results(): Getr()ande()scalars/macros.get_help(topic, plain_text=false): Returns Markdown-rendered Stata help (default). Useplain_text=truefor stripped text. Falls back to the Stata online help URL if missing.get_variable_list(): JSON list of variables and labels.
License
This project is licensed under the GNU Affero General Public License v3.0 or later. See the LICENSE file for the full text.
Error reporting
All tools that execute Stata commands support JSON envelopes (
as_json=true) carrying:rc(from r()/c(rc)),stdout,stderr,message, optionalline(when Stata reports it),command, and asnippetexcerpt of error output.
Stata-specific cues are preserved:
r(XXX)codes are parsed when present in output.“Red text” is captured via stderr where available.
trace=trueaddsset trace onaround the command/do-file to surface program-defined errors; the trace is turned off afterward.
Logging
Set STATA_MCP_LOGLEVEL (e.g., DEBUG, INFO) to control server logging. Logs include discovery details (edition/path) and command-init traces for easier troubleshooting.
This server cannot be deployed
Maintenance
Related MCP Connectors
Use your Mac, Windows or Linux computer from ChatGPT, Claude or Codex: files, commands, documents.
Connect AI agents to Exa for web search, content fetching, and multi-step research.
Work on your own computers from Claude or ChatGPT: run commands, edit and search files.
Machine-readable utilities and datasets for AI agents.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceProvides a bridge between Stata statistical software and code editors like VS Code and Cursor, enabling users to run Stata commands directly from the editor, view output in real-time, and get AI-powered assistance with Stata coding.515MIT
- AlicenseNot gradedqualityDmaintenanceConnects AI agents to a local Stata installation, enabling execution of Stata code, data inspection, graph generation, and result verification through natural language interactions.597 PyPI90AGPL 3.0
- FlicenseNot gradedqualityDmaintenanceEnables an agent to execute Stata do scripts or inline commands locally and retrieve structured results including status, error diagnostics, and output text for consumption by the model.1-
- AlicenseCqualityBmaintenanceProvides project-local, reproducible Stata execution for humans and AI agents, with immutable run artifacts, provenance tracking, planning gates, and a shared dashboard.22AGPL 3.0