mcpField
S
Stata MCP Server (macOS)

Stata MCP Server (macOS)

本地服务
github.com/mkprevo数据与分析174 周前更新

关于 Stata MCP Server (macOS)

Stata MCP Server (macOS) 面向 Claude Desktop 用户,用于管理和运行 Stata .do 文件。它结合文件编辑与自动备份功能,并支持在 Stata 中运行整个文件或选定行。

主要功能

  1. 01列出、读取、写入和编辑 .do 文件
  2. 02修改文件时自动备份
  3. 03添加变量和分析代码段
  4. 04用 AI 生成 .do 文件模板
  5. 05在 Stata 中运行文件或选定行

适用场景

  1. 01创建 Stata 分析脚本
  2. 02带备份地编辑现有 .do 文件
  3. 03测试 Stata 脚本中的选定行

MCP 相关

它作为与 Claude Desktop 集成的 MCP 服务,提供 .do 文件管理和 Stata 执行工具。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

暂未收录安装方式

我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。

代码仓库

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

Stata MCP 服务(macOS)

一个用于管理和运行 Stata .do 文件的模型上下文协议(MCP)服务,可与 Claude Desktop 集成。

功能

📁 文件管理
  • BROOK_Do_FILES:获取目录中的 .do 文件列表
  • READ_FILE**:读取 .do 文件
  • WRITE_FILE**:创建或覆盖 .do 文件(支持自动备份)
✏️ 编辑文件
  • EDIT_FILE**:编辑 .do 文件的指定部分
    • 添加变量(add_variable)
    • 添加分析代码(add_analysis)
    • 插入自定义部分(insert_section)
🚀 自动化。
  • generate_do_template**:使用 AI 生成 .do 文件模板
  • run_do_file**:在 Stata 中运行 .do 文件(支持 macOS)
  • run_do_selected_lines**:仅运行选定的行 ⭐ 新增!

安装完成 ✅

安装已完成,配置如下:

  • 项目路径:/users/username/projects/stata-mcp-server
  • Stata 路径:/Applications/Stata/StataBE.app/Contents/MacOS/StataBE
  • 工作目录**:/Users/username/Documents/Stata
  • Cloud Desktop 设置**:/Users/username/Library/Application Support/Claude/claude_desktop_config.json

使用方法。

1. 重启 Claude Desktop

完全关闭并重启 Claude Desktop。

2. 在 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. 运行选定的行 ⭐

现在,你可以选择并仅运行 do 文件中的某些行:

"Run only lines 5 through 10 of the analysis.do file"
"Run only the data load part (lines 8-12) to test"

此功能的工作方式如下

  1. 提取指定的行范围
  2. 创建临时 .do 文件(自动添加所需设置)
  3. 在 Stata 中运行临时文件
  4. 返回结果后清理临时文件

do 文件模板结构。

/*******************************************************************************
* 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

测试

验证服务是否正常工作:

cd /users/username/projects/stata-mcp-server
echo '{"jsonrpc":"2.0","method":"tools/list","id":1}' | node dist/index.js

备份系统

  • 修改文件时自动创建备份
  • 备份位置:$STATA_WORKSPACE/.stata-backups/
  • 格式:文件名:filename.do.YYYY-MM-DDTHH-MM-SS-sssZ.bak

故障排除

常见问题
  1. Cloud Desktop 无法识别 1.

    • 完全重启 Cloud Desktop
    • 检查配置文件路径:/users/username/library/application support/Claude/claude_desktop_config.json
  2. **Stata 无法运行

    • 检查 Stata 路径:/Applications/Stata/StataBE.app/Contents/MacOS/StataBE
    • 检查 Stata 许可证
  3. **权限错误

    • 检查 Documents/Stata 目录权限
    • 检查文件读写权限
查看日志
# 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

开发

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

环境变量

  • STATA_PATH**:Stata 可执行文件路径
  • STATA_WORKSPACE**:Stata 工作目录

许可证

MIT 许可证。

---。

**由科学社会学研究团队创建 ❤️ ** **

恭喜你安装了 Stata MCP 服务! 🎉 。

重启 Claude desktop 并试用。

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。