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
Provider
Lu Han
Release date
Mar 23, 2025
Language
TypeScript
Stats
46 stars

The Stata MCP Extension provides a seamless integration between Stata and modern code editors like VS Code and Cursor, allowing you to run Stata commands directly from your editor and view results in real-time while leveraging AI assistance through the Model Context Protocol (MCP).

Installation

VS Code Installation

From VS Code Marketplace

You can install the extension directly from the VS Code Marketplace:

code --install-extension DeepEcon.stata-mcp

Alternatively:

  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 the extension package from the releases page
  2. Install using the command:
code --install-extension path/to/stata-mcp-0.2.4.vsix

Or through the VS Code interface:

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

Cursor Installation

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

Or through the Cursor interface:

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

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.

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 when extension activates (default: true)
  • stata-vscode.debugMode: Show detailed debug information in output panel (default: false)
  • stata-vscode.forcePort: Force the MCP server to use the specified port even if it's already in use (default: false)
  • stata-vscode.clineConfigPath: Custom path to Cline configuration file
  • stata-vscode.runFileTimeout: Timeout in seconds for 'Run File' operations (default: 600 seconds)
  • stata-vscode.stataEdition: Stata edition to use (MP, SE, IC) - default: MP

Cursor MCP Configuration

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)
  3. Type "Stata: Test MCP Server Connection" and press Enter
  4. You should see a success message if properly connected

If you need to manually configure Cursor:

  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:

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

Cline MCP Configuration

  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:

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

You can also configure Cline through VS Code settings:

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

Usage

Running Stata Commands

  1. Open a Stata .do file in VS Code or Cursor
  2. Run commands using:
    • Run Selection: Select Stata code and press Ctrl+Shift+Enter (or Cmd+Shift+Enter on Mac)
    • Run File: Press Ctrl+Shift+D (or Cmd+Shift+D on Mac) to run the entire file
  3. View output directly in the editor panel

Choosing Stata Edition

Select your preferred Stata edition (MP, SE, or IC) in the extension settings. Make sure it matches the version installed on your system.

Troubleshooting

If you encounter issues with the extension, try these steps:

Windows

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

macOS/Linux

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

Common Issues

  • If you see error messages in the Output panel (View -> Output -> Stata-MCP), check for:

    • Python or UV not being found in your PATH
    • Permission issues (try running as Administrator on Windows)
    • Conflicts with existing Python installations or virtual environments
    • Make sure your selected Stata edition matches what's installed on your system
  • For persistent issues, verify:

    • Your Python installation: python --version or python3 --version
    • UV installation: uv --version
    • That you have Python 3.11 or later installed

Claude Desktop Integration

You can use this extension with Claude Desktop through mcp-proxy:

  1. Ensure the Stata MCP extension is running in VS Code or Cursor
  2. Install mcp-proxy:
    pip install mcp-proxy
    # or
    uv install mcp-proxy
    
  3. Find the path to mcp-proxy:
    which mcp-proxy  # On Mac/Linux
    (Get-Command mcp-proxy).Path  # On Windows (PowerShell)
    
  4. Configure Claude Desktop:
    • Edit the config file at %APPDATA%\Claude Desktop\claude_desktop_config.json (Windows) or ~/Library/Application Support/Claude Desktop/claude_desktop_config.json (macOS)
    • Add:
      {
        "mcpServers": {
          "stata-mcp": {
            "command": "/path/to/mcp-proxy",
            "args": ["http://127.0.0.1:4000/mcp"]
          }
        }
      }
      
  5. Restart Claude Desktop

How to add this MCP server to 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 > MCP and click "Add new global MCP server".

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

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

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 explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

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