Stata MCP server

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.
Back to servers
Setup instructions
Provider
Lu Han
Release date
Mar 23, 2025
Language
TypeScript
Stats
113 stars

The Stata MCP Extension is a powerful tool that enables Stata integration with Visual Studio Code and Cursor IDE using the Model Context Protocol (MCP). It allows you to run Stata commands directly from your editor, view real-time output, and leverage AI assistance for your data analysis tasks.

Installation

VS Code Installation

From VS Code Marketplace:

  1. Open VS Code
  2. Go to Extensions view (Ctrl+Shift+X)
  3. Search for "Stata MCP"
  4. Click "Install"

Alternatively, use the command:

code --install-extension DeepEcon.stata-mcp

From .vsix file:

  1. Download the extension package from the releases page
  2. In VS Code, go to Extensions view
  3. Click "..." menu and select "Install from VSIX..."
  4. Navigate to the downloaded file

Cursor Installation

  1. Download the extension package from the releases page
  2. In Cursor, go to Extensions view
  3. Click "..." menu and select "Install from VSIX"
  4. Navigate to the downloaded file

Usage

Running Stata Code

  1. Open a Stata .do file
  2. Run commands using:
    • Run Selection: Select code and press Ctrl+Shift+Enter (or Cmd+Shift+Enter on Mac), or click the ▶️ button
    • Run File: Press Ctrl+Shift+D (or Cmd+Shift+D on Mac), or click the second button
    • Interactive Mode: Select code and click the 📊 button, or click without selection to run the entire file
  3. View output in the editor panel or interactive window

Data Viewer

  1. Click the View Data button (table icon) in the editor toolbar
  2. View your current dataset in table format
  3. Filter data: Use Stata if conditions (e.g., price > 5000 & mpg < 30)
    • Type your condition in the filter box and click "Apply"
    • Click "Clear" to remove filters

Graph Display Options

  1. Auto-display graphs: Enabled by default (can be disabled in settings)
  2. Choose display method:
    • VS Code webview (default): Graphs appear in VS Code
    • External browser: Graphs open in your browser

Stata Edition Selection

Select your preferred Stata edition (MP, SE, or BE) in the Extension Settings

Configuration

Access settings via File > Preferences > Settings (or Ctrl+, / Cmd+,), then search for "Stata MCP".

Core Settings

  • Stata Path: Path to Stata installation directory
  • Stata Edition: Stata edition to use (MP, SE, BE)
  • Auto Start Server: Automatically start MCP server

Server Settings

  • MCP Server Host: Host for MCP server
  • MCP Server Port: Port for the MCP server

Graph Settings

  • Auto Display Graphs: Automatically display generated graphs
  • Graph Display Method: Choose how to display graphs

Log File Settings

  • Log File Location: Where to save Stata log files
  • Custom Log Directory: Custom directory for logs

Troubleshooting

If you encounter issues:

  1. Close all VS Code/Cursor windows
  2. Kill any running Python or uvicorn processes
  3. Remove the extension folder:
    • Windows: %USERPROFILE%\.vscode\extensions\deepecon.stata-mcp-0.x.x
    • macOS/Linux: ~/.vscode/extensions/deepecon.stata-mcp-0.x.x
  4. Install UV manually if needed:
    • Windows: powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
    • macOS/Linux: curl -LsSf https://astral.sh/uv/install.sh | sh
  5. Restart your computer
  6. Reinstall the extension

For persistent issues, check the Output panel (View → Output → Stata-MCP) for error messages.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "stata-mcp" '{"url":"http://localhost:4000/mcp","transport":"sse"}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "stata-mcp": {
            "url": "http://localhost:4000/mcp",
            "transport": "sse"
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "stata-mcp": {
            "url": "http://localhost:4000/mcp",
            "transport": "sse"
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later