Stata

by hanlulong

22 stars
Not rated
GitHub

About

Integrates Stata statistical software with code editors like VS Code and Cursor, enabling direct command execution, real-time output viewing, and contextual coding assistance for data scientists and researchers.

Details

Author
hanlulong
Repository
hanlulong/stata-mcp
GitHub stars
22
License
MIT License
Categories
Developer Tools, Other, Productivity, File Management, AI, Search, Infrastructure
Tags
#integration

- Run Stata Commands: Execute selections or entire .do files directly from your editor
- Real-time Output: See Stata results instantly in your editor
- Syntax Highlighting: Full syntax support for Stata .do, .ado, .mata, and .doh files
- AI Assistant Integration: Contextual help and code suggestions via MCP
- Cross-platform: Works on Windows, macOS, and Linux
- Multi-Session Parallel Execution: Run multiple Stata sessions simultaneously with AI coding tools

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name Stata
    Command (node, npx, python, etc.) npx
    Arguments
    • Argument 1 -y
    • Argument 2 mcp-remote
    • Argument 3 http://localhost:4000/mcp-streamable

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Once the Stata MCP server is running, configure Claude Code to connect to it:

1. Open your terminal or command palette

2. Run the following command to add the Stata MCP server:

   claude mcp add --transport http stata-mcp http://localhost:4000/mcp-streamable --scope user

> Older Claude Code versions (pre-2026) may not recognize --transport http. On those, use --transport sse with http://localhost:4000/mcp instead. Claude Code now treats SSE as legacy — prefer http whenever it is supported.

3. Restart your IDE

4. Claude Code will now have access to Stata tools and can help you:
- Write and execute Stata commands
- Analyze your data
- Generate visualizations
- Debug Stata code
- Create statistical reports

antigravity --install-extension DeepEcon.stata-mcp


Paste the block below into any MCP-aware assistant — Claude Code, OpenAI Codex, Cursor AI, Copilot Chat, etc. Hover the box on GitHub and click the copy icon in the top-right corner.

text
Set up the Stata MCP server for me. Endpoint: http://localhost:4000/mcp-streamable — setup guide: https://github.com/hanlulong/stata-mcp#detailed-configurations — if I already have a stata-mcp entry in my MCP config (e.g. using mcp-proxy), replace it rather than appending. When registration succeeds, tell me to restart the client so the stata_run_selection tool becomes available.

The assistant reads the guide, detects which client it is, writes the right config (or runs the right CLI command), and tells you to restart. The stata_run_selection tool becomes visible after the restart — MCP tool lists do not refresh mid-session.

Prefer manual setup? Expand Detailed Configurations below for per-client instructions.

1. Open a Stata .do file
2. Run commands using:
- Run Selection: Select Stata code and press Ctrl+Shift+Enter (or Cmd+Shift+Enter on Mac), or click the play button in the editor toolbar
- Run File: Press Ctrl+Shift+D (or Cmd+Shift+D on Mac) to run the entire .do file, or click the run-all button in the toolbar
- Stop Execution: Press Ctrl+Shift+C (or Cmd+Shift+C on Mac) to stop a running command
- Restart Session: Click the restart button in the editor toolbar or use the Command Palette ("Stata: Restart Session") to reset the Stata session. This clears all in-memory data, globals, and programs — equivalent to closing and reopening Stata
- Interactive Mode: Click the graph button in the editor toolbar to run code in an interactive browser window
3. View output in the Stata Output panel

> Note for Cursor/Antigravity Users: Toolbar buttons may be hidden by default. To show them:
> 1. Click the ... (three dots) menu in the editor title bar
> 2. Select "Configure Icon Visibility"
> 3. Enable the Stata buttons you want to see (Run Selection, Run File, Stop, View Data, Restart Session, Interactive)

<details>
<summary><strong>Extension Settings</strong></summary>

Customize the extension behavior through VS Code settings. Access these settings via:
- VS Code/Cursor/Antigravity: File > Preferences > Settings (or Ctrl+, / Cmd+,)
- Search for "Stata MCP" to find all extension settings

If Codex doesn't see the Stata tools:
1. Verify the MCP server is running (status bar shows "Stata") — try curl -s http://localhost:4000/health
2. Check codex --version — make sure you're on 0.46.0 or newer. Older Codex versions need the mcp-proxy wrapper (see note below).
3. Verify the config file exists at ~/.codex/config.toml and contains the exact [mcp_servers.stata-mcp] block above
4. Run codex mcp liststata-mcp should appear as registered
5. Restart Codex (CLI or IDE) after config changes
6. Check the extension output panel (View → Output → Stata) for any server-side errors
7. Ensure no port conflict (default is 4000 — change via stata-vscode.mcpServerPort if needed)

<details>
<summary>Stuck on Codex &lt; 0.46.0?</summary>

If you cannot upgrade, use mcp-proxy as a stdio wrapper around the SSE endpoint:

bash

curl -LsSf https://astral.sh/uv/install.sh | sh # macOS/Linux


toml [mcp_servers.stata-mcp] command = "uvx" args = ["mcp-proxy", "http://localhost:4000/mcp"]

</details>

<br>

</details>
<details>
<summary><strong>Cline</strong></summary>

1. Open your Cline MCP settings file:
- macOS: ~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
- Windows: %APPDATA%/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
- Linux: ~/.config/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json

2. Add the Stata MCP server configuration:

json
{
"mcpServers": {
"stata-mcp": {
"url": "http://localhost:4000/mcp-streamable"
}
}
}

Cline auto-detects the transport from the URL — no transport key needed. Point it at http://localhost:4000/mcp if you need SSE for any reason.

3. If the file already contains other MCP servers, just add the "stata-mcp" entry to the existing "mcpServers" object.

4. Save the file and restart VS Code.

You can also configure Cline through VS Code settings:

json
"cline.mcpSettings": {
"stata-mcp": {
"url": "http://localhost:4000/mcp-streamable"
}
}

If Cline is not recognizing the Stata MCP server:
1. Verify the MCP server is running (Status bar should show "Stata")
2. Check that the configuration file exists with the correct content
3. Try restarting VS Code
4. Check the extension output panel (View > Output > Stata MCP) for any errors

<br>

</details>
<details>
<summary><strong>Cursor</strong></summary>

The extension automatically configures Cursor MCP integration. To verify it's working:

1. Open Cursor
2. Press Ctrl+Shift+P (or Cmd+Shift+P on Mac) to open the Command Palette
3. Type "Stata: Test MCP Server Connection" and press Enter
4. You should see a success message if the server is properly connected

Cursor reads user-level MCP config from:

- macOS / Linux: ~/.cursor/mcp.json
- Windows: %USERPROFILE%\.cursor\mcp.json

Workspace-level config (overrides user-level for that project) goes in .cursor/mcp.json at the workspace root.

If you need to manually configure Cursor MCP:

1. Create or edit the MCP configuration file:
- macOS/Linux: ~/.cursor/mcp.json
- Windows: %USERPROFILE%\.cursor\mcp.json

2. Add the Stata MCP server configuration:

json
{
"mcpServers": {
"stata-mcp": {
"url": "http://localhost:4000/mcp-streamable"
}
}
}

Cursor auto-detects the transport from the URL — no transport key needed. It tries Streamable HTTP first and falls back to SSE if the server advertises it.

3. If the file already contains other MCP servers, just add the "stata-mcp" entry to the existing "mcpServers" object.

4. Save the file and restart Cursor.

If Cursor is not recognizing the Stata MCP server:
1. Verify the MCP server is running
2. Check that the configuration file exists with the correct content
3. Try restarting Cursor
4. Ensure there are no port conflicts with other running applications

<br>

</details>
<details>
<summary><strong>Python Environment Management</strong></summary>

This extension uses uv, a fast Python package installer built in Rust, to manage Python dependencies. Key features:

- Automatic Python setup and dependency management
- Creates isolated environments that won't conflict with your system
- Works across Windows, macOS, and Linux
- 10-100x faster than traditional pip installations

If you encounter any UV-related errors during installation:
1. Install UV manually:

bash

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "stata": {
            "cwd": "string (optional)",
            "env": {},
            "args": [
                "-y",
                "mcp-remote",
                "http://localhost:4000/mcp-streamable"
            ],
            "shell": false,
            "command": "npx"
        }
    }
}

Linux

{
    "cwd": "string (optional)",
    "env": [],
    "args": [
        "-y",
        "mcp-remote",
        "http://localhost:4000/mcp-streamable"
    ],
    "shell": false,
    "command": "npx"
}

Macos

{
    "cwd": "string (optional)",
    "env": [],
    "args": [
        "-y",
        "mcp-remote",
        "http://localhost:4000/mcp-streamable"
    ],
    "shell": false,
    "command": "npx"
}

Windows

{
    "cwd": "string (optional)",
    "env": [],
    "args": [
        "/c",
        "npx",
        "-y",
        "mcp-remote",
        "http://localhost:4000/mcp-streamable"
    ],
    "shell": false,
    "command": "cmd"
}

Stata MCP Extension for VS Code, Cursor, and Antigravity

en
cn
VS Code Marketplace
VS Code Installs
Open VSX
Open VSX Downloads
GitHub Downloads
GitHub License

This extension provides Stata integration for Visual Studio Code, Cursor, and Antigravity IDE using the Model Context Protocol (MCP). It enables AI-powered Stata development with GitHub Copilot, Cursor, Antigravity, Cline, Claude Code, or Codex.

Features

- Run Stata Commands: Execute selections or entire .do files directly from your editor
- Real-time Output: See Stata results instantly in your editor
- Syntax Highlighting: Full syntax support for Stata .do, .ado, .mata, and .doh files
- AI Assistant Integration: Contextual help and code suggestions via MCP
- Cross-platform: Works on Windows, macOS, and Linux
- Multi-Session Parallel Execution: Run multiple Stata sessions simultaneously with AI coding tools

Demo

Watch how this extension enhances your Stata workflow with Cursor (or VS Code/Antigravity) and AI assistance:

Stata MCP Extension Demo

🎬 Full Video Version &nbsp;&nbsp;|&nbsp;&nbsp; 📄 View Generated PDF Report

<sub>Demo prompt: "Write and execute Stata do-files, ensuring that full absolute file paths are used in all cases. Load the auto dataset (webuse auto) and generate summary statistics for each variable. Identify and extract key features from the dataset, produce relevant plots, and save them in a folder named plots. Conduct a regression analysis to examine the main determinants of car prices. Export all outputs to a LaTeX file and compile it. Address any compilation errors automatically, and ensure that LaTeX compilation does not exceed 10 seconds. All code errors should be identified and resolved as part of the workflow."</sub>

Requirements

- Stata 17 or higher installed on your machine
- UV package manager (automatically installed or can be installed manually if needed)

Installation

> Note: Initial installation requires setting up dependencies which may take up to 2 minutes to complete. Please be patient during this one-time setup process. All subsequent runs will start instantly.

1. Open VS Code, Cursor, or Antigravity
2. Open the Extensions view (Ctrl+Shift+X / Cmd+Shift+X)
3. Search for "Stata MCP"
4. Click Install

That's it — the extension auto-starts the MCP server and appears in the status bar as "Stata".

<details>
<summary><strong>Other installation methods</strong> — CLI, .vsix file, Open VSX</summary>

From the command line

```bash

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.