Stata MCP Server
Supported as a platform for running the Stata MCP extension, enabling cross-platform functionality
Supported as a platform for running the Stata MCP extension, with specific configuration paths for MCP integration
Required as a dependency for the MCP server, but not directly integrated as a service
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
Stata MCP Extension for VS Code, Cursor, and Antigravity
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
Related MCP server: stata-mcp
Demo
Watch how this extension enhances your Stata workflow with Cursor (or VS Code/Antigravity) and AI assistance:

π¬ Full Video Version | π View Generated PDF Report
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."
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.
Open VS Code, Cursor, or Antigravity
Open the Extensions view (
Ctrl+Shift+X/Cmd+Shift+X)Search for "Stata MCP"
Click Install
That's it β the extension auto-starts the MCP server and appears in the status bar as "Stata".
From the command line
# VS Code
code --install-extension DeepEcon.stata-mcp
# Cursor
cursor --install-extension DeepEcon.stata-mcp
# Antigravity (installs from Open VSX Registry)
antigravity --install-extension DeepEcon.stata-mcpFrom a local .vsix file
Download stata-mcp-<version>.vsix from the releases page, then either:
code --install-extension path/to/stata-mcp-0.5.3.vsix
cursor --install-extension path/to/stata-mcp-0.5.3.vsix
antigravity --install-extension path/to/stata-mcp-0.5.3.vsixβ¦or in the UI: Extensions view β β¦ menu β Install from VSIXβ¦ β pick the downloaded file.
Registries
VS Code Marketplace: https://marketplace.visualstudio.com/items?itemName=DeepEcon.stata-mcp
Open VSX (Cursor / Antigravity): https://open-vsx.org/extension/DeepEcon/stata-mcp
Starting with version 0.1.8, the extension integrates a fast Python package installer called uv to set up the environment. If uv is not found on your system, the extension will attempt to install it automatically.
β‘ Connect Your AI Assistant
Once the extension is running (status bar shows "Stata"), the local MCP server is listening on:
http://localhost:4000/mcp-streamableβ Streamable HTTP (preferred for modern clients)http://localhost:4000/mcpβ SSE (legacy fallback)
Quick health check: curl -s http://localhost:4000/health should print a response that includes "status": "ok" and "stata_available": true. If stata_available is false, the server is up but Stata failed to load: check the Stata output channel (View > Output > Stata).
π One-prompt setup
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.
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.
Usage
Running Stata Code
Open a Stata .do file
Run commands using:
Run Selection: Select Stata code and press
Ctrl+Shift+Enter(orCmd+Shift+Enteron Mac), or click the play button in the editor toolbarRun File: Press
Ctrl+Shift+D(orCmd+Shift+Don Mac) to run the entire .do file, or click the run-all button in the toolbarStop Execution: Press
Ctrl+Shift+C(orCmd+Shift+Con Mac) to stop a running commandRestart 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 window, shown in a panel (or in your browser, per
stata-vscode.interactiveDisplayMode)
View output in the Stata Output panel
Note for Cursor/Antigravity Users: Toolbar buttons may be hidden by default. To show them:
Click the ... (three dots) menu in the editor title bar
Select "Configure Icon Visibility"
Enable the Stata buttons you want to see (Run Selection, Run File, Stop, View Data, Restart Session, Interactive)
Data Viewer
Access the data viewer to inspect your Stata dataset:
Click the View Data button (fourth button, table icon) in the editor toolbar
View your current dataset in a table format
Filter data: Use Stata
ifconditions to view subsets of your dataExample:
price > 5000 & mpg < 30Type your condition in the filter box and click "Apply"
Click "Clear" to remove the filter and view all data
Graph Display Options
Control how graphs are displayed:
Auto-display graphs: Graphs are automatically shown when generated (default: enabled)
Disable in Extension Settings:
stata-vscode.autoDisplayGraphs
Choose display method:
VS Code webview (default): Graphs appear in a panel within VS Code
External browser: Graphs open in your default web browser
Change in Extension Settings:
stata-vscode.graphDisplayMethod
Detailed Configurations
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
Core Settings
Setting | Description | Default |
| Path to Stata installation directory | Auto-detected |
| Stata edition to use (MP, SE, BE) |
|
| Automatically start MCP server when extension activates |
|
| Always show the Stata status bar item, even when not editing a Stata file |
|
Server Settings
Setting | Description | Default |
| Host for MCP server |
|
| Port for the MCP server |
|
| Force the specified port even if it's already in use |
|
Keep mcpServerHost set to localhost. 0.0.0.0 exposes an unauthenticated server that runs Stata code (including shell commands) to your network. On shared multi-user machines (for example HPC login nodes over Remote-SSH), other users of that machine can also reach localhost:4000, so turn stata-vscode.autoStartServer off there.
Graph Settings
Setting | Description | Default |
| Automatically display graphs when generated by Stata commands |
|
| Choose how to display graphs: |
|
| Where the Interactive Window opens: |
|
Log File Settings
Setting | Description | Default |
| Location for Stata log files: |
|
| Custom directory for Stata log files (only used when logFileLocation is set to | Empty |
Advanced Settings
Setting | Description | Default |
| Timeout in seconds for 'Run File' operations |
|
| Timeout in seconds for 'Run Selection' and interactive window commands |
|
| Show detailed debug information in output panel |
|
| Maximum number of rows the Data Viewer loads (100-500000) |
|
Working Directory Settings
Control which directory Stata uses when running .do files:
Setting | Description | Default |
| Working directory when running .do files: |
|
| Custom working directory path (only used when workingDirectory is set to | Empty |
Example: If your project structure is project/code/analysis.do and your do-file expects to run from project/, set workingDirectory to parent.
MCP Output Settings
These settings control how Stata output is returned to AI assistants (LLMs) via the MCP protocol, helping to reduce token usage:
Setting | Description | Default |
| Output mode for MCP returns: |
|
| Maximum tokens for MCP output (0 = unlimited). Large outputs are saved to file with a path returned instead |
|
Compact mode filters:
Loop code echoes (foreach/forvalues/while blocks) - keeps actual output only
Program definitions and Mata blocks
Command echoes and line continuations (for
run_fileonly)Verbose messages like "(N real changes made)" and "(N missing values generated)"
Multi-Session Settings
Enable parallel Stata execution with isolated sessions. Each session has its own data, variables, and macros.
Setting | Description | Default |
| Enable multi-session mode for parallel Stata execution |
|
| Maximum number of concurrent sessions (1-100) |
|
| Session idle timeout in seconds. Sessions are automatically destroyed after this period of inactivity |
|
Note: Each session requires ~200-300 MB RAM for Stata. Check your Stata license for concurrent instance limits.
GitHub Copilot supports MCP (Model Context Protocol) starting from VS Code 1.102. You can connect the Stata MCP server to Copilot for AI-powered Stata development.
Configuration
Install the Stata MCP extension in VS Code (see Installation section above)
Start the Stata MCP server: The server should start automatically when you open VS Code with the extension installed. Verify it's running by checking the status bar (should show "Stata").
Add the Stata MCP server to Copilot: You can configure MCP servers either per-workspace or globally.
Option A: Per-Workspace Configuration
Create a
.vscode/mcp.jsonfile in your workspace root:{ "servers": { "stata-mcp": { "type": "http", "url": "http://localhost:4000/mcp-streamable" } } }Option B: Global Configuration (All Workspaces)
Open Command Palette (Ctrl+Shift+P / Cmd+Shift+P)
Type "MCP: Open User Configuration" and select it
Add the Stata MCP server to the
mcp.jsonfile:{ "servers": { "stata-mcp": { "type": "http", "url": "http://localhost:4000/mcp-streamable" } } }
On older VS Code versions without Streamable HTTP support, use
"type": "sse"withhttp://localhost:4000/mcpinstead.The user-level
mcp.jsonfile is located at:Windows:
%APPDATA%\Code\User\mcp.jsonmacOS:
~/Library/Application Support/Code/User/mcp.jsonLinux:
~/.config/Code/User/mcp.json
Reload VS Code to apply the configuration.
GitHub Copilot 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
Verifying the Connection
Open GitHub Copilot Chat (Ctrl+Shift+I / Cmd+Shift+I)
Open Configure Tools in the chat input
Check that stata-mcp's tools (
stata_run_selection,stata_run_file, andstata_sessionover Streamable HTTP) are listed
Troubleshooting
If Copilot is not recognizing the Stata MCP server:
Verify VS Code version 1.102 or later
Verify the MCP server is running (Status bar should show "Stata")
Check that
.vscode/mcp.jsonexists with the correct contentTry restarting VS Code
Check the extension output panel (View > Output > Stata) for any errors
Ensure MCP is enabled in your organization's Copilot policy (if applicable)
Claude Code is Anthropic's official AI coding assistant available in VS Code, Cursor, and Antigravity. Follow these steps to configure the Stata MCP server:
Installation
Install the Stata MCP extension in VS Code, Cursor, or Antigravity (see Installation section above)
Start the Stata MCP server: The server should start automatically when you open your IDE with the extension installed. Verify it's running by checking the status bar (should show "Stata").
Configuration
Once the Stata MCP server is running, configure Claude Code to connect to it:
Open your terminal or command palette
Run the following command to add the Stata MCP server:
claude mcp add --transport http stata-mcp http://localhost:4000/mcp-streamable --scope userClaude Code versions older than 1.0.27 (June 2025) may not recognize
--transport http. On those, use--transport ssewithhttp://localhost:4000/mcpinstead. Claude Code now treats SSE as legacy β preferhttpwhenever it is supported.Restart your IDE
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
Verifying the Connection
To verify Claude Code is properly connected to the Stata MCP server:
Open a Stata .do file or create a new one
Ask Claude Code to help with a Stata task (e.g., "Load the auto dataset and show summary statistics")
Claude Code should be able to execute Stata commands and show results
Troubleshooting
If Claude Code is not recognizing the Stata MCP server:
Verify the MCP server is running (Status bar should show "Stata")
Check that you ran the
claude mcp addcommand with the correct URLTry restarting your IDE
Check the extension output panel (View > Output > Stata) for any errors
Ensure there are no port conflicts (default port is 4000)
Claude Desktop can use the extension's local MCP server through claude_desktop_config.json. Make sure the Stata MCP extension is installed and its status bar shows "Stata" before configuring Claude Desktop.
Claude Desktop's JSON config doesn't accept remote URLs directly, so you need a local stdio wrapper. The easiest is mcp-remote, which runs through npx if you have Node.js:
Open the config file from Claude Desktop β Settings β Developer β Edit Config, or open it directly:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json
Add this block (merge with any existing
mcpServersobject):{ "mcpServers": { "stata-mcp": { "command": "npx", "args": ["-y", "mcp-remote", "http://localhost:4000/mcp-streamable"] } } }Fully quit and restart Claude Desktop. The Stata tools will appear in the available-tools list.
Note: don't add this server with Settings β Connectors β Add custom connector. Custom connectors only accept
https://URLs of internet-hosted servers, so they can't reach the localhttp://localhost:4000server.
If the tools don't show up, check that curl -s http://localhost:4000/health responds with "status": "ok" and "stata_available": true (false means the server is up but Stata failed to load; see the Stata output channel), then look at Claude Desktop's MCP logs (~/Library/Logs/Claude/mcp-server-stata-mcp.log on macOS, %APPDATA%\Claude\logs\mcp-server-stata-mcp.log on Windows).
You can use this extension with OpenAI Codex β the CLI and every IDE extension share the same ~/.codex/config.toml. Codex CLI 0.46.0+ (October 2025) connects to HTTP MCP servers directly, without a wrapper (0.46.x needed one extra flag; see Troubleshooting below). Either drive it from the command line:
codex mcp add stata-mcp --url http://localhost:4000/mcp-streamableThen add tool_timeout_sec = 900 under the [mcp_servers.stata-mcp] block that this command writes to ~/.codex/config.toml (see below).
Or append this block manually to ~/.codex/config.toml (or %USERPROFILE%\.codex\config.toml on Windows):
[mcp_servers.stata-mcp]
url = "http://localhost:4000/mcp-streamable"
tool_timeout_sec = 900Codex's default per-tool timeout (60 s in early releases, 300 s in current ones) is shorter than the server's default 600-second run limit, so raise it to keep long Stata runs from being cut off.
Upgrading from an older setup? If an existing
[mcp_servers.stata-mcp]block usescommand = "mcp-proxy"(orcommand = "uvx"+mcp-proxyin args), delete that block before adding the one above β TOML forbids duplicate keys, and Codex will silently skip the server if both are present.
Then restart Codex β the stata_run_selection, stata_run_file and stata_session tools will appear. Run codex mcp list to confirm the server is registered.
Note on transports. Codex only speaks MCP's Streamable HTTP transport (single endpoint at
/mcp-streamable). The extension's legacy SSE endpoint (/mcp) is for older clients like GitHub Copilot β don't point Codex at it.
Troubleshooting Codex Configuration
If Codex doesn't see the Stata tools:
Verify the MCP server is running (status bar shows "Stata") β try
curl -s http://localhost:4000/health; the response should include"status": "ok"and"stata_available": true(falsemeans Stata failed to load; check the Stata output channel)Check
codex --versionβ make sure you're on 0.46.0 or newer. Older Codex versions need themcp-proxywrapper (see note below). On early HTTP-capable releases (0.46.x), Codex also neededexperimental_use_rmcp_client = trueat the top level ofconfig.toml; if the server doesn't load on such a release, add it or update Codex.Verify the config file exists at
~/.codex/config.tomland contains the exact[mcp_servers.stata-mcp]block aboveRun
codex mcp listβstata-mcpshould appear as registeredRestart Codex (CLI or IDE) after config changes
Check the extension output panel (View β Output β Stata) for any server-side errors
Ensure no port conflict (default is 4000 β change via
stata-vscode.mcpServerPortif needed)
If you cannot upgrade, use mcp-proxy as a stdio wrapper around the SSE endpoint:
# Install uv first if needed:
curl -LsSf https://astral.sh/uv/install.sh | sh # macOS/Linux
# Windows: powershell -c "irm https://astral.sh/uv/install.ps1 | iex"[mcp_servers.stata-mcp]
command = "uvx"
args = ["mcp-proxy", "http://localhost:4000/mcp"]Open your Cline MCP settings file. The easiest way: in the Cline panel, click the MCP Servers icon, open the Configure tab and click Configure MCP Servers. This opens the file your Cline version uses:
Newer Cline builds (shown as "Next" next to the version in Cline's Settings > About) and the Cline CLI:
~/.cline/data/settings/cline_mcp_settings.json(on Windows,%USERPROFILE%\.cline\data\settings\cline_mcp_settings.json)Older Cline builds (or "Legacy" in Settings > About):
macOS:
~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.jsonWindows:
%APPDATA%/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.jsonLinux:
~/.config/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
Add the Stata MCP server configuration:
{ "mcpServers": { "stata-mcp": { "type": "streamableHttp", "url": "http://localhost:4000/mcp-streamable" } } }Keep the
"type": "streamableHttp"line: without atype, Cline uses the legacy SSE transport. To use SSE instead, set"type": "sse"withhttp://localhost:4000/mcp.If the file already contains other MCP servers, just add the
"stata-mcp"entry to the existing"mcpServers"object.Save the file and restart VS Code.
Set up stata-mcp in Cline earlier without a
typefield? Cline treats that entry as SSE, which fails against/mcp-streamable. Open the settings file as in step 1 and set"type": "streamableHttp"on thestata-mcpentry. Newer ("Next") Cline builds copy old entries once into~/.cline/data/settings/cline_mcp_settings.jsonand stop reading the old globalStorage file after that, so edit the new file; a copied entry may look like"transport": { "type": "sse", ... }, in which case change thattypeto"streamableHttp".
Troubleshooting Cline Configuration
If Cline is not recognizing the Stata MCP server:
Verify the MCP server is running (Status bar should show "Stata")
Check that the configuration file exists with the correct content
Try restarting VS Code
Check the extension output panel (View > Output > Stata) for any errors
The extension automatically configures Cursor MCP integration. To verify it's working:
Open Cursor
Press
Ctrl+Shift+P(orCmd+Shift+Pon Mac) to open the Command PaletteType "Stata: Test MCP Server Connection" and press Enter
You should see a success message if the server is properly connected
Cursor Configuration File Paths
Cursor reads user-level MCP config from:
macOS / Linux:
~/.cursor/mcp.jsonWindows:
%USERPROFILE%\.cursor\mcp.json
Workspace-level config (overrides user-level for that project) goes in .cursor/mcp.json at the workspace root.
Manual Cursor Configuration
If you need to manually configure Cursor MCP:
Create or edit the MCP configuration file:
macOS/Linux:
~/.cursor/mcp.jsonWindows:
%USERPROFILE%\.cursor\mcp.json
Add the Stata MCP server configuration:
{ "mcpServers": { "stata-mcp": { "url": "http://localhost:4000/mcp-streamable" } } }Cursor auto-detects the transport from the URL β no
transportkey needed. It tries Streamable HTTP first and falls back to SSE if the server advertises it.If the file already contains other MCP servers, just add the
"stata-mcp"entry to the existing"mcpServers"object.Save the file and restart Cursor.
Troubleshooting Cursor Configuration
If Cursor is not recognizing the Stata MCP server:
Verify the MCP server is running
Check that the configuration file exists with the correct content
Try restarting Cursor
Ensure there are no port conflicts with other running applications
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:
Install UV manually:
# Windows (PowerShell as Administrator) powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" # macOS/Linux curl -LsSf https://astral.sh/uv/install.sh | shFollow the clean-reinstall steps in the troubleshooting guide to reinstall the extension.
Troubleshooting
Running into trouble? The full troubleshooting guide β clean reinstall steps for Windows / macOS / Linux, common Python and UV issues, Stata-edition mismatches, and what to include when opening a GitHub issue β lives in docs/troubleshooting.md.
Star History
License
MIT
Credits
Created by Lu Han, Published by OpenEcon.ai
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogβ¦
This server cannot be deployed
Maintenance
Related MCP Connectors
Connect ChatGPT, Claude, Cursor or VS Code to your Windows PC: files, terminal, browser, apps.
Build, validate, test-run and publish AIOS workflows from Claude Code, Codex, Cursor or VS Code.
Run accessibility, contrast, and design token audits and file QA issues from your AI coding tool.
The OpenRouter MCP server plugs OpenRouter into the AI tools you already use. Once connected, your assistant can pull live OpenRouter data (models, prices, your credits, rankings, and docs) and send quick test messages, all without leaving your editor.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceConnects AI agents to a local Stata installation, enabling execution of Stata code, data inspection, graph generation, and result verification through natural language interactions.1,054 PyPI92AGPL 3.0
- AlicenseAqualityDmaintenanceControls the Stata GUI through Windows Stata Automation COM, enabling do-file management, command execution, and data analysis within natural language workflows.1219 PyPI7MIT
- AlicenseCqualityDmaintenanceProvides project-local, reproducible Stata execution for humans and AI agents, with immutable run artifacts, provenance tracking, planning gates, and a shared dashboard.22AGPL 3.0
- AlicenseAqualityBmaintenanceEnables LLM/agent applications to execute Stata code, load and inspect data, obtain structured regression results and graphs, and manage background tasks through the Model Context Protocol.10MIT