Observed since 21 Oct, 10:51 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
A Stata integration server based on Model Context Protocol (MCP) that allows AI assistants to execute Stata scripts, fetch data information, and run statistical analysis.
一个基于 Model Context Protocol (MCP) 的 Stata 集成服务器,允许 AI 助手执行 Stata 脚本、获取数据信息和运行统计分析。
.do 文件并捕获日志输出.dta 和 .csv 文件的描述性统计# 使用 pip 安装
pip install aigroup-stata-mcp
# 或使用 uv 安装
uv add aigroup-stata-mcp
# 或使用 uvx 直接运行(无需安装)
uvx aigroup-stata-mcp
Stata-MCP 支持使用 TOML 格式的配置文件。配置文件位于项目根目录的 config.toml。
示例配置文件:
name = "aigroup-stata-mcp"
instructions = "Stata-MCP lets you and LLMs run Stata do-files and fetch results"
website_url = "https://github.com/jackdark425"
# Working directory for the server
# If not specified, will use default based on OS:
# - Linux/macOS: ~/Documents
# - Windows: %USERPROFILE%\Documents
# working_directory = "/path/to/working/directory"
# Path to Stata CLI executable
# If not specified, will auto-detect
# stata_cli = "/usr/local/stata/stata-mp"
你也可以通过 --config 参数指定自定义配置文件路径。
在支持 MCP 协议的 AI 客户端配置文件中添加以下内容:
通用配置格式:
{
"mcpServers": {
"stata-mcp": {
"command": "uvx",
"args": ["aigroup-stata-mcp"]
}
}
}
注意: 系统会自动识别 Stata 安装路径,通常无需手动配置。如果自动识别失败,可以通过设置
STATA_CLI环境变量指定 Stata 可执行文件路径。
不同客户端的配置文件位置可能不同,以下是一些常见客户端的配置文件位置:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json项目提供了自动安装工具:
# 检查系统兼容性
stata-mcp --usable
# 自动安装到 Claude Desktop
stata-mcp --install
stata_do执行 Stata do 文件并返回执行结果。
参数:
dofile_path: do 文件路径log_file_name: 日志文件名(可选)is_read_log: 是否读取日志内容(默认: true)示例:
regress price mpg weight
outreg2 using "results", replace
get_data_info获取数据文件的描述性统计信息。
参数:
data_path: 数据文件路径vars_list: 变量列表(可选)encoding: 文件编码(默认: utf-8)file_extension: 文件扩展名(可选)is_save: 是否保存结果到文件(默认: true)支持格式:
help获取 Stata 命令的帮助文档。
参数:
cmd: Stata 命令名称示例:
help regress
help summarize
ssc_install从 SSC 仓库安装 Stata 包。
参数:
command: 包名称is_replace: 是否替换已安装版本(默认: true)write_dofile创建新的 Stata do 文件。
参数:
content: Stata 代码内容encoding: 文件编码(默认: utf-8)append_dofile向现有 do 文件追加内容或创建新文件。
参数:
original_dofile_path: 原始 do 文件路径content: 要追加的 Stata 代码encoding: 文件编码(默认: utf-8)read_file读取文件内容。
参数:
file_path: 文件路径encoding: 文件编码(默认: utf-8)load_figure加载图片文件。
参数:
figure_path: 图片文件路径(支持 png、jpg 格式)mk_dir安全创建目录。
参数:
path: 目录路径stata_assistant_role获取 Stata 助手角色定义提示。
参数:
lang: 语言代码(en/cn,可选)stata_analysis_strategy获取 Stata 分析策略指南。
参数:
lang: 语言代码(en/cn,可选)results_doc_path生成结果文档存储路径。
stata_mcp/
├── core/ # 核心功能模块
│ ├── data_info/ # 数据信息处理
│ │ ├── _base.py # 数据信息基类
│ │ ├── dta.py # Stata 文件处理
│ │ └── csv.py # CSV 文件处理
│ └── stata/ # Stata 集成
│ ├── stata_controller/ # Stata 会话控制
│ ├── stata_do/ # do 文件执行器
│ └── stata_finder/ # Stata 路径查找器
├── server/ # MCP 服务器实现
│ ├── tools/ # MCP 工具定义
│ │ ├── core_tools.py # 核心工具
│ │ ├── file_tools.py # 文件工具
│ │ └── stata_tools.py # Stata 工具
│ ├── prompts/ # MCP 提示定义
│ └── main.py # 服务器主程序
├── utils/ # 工具类
│ ├── Installer/ # 安装器
│ ├── Prompt/ # 提示管理
│ └── usable.py # 系统兼容性检查
└── cli/ # 命令行接口
git clone https://github.com/jackdark425/aigroup-stata-mcp.git
cd aigroup-stata-mcp
pip install -e ".[dev]"
python -m pytest
在 src/stata_mcp/server/tools/ 目录下创建新的工具文件:
from mcp.server.fastmcp import Context, FastMCP
from pydantic import BaseModel, Field
class MyToolResult(BaseModel):
result: str = Field(description="Tool execution result")
def register_my_tools(server: FastMCP) -> None:
@server.tool()
def my_tool(ctx: Context, param: str) -> MyToolResult:
"""Tool description."""
# Tool implementation
return MyToolResult(result="Success")
然后在 src/stata_mcp/server/main.py 中注册新工具。
Stata 未找到
STATA_CLI 环境变量stata-mcp --usable 检查配置权限错误
编码问题
启用详细日志输出:
stata-mcp --verbose
我们欢迎贡献!请参阅 CONTRIBUTING.md 了解详细信息。
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)本项目基于 MIT 许可证 - 查看 LICENSE 文件了解详细信息。
如果您遇到问题或有建议,请:
注意: 本项目与 StataCorp LLC 无关,Stata 是 StataCorp LLC 的注册商标。
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 1.0.9 | 4 Dec 2025 | 11 |
This describes our collected data; it is not a security assessment.
Observed since 21 Oct, 10:51 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:ca59329c897da072d12ec2dc22b9aa3a4685dfd85617edd90a6cc03f99e0b0eb