Stata MCP Server

Stata MCP Server

An MCP server for managing, editing, and running Stata .do files, integrating with Claude Desktop to enable natural language control of Stata analysis on macOS.

Category
访问服务器

README

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

# 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 file

Develop

Script

npm run build # compile typescript
npm run dev # Development mode (watch)
npm run start # Start the server
npm run clean # Clean build files

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

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选