SM

sepinetam/mcp-for-stata

Developer tools
232 stars 0 forks 품질 56 트렌드 56

Enable Claude Code, Codex, OpenClaw, and other AI agents to safely invoke Stata on your local device for data analysis.

개요

Enable Claude Code, Codex, OpenClaw, and other AI agents to safely invoke Stata on your local device for data analysis.

README

MCP-for-Stata: Integrate Stata into your agent

Enable Claude Code, Codex, OpenClaw, and other AI agents to safely invoke Stata on your local device for data analysis.

Stata is a registered trademark of StataCorp LLC. This project is an independent community-developed tool and is not affiliated with, endorsed by, or sponsored by StataCorp LLC.


🆕 News

Finding our newest research? View latest research reports.


💡 Quickly Start

🚀 One-click installation for all clients!

No config, no manual JSON editing. Just one command installs MCP-for-Stata for every supported agent (Claude Code, Codex, OpenClaw, Cursor, Gemini CLI, and more):

uvx stata-mcp install --all

If you don’t have uv, see the uv installation guide to install it. Or, use our beta install script (auto-installs uv if missing):

macOS / Linux:

curl -fsSL https://raw.githubusercontent.com/SepineTam/mcp-for-stata/master/scripts/install.sh | bash

Windows (PowerShell):

irm https://raw.githubusercontent.com/SepineTam/mcp-for-stata/master/scripts/install.ps1 | iex

If you don’t know how to use them, download the installation scripts and double-click it in your device. install.bat for Windows users, and install.command for macOS users.

Advanced - Claude Code

As we find Claude Code is the best agent for MCP-for-Stata as its prefect agentic ability, we recommend using it, and there are lots of advanced usage following:

Before using it, please make sure you have ever install Claude Code, if you don’t know how to install it, visit on GitHub

Generally, you can install MCP-for-Stata globally for one time, you can run:

claude mcp add stata-mcp --scope user -- uvx stata-mcp

Then, you do not need to watch it again.

Then, you can use MCP-for-Stata in Claude Code. Here are some scenarios for using it:

  • Paper Replication: Replicate empirical studies from economics papers
  • Quick Hypothesis Testing: Validate economic hypotheses through regression analysis
  • Stata Learning Assistant: Learn econometrics with step-by-step Stata explanations
  • Code Organization: Review and optimize existing Stata do-files
  • Result Interpretation: Understand complex statistical outputs and regression results

If you use Claude Code inside IDEs (either the integrated terminal or the Claude Code Extension), installing our plugin including MCP-for-Stata and Stata LSP maintained by @euglevi.

# Add the MCP-for-Stata marketplace
claude plugin marketplace add SepineTam/mcp-for-stata

# Install the plugin to local, project or user scope
claude plugin install stata-toolbox -s project

The language server gives AI-generated Stata code better syntax awareness and completion, which improves output quality. We package the LSP in compliance with its license and give full attribution to the original author.

Advanced - Codex

We find that many researchers are using Codex as their agent, therefore we also provide instructions for Codex users.

I figure that researchers are not using Codex CLI but Codex Desktop, so we can say it is easier to config MCP-for-Stata than other agents.

You just need to say Install MCP-for-Stata for yourself globally from https://www.statamcp.com or visit https://github.com/SepineTam/mcp-for-stata then restart your Codex Desktop after it say ready.

Also, if you want to install it manually, here are two ways:

A. Install in Codex Desktop GUI

  1. Open your Codex Desktop APP
  2. Click Settings in the bottom-left corner
  3. Find MCP servers on the left side
  4. Click Add server
  5. Fill with the following:
    Name: stata-mcp
    Command to launch: uvx
    Arguments: stata-mcp
    
  6. Click Save
  7. Then, restart your Codex Desktop and enjoy it.

B. Install with Codex CLI

For CLI mode, just run the following command in your terminal

uvx stata-mcp install -c codex

Or use

codex mcp add stata-mcp -- uvx stata-mcp

Advanced - Claude Science

Claude Science runs MCP servers inside a strict sandbox that blocks access to the home directory (~) by default. If you try to launch MCP-for-Stata the standard way, you may see:

Couldn't load tools: MCP error -32000: Connection closed
FileNotFoundError: [Errno 2] No such file or directory

To fix this, allowlist the paths where uv tool install stata-mcp places its files. Create or edit ~/.claude-science/config.toml:

[sandbox]
user_write_paths = [
  "~/.local/bin",
  "~/.local/share/uv/tools/stata-mcp",
]

Then add the server in Claude Science:

  • Name: stata-mcp
  • Command: ~/.local/bin/stata-mcp

Restart Claude Science and the tools will load. For the full walkthrough, see the Claude Science guide.

Other Clients

Standard config requires: please make sure the stata is installed at the default path, and the stata cli (for macOS and Linux) exists.

The standard config json as follows, you can DIY your config via add envs.

{
  "mcpServers": {
    "stata-mcp": {
      "command": "uvx",
      "args": [
        "stata-mcp"
      ]
    }
  }
}

For more detailed usage information, visit the Usage guide.

Prerequisites

  • uv - Package installer and virtual environment manager
  • Claude Code, Codex, OpenClaw or other Agents
  • Stata License
  • Your API-KEY from LLM

If you want to check whether your device is supported, you can run:

uvx stata-mcp doctor

It displays basic information about your device and checks whether your setup is supported.

Notes:

  1. If you are located in China and package downloads are slow, see the solution.
  2. Claude is the best choice for MCP-for-Stata, for Chinese, I recommend to use DeepSeek as your model provider as it is cheap and powerful, also the score is highest in China provider, if you are increased in it, visit the report How to use StataMCP improve your social science research.

Comparison

There are several Stata-related MCP projects. The table below was generated by Claude Code after analyzing each codebase directly.

Feature MCP-for-Stata (this) haoyu-haoyu/stata-ai-fusion hanlulong/stata-mcp tmonk/mcp-stata
Best for Agent-driven analysis (Claude Code, Codex, OpenClaw) Interactive sessions, graph export, and curated Stata knowledge Users who write and run Stata code inside VSCode themselves Research workflows (replication, robustness, publication QA)
Agents All All VSCode window must stay active All
Type MCP Server + CLI toolkit MCP Server + Skill KB + VS Code Extension VSCode Extension (localhost server, not standalone MCP) Session-based MCP Server
Execution do-file via subprocess pexpect interactive session + batch fallback IDE-embedded runner via localhost :4000 pystata (Stata 17+)
Safety Command guard + RAM monitor Cancel command + session cleanup
Data analysis CSV, DTA, XLSX, SPSS handlers In-session inspect_data / codebook In-session describe / codebook
Logs Text + SMCL readers In-session search_log Built-in log reader
Graphs Auto-detect + export_graph PNG/SVG/PDF Export, cache, SVG/PNG
CLI Support Native (same tools as MCP server) Basic entry point
Sessions Multi named sessions with idle timeout Multi-session, background tasks
IDE plug-in Native VS Code / Cursor extension Native VSCode / Cursor Stata Workbench (VS Code)
Skill / Knowledge Tool-focused skill for MCP-for-Stata (742 lines) 5,653-line general Stata skill knowledge base 20+ specialized research skills (causal inference, replication, publication QA, etc.)
Install uvx stata-mcp install uvx --from stata-ai-fusion stata-ai-fusion VS Code Marketplace uvx or install script

📝 Documentation

MCP-for-Stata documents visit https://sepinetam.github.io/mcp-for-stata

Core Documentation

Key Features

  • Security Guard: Blocks dangerous commands (!, shell, erase, etc.)
  • RAM Monitoring: Prevents memory exhaustion with configurable limits
  • Layered Configuration: User, project, environment, and Linux system config support
  • Beta async stata_do execution: Supports concurrent MCP calls for multi-client workflows
  • Configurable data access boundaries: Data info URL guard and optional direct read_log boundary
  • Cross-platform support (macOS, Windows, Linux)
  • Automatic log capture and error reporting

🐛 Report Issues

If you encounter any bugs or have feature requests, please open an issue.

📄 License

GNU Affero General Public License v3.0

📚 Citation

If you use MCP-for-Stata in your research, and it really helps you, you can cite this repository using one of the following formats:

BibTeX

@software{sepinetam2025stata,
  author = {Song Tan},
  title = {MCP-for-Stata: Integrate Stata into your agent},
  year = {2025},
  url = {https://github.com/sepinetam/mcp-for-stata},
  version = {1.21.0}
}

APA

Song Tan. (2025). MCP-for-Stata: Integrate Stata into your agent (Version 1.21.0) [Computer software]. https://github.com/sepinetam/mcp-for-stata

Chicago

Song Tan. 2025. "MCP-for-Stata: Integrate Stata into your agent." Version 1.21.0. https://github.com/sepinetam/mcp-for-stata.

📬 Contact

Email: [email protected]

Or contribute directly by submitting a Pull Request! We welcome contributions of all kinds, from bug fixes to new features.

📃 Statement

Stata is a registered trademark of StataCorp LLC. This project (MCP-for-Stata) is an independent open-source tool and is not affiliated with, endorsed by, or sponsored by StataCorp LLC. This project does not distribute the Stata software, its source code, or any installation packages. Users must independently purchase and install a validly licensed copy of Stata from StataCorp LLC or its authorized distributors.

This project is licensed under AGPL-3.0. The project maintainers accept no liability for any loss or damage arising solely from the use of this project’s code or documentation.

More information: refer to the Chinese version at README.zh-CN.md; in case of any conflict, the Chinese version shall prevail.

✨ Star History

View this README on GitHub

설치

uvx stata-mcp

설정

{ "mcpServers": { "stata-mcp": { "command": "uvx", "args": [ "stata-mcp" ] } } }