Stata MCP provides Stata integration for VS Code, Cursor, and Antigravity IDE through the Model Context Protocol, enabling AI-powered statistical development with tools like GitHub Copilot and Claude. The server offers capabilities to execute Stata commands and do-files, display real-time output, provide syntax highlighting for Stata file types, and support multi-session parallel execution for collaborative AI coding. It solves the problem of integrating Stata workflows with modern AI-assisted development environments and LLM-based coding assistants.
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.
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."
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.
Ctrl+Shift+X / Cmd+Shift+X)That's it — the extension auto-starts the MCP server and appears in the status bar as "Stata".
# 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-mcp
Download stata-mcp-<version>.vsix from the releases page, then either:
code --install-extension path/to/stata-mcp-0.5.2.vsix
cursor --install-extension path/to/stata-mcp-0.5.2.vsix
antigravity --install-extension path/to/stata-mcp-0.5.2.vsix
…or in the UI: Extensions view → … menu → Install from VSIX… → pick the downloaded file.
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.
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 {"status":"ok",...}.
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.
Ctrl+Shift+Enter (or Cmd+Shift+Enter on Mac), or click the play button in the editor toolbarCtrl+Shift+D (or Cmd+Shift+D on Mac) to run the entire .do file, or click the run-all button in the toolbarCtrl+Shift+C (or Cmd+Shift+C on Mac) to stop a running commandNote 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)
Access the data viewer to inspect your Stata dataset:
if conditions to view subsets of your data
price > 5000 & mpg < 30Control how graphs are displayed:
stata-vscode.autoDisplayGraphsstata-vscode.graphDisplayMethodCustomize the extension behavior through VS Code settings. Access these settings via:
Ctrl+, / Cmd+,)| Setting | Description | Default |
|---|---|---|
stata-vscode.stataPath | Path to Stata installation directory | Auto-detected |
stata-vscode.stataEdition | Stata edition to use (MP, SE, BE) | mp |
stata-vscode.autoStartServer | Automatically start MCP server when extension activates | true |
| Setting | Description | Default |
|---|---|---|
stata-vscode.mcpServerHost | Host for MCP server | localhost |
stata-vscode.mcpServerPort | Port for the MCP server | 4000 |
stata-vscode.forcePort | Force the specified port even if it's already in use | false |
| Setting | Description | Default |
|---|---|---|
stata-vscode.autoDisplayGraphs | Automatically display graphs when generated by Stata commands | true |
stata-vscode.graphDisplayMethod | Choose how to display graphs: vscode (webview panel) or browser (external browser) | vscode |
| Setting | Description | Default |
|---|---|---|
stata-vscode.logFileLocation | Location for Stata log files: dofile (same directory as .do file), parent (parent directory of .do file), workspace (VS Code workspace root), extension (logs folder in extension directory), or custom (user-specified directory) | extension |
stata-vscode.customLogDirectory | Custom directory for Stata log files (only used when logFileLocation is set to custom) | Empty |
| Setting | Description | Default |
|---|---|---|
stata-vscode.runFileTimeout | Timeout in seconds for 'Run File' operations | 600 (10 minutes) |
stata-vscode.runSelectionTimeout | Timeout in seconds for 'Run Selection' and interactive window commands | 600 (10 minutes) |
stata-vscode.debugMode | Show detailed debug information in output panel | false |
Control which directory Stata uses when running .do files:
| Setting | Description | Default |
|---|---|---|
stata-vscode.workingDirectory | Working directory when running .do files: dofile (same as .do file), parent (parent directory of .do file), workspace (VS Code workspace root), extension (logs folder in extension directory), custom (user-specified), or none (don't change directory) | dofile |
stata-vscode.customWorkingDirectory | Custom working directory path (only used when workingDirectory is set to custom) | Empty |
Example: If your project structure is project/code/analysis.do and your do-file expects to run from project/, set workingDirectory to parent.
These settings control how Stata output is returned to AI assistants (LLMs) via the MCP protocol, helping to reduce token usage:
| Setting | Description | Default |
|---|---|---|
stata-vscode.resultDisplayMode | Output mode for MCP returns: compact (filters redundant output to save tokens) or full (returns complete output) | compact |
stata-vscode.maxOutputTokens | Maximum tokens for MCP output (0 = unlimited). Large outputs are saved to file with a path returned instead | 10000 |
Compact mode filters:
run_file only)Enable parallel Stata execution with isolated sessions. Each session has its own data, variables, and macros.
| Setting | Description | Default |
|---|---|---|
stata-vscode.multiSession | Enable multi-session mode for parallel Stata execution | true |
stata-vscode.maxSessions | Maximum number of concurrent sessions (1-100) | 100 |
stata-vscode.sessionTimeout | Session idle timeout in seconds. Sessions are automatically destroyed after this period of inactivity | 3600 |
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.
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.json file in your workspace root:
{
"servers": {
"stata-mcp": {
"type": "http",
"url": "http://localhost:4000/mcp-streamable"
}
}
}
Option B: Global Configuration (All Workspaces)
mcp.json file:
{
"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.json file is located at:
%APPDATA%\Code\User\mcp.json~/Library/Application Support/Code/User/mcp.json~/.config/Code/User/mcp.jsonReload VS Code to apply the configuration.
GitHub Copilot will now have access to Stata tools and can help you:
@mcp to see available MCP toolsstata_run_selection, stata_run_file) should appearIf Copilot is not recognizing the Stata MCP server:
.vscode/mcp.json exists with the correct contentClaude Code is Anthropic's official AI coding assistant available in VS Code, Cursor, and Antigravity. Follow these steps to configure the Stata MCP server:
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").
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 user
Older Claude Code versions (pre-2026) 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:
To verify Claude Code is properly connected to the Stata MCP server:
If Claude Code is not recognizing the Stata MCP server:
claude mcp add command with the correct URLClaude Desktop connects to remote MCP servers like the one this extension exposes. Make sure the Stata MCP extension is installed and its status bar shows "Stata" before configuring Claude Desktop.
Option A (recommended): add as a Custom Connector
Stata MCPhttp://localhost:4000/mcp-streamableNo wrapper, no config file editing, no Python/Node install required. This is Anthropic's current recommended way to add remote MCP servers to Claude Desktop.
Option B: JSON config with a stdio wrapper (if you prefer editing claude_desktop_config.json)
Anthropic's JSON config doesn't yet accept remote URLs directly — you still need a local stdio wrapper. The easiest is mcp-remote, which is zero-install if you have Node:
Open the config file:
~/Library/Application Support/Claude Desktop/claude_desktop_config.json%APPDATA%\Claude Desktop\claude_desktop_config.jsonAdd this block (merge with any existing mcpServers object):
{
"mcpServers": {
"stata-mcp": {
"command": "npx",
"args": ["-y", "mcp-remote", "http://localhost:4000/mcp-streamable"]
}
}
}
Restart Claude Desktop. The Stata tools will appear in the available-tools list.
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) supports MCP servers over HTTP natively, so no wrapper is needed. Either drive it from the command line:
codex mcp add stata-mcp --url http://localhost:4000/mcp-streamable
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"
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 and stata_run_file 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.
If Codex doesn't see the Stata tools:
curl -s http://localhost:4000/healthcodex --version — make sure you're on 0.46.0 or newer. Older Codex versions need the mcp-proxy wrapper (see note below).~/.codex/config.toml and contains the exact [mcp_servers.stata-mcp] block abovecodex mcp list — stata-mcp should appear as registeredstata-vscode.mcpServerPort if 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:
~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json%APPDATA%/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json~/.config/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.jsonAdd the Stata MCP server configuration:
{
"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.
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.
You can also configure Cline through VS Code settings:
"cline.mcpSettings": {
"stata-mcp": {
"url": "http://localhost:4000/mcp-streamable"
}
}
If Cline is not recognizing the Stata MCP server:
The extension automatically configures Cursor MCP integration. To verify it's working:
Ctrl+Shift+P (or Cmd+Shift+P on Mac) to open the Command PaletteCursor reads user-level MCP config from:
~/.cursor/mcp.json%USERPROFILE%\.cursor\mcp.jsonWorkspace-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:
Create or edit the MCP configuration file:
~/.cursor/mcp.json%USERPROFILE%\.cursor\mcp.jsonAdd the Stata MCP server configuration:
{
"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.
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.
If Cursor is not recognizing the Stata MCP server:
This extension uses uv, a fast Python package installer built in Rust, to manage Python dependencies. Key features:
If you encounter any UV-related errors during installation:
# 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 | sh
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.
MIT
Created by Lu Han, Published by OpenEcon.ai