Stata MCP Server
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Stata MCP Server Show me a list of all do files in the current directory"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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!
Related MCP server: Universal MCP Server
Installation complete โ
The installation is complete with the following configuration:
project path:
/users/username/projects/stata-mcp-serverStata path:
/Applications/Stata/StataBE.app/Contents/MacOS/StataBEWorking directory**:
/Users/username/Documents/StataCloud 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
extracts the specified line range
creates a temporary .do file (automatically adding the necessary settings)
run the temporary file in Stata
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
Not recognized by Cloud Desktop 1.
Restart Cloud Desktop completely
Check configuration file path:
/users/username/library/application support/Claude/claude_desktop_config.json
**Stata fails to run
Check Stata path:
/Applications/Stata/StataBE.app/Contents/MacOS/StataBECheck Stata license
**Permissions error
Check Documents/Stata directory permissions
Check file read/write permissions
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.
Available Tools
7 toolsbrowse_do_filesA
์ง์ ๋ ๋๋ ํ ๋ฆฌ์ do ํ์ผ ๋ชฉ๋ก ์กฐํ
Inputs: directory.
edit_do_fileC
do ํ์ผ์ ํน์ ๋ถ๋ถ ํธ์ง
Inputs: params (required), file_path (required), operation (required).
generate_do_templateB
LLM์ ํ์ฉํ do ํ์ผ ํ ํ๋ฆฟ ์์ฑ
Inputs: description (required), output_path (required).
read_do_fileC
๋ก์ปฌ ์ปดํจํฐ์ do ํ์ผ ์ฝ๊ธฐ
Inputs: file_path (required).
run_do_fileC
Stata์์ do ํ์ผ ์คํ
Inputs: file_path (required).
run_do_selected_linesB
do ํ์ผ์ ์ ํ๋ ๋ผ์ธ๋ค๋ง ์คํ
Inputs: end_line (required), file_path (required), start_line (required).
write_do_fileC
do ํ์ผ ์์ฑ ๋๋ ๋ฎ์ด์ฐ๊ธฐ
Inputs: content (required), file_path (required), create_backup.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogโฆ
TDQS
Scored across 7 tools
Each tool targets a distinct aspect of do file management: browsing directories, reading, writing, editing, generating templates, and running files or selected lines. There is minimal overlap between tools, and their purposes are clear from names and descriptions.
All tool names follow a consistent verb_noun pattern in snake_case (e.g., browse_do_files, run_do_file, generate_do_template). Naming conventions are uniform and predictable across the entire set.
With 7 tools, the server is well-scoped for its purpose of managing and executing Stata do files. Each tool covers a necessary function without redundancy or bloat.
The tool surface covers the full lifecycle of do file work: discover, view, create, edit, template, and run (both full and partial). There are no obvious gaps that would prevent an agent from completing typical Stata workflows.
Related MCP Connectors
Shared memory MCP server for Claude Code, Codex, Gemini CLI and Cursor. Cited, editable.
Connect ChatGPT and Claude to your Mac, Windows or Linux with secure MCP remote access.
MCP server unifying ERPs, CRMs, APIs and knowledge base for Claude, ChatGPT and Gemini.
Hosted SQL Server MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Related MCP Servers
- AlicenseAqualityAmaintenanceAn MCP server that lets Large Language Models interact with Stata software to perform regression analysis and other statistical operations.41,882 PyPI277AGPL 3.0
- FlicenseBqualityDmaintenanceMulti-mode MCP server supporting both Claude Desktop (STDIO) and OpenAI (HTTP/SSE) integrations with file operations including read, write, delete, and search capabilities.3-
- AlicenseAqualityBmaintenanceMCP server that gives Claude Desktop and other desktop MCP clients filesystem powersโread, write, edit, and manage files like AI coding assistants.1777 npm9MIT
- AlicenseNot gradedqualityCmaintenanceA cross-platform desktop MCP server that allows Codex and other MCP clients to execute tasks via the Claude Agent SDK, providing tools for code generation, file editing, and task management with session continuation.14MIT