Stata MCP Extension for VS Code, Cursor, and Antigravity IDE
개요
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. - : Execute selections or entire .do files directly from your editor - : See Stata results instantly in your editor - : Full syntax support for Stata .do, .ado, .mata, and .doh files - : Contextual help and code suggestions via MCP - : Works on Windows, macOS, and Linux - : Run multiple Stata sessions simultaneously with AI coding tools Watch how this extension enhances your Stata workflow with Cursor (or VS Code/Antigravity) and AI assistance: 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.
README
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
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”.
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 {"status":"ok",...}.
📋 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 toolbar - Run File: Press
Ctrl+Shift+D(orCmd+Shift+Don Mac) to run the entire .do file, or click the run-all button in the toolbar - Stop Execution: Press
Ctrl+Shift+C(orCmd+Shift+Con Mac) to stop a running command - Restart 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 browser window
- Run Selection: Select Stata code and press
- 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 data- Example:
price > 5000 & mpg < 30 - Type your condition in the filter box and click “Apply”
- Click “Clear” to remove the filter and view all data
- Example:
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
- Disable in Extension Settings:
- 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
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
설치
npx -y mcp-remote http://localhost:4000/mcp-streamable설정
{
"mcpServers": {
"stata-mcp": {
"command": "npx",
"args": ["-y", "mcp-remote", "http://localhost:4000/mcp-streamable"]
}
}
}