stata-mcp
Stata MCP Server
Ein MCP-Server, der die Stata-GUI über Windows Stata Automation COM für Claude Code steuerbar macht.
中文
功能
Durch Stata Automation COM Befehle in einem echten Stata-GUI-Fenster ausführen.
Stata-Sitzungen anhand des absoluten Pfads der Do-Files verwalten: Dasselbe Do-File verwendet dasselbe Stata-Fenster wieder.
Verschiedene Do-Files öffnen verschiedene Stata-Fenster, was das gleichzeitige Betrachten mehrerer Analyseaufgaben erleichtert.
Befehle ohne Pfadangabe werden an die zuletzt ausgeführte Do-File-Sitzung gesendet.
Unterstützt das Schreiben, Lesen, Anhängen und Ausführen von Do-Files.
Unterstützt das Lesen von Stata-Text-Logs, damit Claude die Ergebnisse analysieren kann.
Unterstützt das Lesen der aktuellen Datenstruktur, fehlender Werte und einer Stichprobenvorschau, um Claude bei der Bearbeitung von Do-Files zu unterstützen.
Demo

Verzeichnisstruktur
D:/Stata18/mcp/
├── README.md
├── pyproject.toml
├── .gitignore
├── stata_mcp.py # 兼容启动器
├── src/
│ └── stata_mcp/
│ ├── __init__.py
│ └── server.py # MCP 服务器主文件
├── runtime/
│ ├── dofiles/ # Claude/MCP 默认生成 do 文件
│ └── logs/ # Claude/MCP 默认读取或生成 log
└── examples/ # 示例 do 文件Systemanforderungen
Windows
Stata 18 MP, mit registriertem Automation COM
Python 3.10+
Python-Pakete:
mcp,pywin32Claude Code
Empfohlener Installationsort
Es wird empfohlen, dieses Projekt im mcp-Ordner des Stata-Installationsverzeichnisses abzulegen, zum Beispiel:
D:/Stata18/mcpFalls Stata an einem anderen Ort installiert ist, wird ebenfalls empfohlen, es im entsprechenden Verzeichnis abzulegen, zum Beispiel:
C:/Program Files/Stata18/mcpFortgeschrittene Benutzer können es auch in einem beliebigen stabilen Verzeichnis ablegen. Unabhängig vom Speicherort muss der Skriptpfad in der Claude Code MCP-Konfiguration auf die tatsächliche stata_mcp.py zeigen.
Installationsschritte
Laden Sie dieses Repository herunter oder klonen Sie es in den
mcp-Ordner im Stata-Installationsverzeichnis.Installieren Sie die Python-Abhängigkeiten:
pip install mcp pywin32Alternativ können Sie diese auch in einer virtuellen Umgebung installieren:
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install mcp pywin32Öffnen Sie PowerShell als Administrator und registrieren Sie Stata Automation. Passen Sie den Befehl an Ihren Stata-Installationspfad an:
Start-Process -FilePath "D:\Stata18\StataMP-64.exe" -ArgumentList "/Register" -WaitÜberprüfen Sie, ob COM verfügbar ist:
python -c "import win32com.client; s=win32com.client.Dispatch('stata.StataOLEApp'); s.DoCommand('display 12345')"Erwartetes Ergebnis: Die Stata-GUI öffnet sich oder wird verbunden und zeigt 12345 an.
Zu Claude Code hinzufügen (empfohlen)
Es wird empfohlen, claude mcp add zu verwenden:
claude mcp add stata -- python D:\Stata18\mcp\stata_mcp.pyFalls die Installation in einem anderen Pfad erfolgte, ersetzen Sie diesen durch den tatsächlichen Pfad. Zum Beispiel:
claude mcp add stata -- python "C:\Program Files\Stata18\mcp\stata_mcp.py"Starten Sie nach dem Hinzufügen Claude Code neu und bestätigen Sie, dass das stata-Tool in der Liste der MCP-Tools erscheint.
Manuelle Konfiguration von Claude Code MCP
Falls Sie claude mcp add nicht verwenden, können Sie die MCP-JSON auch manuell konfigurieren:
"stata": {
"command": "python",
"args": ["D:\\Stata18\\mcp\\stata_mcp.py"]
}Sie können auch direkt auf die Hauptdatei verweisen:
"stata": {
"command": "python",
"args": ["D:\\Stata18\\mcp\\src\\stata_mcp\\server.py"]
}Normalerweise wird die Verwendung des Kompatibilitäts-Launchers stata_mcp.py empfohlen, da die Konfiguration bei späteren Änderungen der internen Projektstruktur stabiler bleibt.
Konfigurierbare Umgebungsvariablen
Für normale Benutzer ist keine Einstellung erforderlich. Falls Ihr Installationspfad oder COM-Name besonders ist, können Sie Folgendes festlegen:
Variable | Standardwert | Funktion |
| Automatisch erkanntes Projekt-Root | MCP-Projektverzeichnis |
| Übergeordnetes Verzeichnis des MCP | Stata-Installationsverzeichnis |
|
| Für README-Registrierungshinweise |
|
| Stata Automation ProgID |
Tools
Tool | Funktion |
| Befehl in der letzten Do-File-Sitzung ausführen |
| Stata-Sitzung anhand des absoluten Do-File-Pfads ausführen/wiederverwenden |
| Do-File schreiben; einfache Dateinamen in |
| Do-File-Inhalt lesen |
| Do-File-Inhalt anhängen |
| Stata-Text-Log lesen |
| Externes Paket in der Stata-GUI installieren |
|
|
|
|
| Aktuelle Datenstruktur, fehlende Werte und Stichprobenvorschau lesen und an Claude zurückgeben |
| MCP- und Stata-Sitzungsstatus anzeigen |
Regeln für Do-Files und Sitzungen
stata_run_dofile(path)verwendet den absoluten Pfad des Do-Files als Sitzungskennung.Derselbe Do-File-Pfad verwendet dasselbe Stata-Fenster wieder.
Verschiedene Do-File-Pfade erstellen verschiedene Stata-Fenster.
stata_run,stata_get_results,stata_get_data_info,stata_get_data_schemawerden standardmäßig an die zuletzt ausgeführte Do-File-Sitzung gesendet.Wenn noch kein Do-File ausgeführt wurde, fordern Befehle ohne Pfad dazu auf, zuerst ein Do-File auszuführen.
Lesen der aktuellen Datenstruktur und Stichproben
stata_get_data_schema generiert einen Text-Log-Snapshot in der letzten Do-File-Sitzung und gibt den Inhalt an Claude zurück. Standardmäßig enthalten:
describecodebook, compactmisstable summarizelist in 1/20, abbreviate(20)noteslabel dir
Optionale Parameter:
Parameter | Standardwert | Beschreibung |
|
| Anzahl der Stichprobenzeilen, maximal 1000 |
|
| Ob ein kompaktes Codebook enthalten sein soll |
|
| Ob eine Stichprobenvorschau enthalten sein soll |
|
| Ob eine Zusammenfassung fehlender Werte enthalten sein soll |
Dies ermöglicht es Claude, nicht nur Variablennamen, Typen und Labels zu sehen, sondern auch eine kleine Menge echter Daten, um die Bearbeitung von Do-Files präziser zu unterstützen.
Log-Strategie
stata_get_data_schemaüberschreibt seinen eigenen Schema-Snapshot-Log, da dieser die aktuelle Datenstruktur repräsentiert.Wenn Claude andere Analyseergebnisse lesen soll, sollte Stata ein Text-Log schreiben, das dann mit
stata_read_loggelesen wird.Empfohlene Regel: Innerhalb derselben Claude/MCP-Sitzung anhängen; beim ersten Ausführen desselben Do-Files in einer neuen Sitzung überschreiben, um ein unendliches Anwachsen der Logs zu vermeiden.
Fehlerbehebung
pywin32 nicht verfügbar
Führen Sie aus:
pip install pywin32COM kann keine Stata-Instanz erstellen
Registrieren Sie Stata Automation erneut:
Start-Process -FilePath "D:\Stata18\StataMP-64.exe" -ArgumentList "/Register" -WaitFühren Sie den Befehl mit /Register nicht direkt in Git Bash aus, da Git Bash /Register möglicherweise in einen Pfad umschreibt.
stata_run meldet, dass keine Do-File-Sitzung existiert
Führen Sie zuerst ein Do-File aus:
stata_run_dofile(path="D:/Stata18/mcp/examples/browse_test.do")Danach werden Befehle ohne Pfad an diese letzte Sitzung gesendet.
Claude kann die Ergebnisse der Stata-GUI nicht direkt sehen
Claude kann den Bildschirminhalt nicht lesen. Sie müssen Stata anweisen, ein Text-Log zu schreiben, das dann über stata_read_log gelesen wird; oder verwenden Sie stata_get_data_schema, um einen Snapshot der aktuellen Datenstruktur zu erhalten.
Related MCP server: Windows-MCP
English
Features
Runs Stata commands in the real Stata GUI through Stata Automation COM.
Keeps one Stata session per absolute do-file path: the same do file reuses the same Stata window.
Different do files open different Stata windows, so multiple analysis tasks can stay visible.
Pathless commands are sent to the most recently used do-file session.
Supports writing, reading, appending, and running do files.
Supports reading Stata text logs so Claude can analyze command output.
Supports reading the current data structure, missing-value summary, and sample rows to help Claude edit do files.
Project layout
D:/Stata18/mcp/
├── README.md
├── pyproject.toml
├── .gitignore
├── stata_mcp.py # compatibility launcher
├── src/
│ └── stata_mcp/
│ ├── __init__.py
│ └── server.py # main MCP server
├── runtime/
│ ├── dofiles/ # default do files generated by Claude/MCP
│ └── logs/ # default logs generated or read by Claude/MCP
└── examples/ # example do filesRequirements
Windows
Stata 18 MP with Automation COM registered
Python 3.10+
Python packages:
mcp,pywin32Claude Code
Recommended install location
It is recommended to place this project inside your Stata installation directory, for example:
D:/Stata18/mcpIf Stata is installed somewhere else, place the project under that Stata directory, for example:
C:/Program Files/Stata18/mcpAdvanced users may place it in any stable directory. Wherever you install it, the Claude Code MCP configuration must point to the actual stata_mcp.py path.
Installation
Download or clone this repository into the
mcpfolder under your Stata installation directory.Install Python dependencies:
pip install mcp pywin32You may also use a virtual environment:
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install mcp pywin32Open PowerShell as Administrator, then register Stata Automation. Adjust the path to your Stata installation:
Start-Process -FilePath "D:\Stata18\StataMP-64.exe" -ArgumentList "/Register" -WaitVerify COM:
python -c "import win32com.client; s=win32com.client.Dispatch('stata.StataOLEApp'); s.DoCommand('display 12345')"Expected result: the Stata GUI opens or is connected, and displays 12345.
Add to Claude Code (recommended)
Use claude mcp add:
claude mcp add stata -- python D:\Stata18\mcp\stata_mcp.pyIf you installed the project somewhere else, replace the path with your actual path. Example:
claude mcp add stata -- python "C:\Program Files\Stata18\mcp\stata_mcp.py"Restart Claude Code after adding the MCP server, then confirm that the stata tools are available.
Manual Claude Code MCP configuration
If you do not use claude mcp add, you can configure MCP manually with JSON:
"stata": {
"command": "python",
"args": ["D:\\Stata18\\mcp\\stata_mcp.py"]
}You can also point directly to the main server file:
"stata": {
"command": "python",
"args": ["D:\\Stata18\\mcp\\src\\stata_mcp\\server.py"]
}The compatibility launcher stata_mcp.py is usually recommended because it keeps your Claude Code configuration stable if the internal project layout changes later.
Environment variables
Most users do not need these. If your installation path or COM ProgID is unusual, you can configure:
Variable | Default | Purpose |
| auto-detected project root | MCP project directory |
| parent of MCP directory | Stata installation directory |
|
| used in README registration examples |
|
| Stata Automation ProgID |
Tools
Tool | Purpose |
| Run commands in the most recent do-file session |
| Run/reuse a Stata session by absolute do-file path |
| Write a do file; simple names go to |
| Read a do file |
| Append content to a do file |
| Read a Stata text log |
| Install external packages in the Stata GUI |
| Display |
| Display |
| Return current data structure, missing summary, and sample rows to Claude |
| Show MCP and Stata session status |
Do-file and session rules
stata_run_dofile(path)uses the absolute do-file path as the session key.The same do-file path reuses the same Stata window.
Different do-file paths create different Stata windows.
stata_run,stata_get_results,stata_get_data_info, andstata_get_data_schemaare sent to the most recent do-file session by default.If no do file has been run yet, pathless commands will ask you to run a do file first.
Reading current data structure and sample rows
stata_get_data_schema creates a text log snapshot in the most recent do-file session and returns it to Claude. By default, it includes:
describecodebook, compactmisstable summarizelist in 1/20, abbreviate(20)noteslabel dir
Options:
Option | Default | Description |
|
| Number of sample rows, max 1000 |
|
| Include compact codebook |
|
| Include sample preview |
|
| Include missing-value summary |
This lets Claude see not only variable names, types, and labels, but also a small real-data sample, which helps it write better Stata code.
Log strategy
stata_get_data_schemaoverwrites its own schema snapshot log because it represents the current data state.For other analysis output, ask Stata to write a text log, then use
stata_read_logto read it.Recommended rule: append within the same Claude/MCP session; overwrite the first time the same do file is run in a new session, so logs do not grow forever.
Troubleshooting
pywin32 is unavailable
Run:
pip install pywin32COM cannot create a Stata instance
Register Stata Automation again:
Start-Process -FilePath "D:\Stata18\StataMP-64.exe" -ArgumentList "/Register" -WaitDo not run the /Register command directly in Git Bash, because Git Bash may rewrite /Register as a path.
stata_run says there is no do-file session
Run a do file first:
stata_run_dofile(path="D:/Stata18/mcp/examples/browse_test.do")After that, pathless commands are sent to the most recent session.
Claude cannot directly see Stata GUI output
Claude cannot read screen contents directly. To let Claude analyze Stata output, write a Stata text log and read it with stata_read_log; or use stata_get_data_schema for a current data snapshot.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseNot gradedqualityAmaintenanceProvides a bridge between Stata statistical software and code editors like VS Code and Cursor, enabling users to run Stata commands directly from the editor, view output in real-time, and get AI-powered assistance with Stata coding.480MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to interact with Windows operating systems through native UI automation, file navigation, application control, and system commands. Provides seamless integration between LLMs and Windows environments for tasks like clicking, typing, launching apps, and capturing desktop state.MIT
- AlicenseNot gradedqualityCmaintenanceConnects AI agents to a local Stata installation, enabling execution of Stata code, data inspection, graph generation, and result verification through natural language interactions.77AGPL 3.0
- FlicenseAqualityDmaintenanceAn MCP server for managing, editing, and running Stata .do files, integrating with Claude Desktop to enable natural language control of Stata analysis on macOS.71
Related MCP Connectors
Control Unreal Engine to browse assets, import content, and manage levels and sequences. Automate…
Streamline your Attio workflows using natural language to search, create, update, and organize com…
Automate eSignature workflows and signing tasks via natural language commands.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/shichengg/stata-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server