stata-mcp-server
MCP server for stata do file
Documentation
Stata MCP Server (macOS)
A Model Context Protocol (MCP) server for managing and running Stata .do files that integrates with Claude Desktop.
Features
π File management
- BROOK_Do_FILES: Get a list of .do files in a directory
- READ_FILE**: Read a .do file
- WRITE_FILE**: Create or overwrite a .do file (supports automatic backup)
βοΈ Edit a file
- EDIT_FILE**: Edit a specific section of a .do file
- Add a variable (`add_variable`)
- Add analysis code (`add_analysis`)
- Insert a custom section (`insert_section`)
π Automation.
- generate_do_template**: Generate a .do file template using AI
- run_do_file**: Run a .do file in Stata (macOS support)
- run_do_selected_lines**: Run only selected lines β NEW!
Installation complete β
The installation is complete with the following configuration:
- project path: `/users/username/projects/stata-mcp-server`
- Stata path: `/Applications/Stata/StataBE.app/Contents/MacOS/StataBE`
- Working directory**: `/Users/username/Documents/Stata`
- Cloud Desktop Settings**: `/Users/username/Library/Application Support/Claude/claude_desktop_config.json`
How to use it.
1. Restart Claude Desktop
Completely shut down and restart Claude Desktop.
2. Enable in Claude Desktop
"Read the test.do file and show me"
"Create a do file that analyzes the relationship between education and income"
"Show me a list of all do files in the current directory"
"Add a logistic regression to the analysis.do file"
"Run only lines 10 through 15 of the test_sample.do file"
"Run only the regression part of the regression.do file separately"3. Run selected lines β
You can now select and run only certain lines of a do file:
"Run only lines 5 through 10 of the analysis.do file"
"Run only the data load part (lines 8-12) to test"This function works as follows
1. extracts the specified line range
2. creates a temporary .do file (automatically adding the necessary settings)
3. run the temporary file in Stata
4. clean up the temporary file after returning results
Do file template structure.
/*******************************************************************************
* Project: [Analysis Description]
* Created: [Current Date]
* Author: Stata MCP Server (LLM generation)]
* Purpose: [Analysis Purpose] [Analysis Purpose
*******************************************************************************/
* Initial Setup
Clear all
More settings
Close capture logs
Log using "logfile.log", replace
* Load data
* Use "your_data.dta", clear
* Verify data
ζθΏ°
summarize
* Create and preprocess variables
* generate new_var = .
* descriptive statistics
* tabulate var1
* main analysis
* regress Y X1 X2 X3
* save results
"results.doc" with * outreg2, replace
Close the log
exitTesting
Verify that the server is working properly:
cd /users/username/projects/stata-mcp-server
echo '{"jsonrpc":"2.0","method":"tools/list","id":1}' | node dist/index.jsBackup system
- Create automatic backups when files are modified
- Backup location: `$STATA_WORKSPACE/.stata-backups/`
- Format: Filename: `filename.do.YYYY-MM-DDTHH-MM-SS-sssZ.bak`
Troubleshooting
Common issues
1. Not recognized by Cloud Desktop 1.
2. **Stata fails to run
3. **Permissions error
Check the log
# Server logs
cd /users/username/project/stata-mcp-server
node dist/index.js 2> server.log
# Stata execution log
# .log files are generated with each .do fileDevelop
Script
npm run build # compile typescript
npm run dev # Development mode (watch)
npm run start # Start the server
npm run clean # Clean build filesEnvironment variables
- STATA_PATH**: Stata executable path
- STATA_WORKSPACE**: Stata working directory
License
MIT License.
---.
Created by the Sociology of Science Research Team β€οΈ **
Congratulations on your Stata MCP server installation! π .
Restart the Claude desktop and try it out.
Frequently asked questions
What is stata-mcp-server?
stata-mcp-server is MCP server for stata do file
How do I install stata-mcp-server?
Open the GitHub repository and follow its README. Most MCP servers are added to your client's MCP config, then called by your agent.
Is stata-mcp-server open source?
Yes β it is hosted on GitHub at https://github.com/mkprevo/stata-mcp-server and has 1 stars.
Related MCP tools
An MCP server that installs other MCP servers for you JavaScript-based implementation. Trusted by 1400+ developers. Trusted by 1400+ developers.
MCP server for interacting with the iOS simulator JavaScript-based implementation. Trusted by 1200+ developers. Trusted by 1200+ developers.
A Model Context Protocol server that provides read-only access to MySQL databases. This server enables LLMs to inspect database schemas and execute read-only...
This is an MCP server that allows you to directly download transcripts of YouTube videos. JavaScript-based implementation.
The all-in-one Desktop & Docker AI application with built-in RAG, AI agents, No-code agent builder, MCP compatibility, and more.
An AI-powered task-management system you can drop into Cursor, Lovable, Windsurf, Roo, and others. Built for the Model Context Protocol to enhance AI capabiliti
Run your own MCP server? See who uses it and what to fix.
Measure it with TrackMCP