Stata MCP Server (macOS)

by mkprevo

360 downloads
Not rated
GitHub

About

A Model Context Protocol (MCP) server for managing and running Stata .do files, integrated with Claude Desktop. It is built for macOS users who want to interact with Stata through natural language commands via Claude.

Details

Author
mkprevo
Downloads
360
Categories
Other

- List .do files in a directory
- Read and write .do files with automatic backup
- Edit specific sections: add variables, analysis, or custom inserts
- Generate .do file templates using AI
- Run entire .do files or selected lines only

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name Stata MCP Server (macOS)
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

After installing, restart Claude Desktop completely. Then use natural language prompts such as “Read the test.do file and show me” or “Run only lines 10 through 15 of the test_sample.do file.” The server supports reading, writing, editing, generating templates, and executing .do files or selected line ranges. Configuration is stored in the Claude Desktop settings file.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "stata mcp server (macos)": {
            "stata-mcp-server": {
                "command": "node",
                "args": [
                    "dist/index.js",
                    "2>",
                    "server.log"
                ]
            }
        }
    }
}

McpServers

{
    "stata-mcp-server": {
        "command": "node",
        "args": [
            "dist/index.js",
            "2>",
            "server.log"
        ]
    }
}

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
exit

Testing

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.js

Backup 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.
- Restart Cloud Desktop completely
- Check configuration file path: /users/username/library/application support/Claude/claude_desktop_config.json

2. Stata fails to run
- Check Stata path: /Applications/Stata/StataBE.app/Contents/MacOS/StataBE
- Check Stata license

3. **Permissions error
- Check Documents/Stata directory permissions
- Check file read/write permissions

Check the log

```bash

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.