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
64 stars

The Stata MCP Extension connects Visual Studio Code and Cursor IDE to Stata through the Model Context Protocol (MCP), allowing you to run Stata commands directly from your editor, view real-time output, and benefit from AI assistant integration.

Installation

VS Code Installation

From VS Code Marketplace

code --install-extension DeepEcon.stata-mcp

Or:

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

From .vsix file

  1. Download stata-mcp-0.2.5.vsix from the releases page
  2. Install using:
code --install-extension path/to/stata-mcp-0.2.5.vsix

Or:

  1. Open VS Code
  2. Go to Extensions view (Ctrl+Shift+X)
  3. Click on "..." menu in the top-right
  4. Select "Install from VSIX..."
  5. Navigate to and select the downloaded .vsix file

Cursor Installation

  1. Download stata-mcp-0.2.5.vsix from the releases page
  2. Install using:
cursor --install-extension path/to/stata-mcp-0.2.5.vsix

Or:

  1. Open Cursor
  2. Go to Extensions view
  3. Click on the "..." menu
  4. Select "Install from VSIX"
  5. Navigate to and select the downloaded .vsix file

Configuration

Extension Settings

Customize the extension through VS Code settings:

  • stata-vscode.stataPath: Path to Stata installation directory
  • stata-vscode.mcpServerHost: Host for MCP server (default: localhost)
  • stata-vscode.mcpServerPort: Port for the MCP server (default: 4000)
  • stata-vscode.autoStartServer: Automatically start MCP server on activation (default: true)
  • stata-vscode.debugMode: Show detailed debug information (default: false)
  • stata-vscode.forcePort: Force the MCP server to use the specified port (default: false)
  • stata-vscode.clineConfigPath: Custom path to Cline configuration file (optional)
  • stata-vscode.runFileTimeout: Timeout for 'Run File' operations (default: 600 seconds)
  • stata-vscode.stataEdition: Stata edition to use (MP, SE, BE) - default: MP
  • stata-vscode.logFileLocation: Location for Stata log files (default: extension)
  • stata-vscode.customLogDirectory: Custom directory for Stata log files

Cursor MCP Configuration

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

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

For manual configuration, edit the appropriate file:

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

Add the Stata MCP server configuration:

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

Cline MCP Configuration

Edit the Cline MCP settings file and add:

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

Or configure through VS Code settings:

"cline.mcpSettings": {
  "stata-mcp": {
    "url": "http://localhost:4000/mcp",
    "transport": "sse"
  }
}

Claude Desktop Configuration

  1. Install mcp-proxy:
pip install mcp-proxy
  1. Find the path to mcp-proxy:
# On Mac/Linux
which mcp-proxy

# On Windows (PowerShell)
(Get-Command mcp-proxy).Path
  1. Edit the Claude Desktop MCP config file:
{
  "mcpServers": {
    "stata-mcp": {
      "command": "/path/to/mcp-proxy",
      "args": ["http://127.0.0.1:4000/mcp"]
    }
  }
}

Usage

  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)
    • Run File: Press Ctrl+Shift+D (or Cmd+Shift+D on Mac)
  3. View output in the editor panel
  4. Choose your Stata edition (MP, SE, or BE) in the extension settings

Log File Management

Control where log files are saved:

  1. Open VS Code/Cursor settings
  2. Search for "Stata MCP"
  3. Select your preferred log file location option:
    • Extension Directory (default)
    • Workspace Directory
    • Custom Directory

Troubleshooting

If you encounter issues, try these steps:

Windows

  1. Close all VS Code/Cursor windows
  2. End any Python or uvicorn processes in Task Manager
  3. Delete the extension folder (%USERPROFILE%\.vscode\extensions\deepecon.stata-mcp-0.x.x)
  4. Install UV manually if needed:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
  1. Restart your computer
  2. Reinstall the extension

macOS/Linux

  1. Close all VS Code/Cursor windows
  2. Kill Python processes:
ps aux | grep python
kill -9 <PID>
  1. Remove the extension folder:
rm -rf ~/.vscode/extensions/deepecon.stata-mcp-0.x.x
  1. Install UV manually if needed:
curl -LsSf https://astral.sh/uv/install.sh | sh
  1. Restart your terminal or computer
  2. Reinstall the extension

For persistent issues:

  • Check the Output panel (View → Output → Stata-MCP)
  • Verify Python 3.11+ is installed: python --version
  • Verify UV installation: uv --version
  • Ensure the selected Stata edition matches what's installed

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