使用说明
状态 MCP 服务器 (macOS)
一个模型上下文协议(MCP)服务器,用于管理和运行与Claude Desktop集成的Stata.do文件。
特性
📁 文件管理
- 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 - 路径状态:
/Applications/Stata/StataBE.app/Contents/MacOS/StataBE - 工作目录**:
/Users/username/Documents/Stata - 云桌面设置**:
/Users/username/Library/Application Support/Claude/claude_desktop_config.json
如何使用它。
1.重新启动克劳德桌面
完全关闭并重新启动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"
此功能的工作原理如下
- 提取指定的行范围
- 创建临时.do文件(自动添加必要的设置)
- 在Stata中运行临时文件
- 返回结果后清理临时文件
做文件模板结构。
/*******************************************************************************
* 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.
- 完全重新启动云桌面
- 检查配置文件路径:
/users/username/library/application support/Claude/claude_desktop_config.json
-
**Stata无法运行
- 检查状态路径 :
/Applications/Stata/StataBE.app/Contents/MacOS/StataBE - 检查许可证状态
- 检查状态路径 :
-
**权限错误
- 检查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_WORKSPACE**:STATA工作目录
许可证
MIT许可证。
---.
**由科学社会学研究团队创建❤️ ** **
恭喜您安装了Stata MCP服务器! 🎉 .
重新启动Claude桌面并尝试。
