aigroup-stata-mcp 1.0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. aigroup_stata_mcp-1.0.6/.gitignore +60 -0
  2. aigroup_stata_mcp-1.0.6/LICENSE +21 -0
  3. aigroup_stata_mcp-1.0.6/PKG-INFO +347 -0
  4. aigroup_stata_mcp-1.0.6/README.md +317 -0
  5. aigroup_stata_mcp-1.0.6/pyproject.toml +58 -0
  6. aigroup_stata_mcp-1.0.6/src/stata_mcp/__init__.py +18 -0
  7. aigroup_stata_mcp-1.0.6/src/stata_mcp/cli/__init__.py +8 -0
  8. aigroup_stata_mcp-1.0.6/src/stata_mcp/cli/_cli.py +96 -0
  9. aigroup_stata_mcp-1.0.6/src/stata_mcp/core/__init__.py +14 -0
  10. aigroup_stata_mcp-1.0.6/src/stata_mcp/core/data_info/__init__.py +11 -0
  11. aigroup_stata_mcp-1.0.6/src/stata_mcp/core/data_info/_base.py +288 -0
  12. aigroup_stata_mcp-1.0.6/src/stata_mcp/core/data_info/csv.py +123 -0
  13. aigroup_stata_mcp-1.0.6/src/stata_mcp/core/data_info/dta.py +70 -0
  14. aigroup_stata_mcp-1.0.6/src/stata_mcp/core/stata/__init__.py +13 -0
  15. aigroup_stata_mcp-1.0.6/src/stata_mcp/core/stata/stata_controller/__init__.py +9 -0
  16. aigroup_stata_mcp-1.0.6/src/stata_mcp/core/stata/stata_controller/controller.py +208 -0
  17. aigroup_stata_mcp-1.0.6/src/stata_mcp/core/stata/stata_do/__init__.py +9 -0
  18. aigroup_stata_mcp-1.0.6/src/stata_mcp/core/stata/stata_do/do.py +177 -0
  19. aigroup_stata_mcp-1.0.6/src/stata_mcp/core/stata/stata_finder/__init__.py +9 -0
  20. aigroup_stata_mcp-1.0.6/src/stata_mcp/core/stata/stata_finder/base.py +294 -0
  21. aigroup_stata_mcp-1.0.6/src/stata_mcp/core/stata/stata_finder/finder.py +193 -0
  22. aigroup_stata_mcp-1.0.6/src/stata_mcp/core/stata/stata_finder/linux.py +43 -0
  23. aigroup_stata_mcp-1.0.6/src/stata_mcp/core/stata/stata_finder/macos.py +88 -0
  24. aigroup_stata_mcp-1.0.6/src/stata_mcp/core/stata/stata_finder/windows.py +191 -0
  25. aigroup_stata_mcp-1.0.6/src/stata_mcp/server/__init__.py +8 -0
  26. aigroup_stata_mcp-1.0.6/src/stata_mcp/server/main.py +153 -0
  27. aigroup_stata_mcp-1.0.6/src/stata_mcp/server/prompts/__init__.py +8 -0
  28. aigroup_stata_mcp-1.0.6/src/stata_mcp/server/prompts/core_prompts.py +122 -0
  29. aigroup_stata_mcp-1.0.6/src/stata_mcp/server/tools/__init__.py +10 -0
  30. aigroup_stata_mcp-1.0.6/src/stata_mcp/server/tools/core_tools.py +59 -0
  31. aigroup_stata_mcp-1.0.6/src/stata_mcp/server/tools/file_tools.py +163 -0
  32. aigroup_stata_mcp-1.0.6/src/stata_mcp/server/tools/stata_tools.py +221 -0
  33. aigroup_stata_mcp-1.0.6/src/stata_mcp/utils/Installer/__init__.py +7 -0
  34. aigroup_stata_mcp-1.0.6/src/stata_mcp/utils/Installer/installer.py +85 -0
  35. aigroup_stata_mcp-1.0.6/src/stata_mcp/utils/Prompt/__init__.py +74 -0
  36. aigroup_stata_mcp-1.0.6/src/stata_mcp/utils/Prompt/string.py +91 -0
  37. aigroup_stata_mcp-1.0.6/src/stata_mcp/utils/__init__.py +23 -0
  38. aigroup_stata_mcp-1.0.6/src/stata_mcp/utils/usable.py +244 -0
@@ -0,0 +1,60 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ dev/
7
+ wheels/
8
+ *.egg-info
9
+
10
+ # Virtual environments
11
+ .venv
12
+
13
+ # Environment variables
14
+ .env
15
+
16
+ # IDEs
17
+ .idea/
18
+ .vscode/
19
+
20
+ # OS X
21
+ *.DS_Store
22
+
23
+ # Config
24
+ config.py
25
+
26
+ # test
27
+ test/
28
+ tests/
29
+ *.test.*
30
+
31
+ # Logs
32
+ logs/
33
+ log/
34
+
35
+ # private
36
+ src_private/
37
+ private/
38
+ privates/
39
+ source/paper
40
+
41
+ # local file
42
+ *.local.*
43
+ local/
44
+
45
+ # temp files
46
+ tmp/
47
+ *.tmp
48
+ *.tmp.*
49
+
50
+ # releases
51
+ releases/
52
+
53
+ # backup
54
+ backup/
55
+ backup.*
56
+ *.backup
57
+ *.backup.*
58
+
59
+ # PyPI configuration
60
+ .pypirc
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Sepine Tam, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,347 @@
1
+ Metadata-Version: 2.4
2
+ Name: aigroup-stata-mcp
3
+ Version: 1.0.6
4
+ Summary: 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.
5
+ Author-email: jackdark425 <jackdark425@gmail.com>
6
+ License: MIT
7
+ License-File: LICENSE
8
+ Keywords: ai,data-analysis,mcp,model-context-protocol,stata,statistics
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Scientific/Engineering
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Requires-Python: >=3.11
20
+ Requires-Dist: mcp[cli]>=1.21.0
21
+ Requires-Dist: numpy>=1.24.0
22
+ Requires-Dist: openpyxl>=3.1.5
23
+ Requires-Dist: pandas>=2.3.0
24
+ Requires-Dist: pathvalidate>=3.3.1
25
+ Requires-Dist: pexpect>=4.9.0
26
+ Requires-Dist: pydantic>=2.0.0
27
+ Requires-Dist: python-dotenv>=1.1.1
28
+ Requires-Dist: requests>=2.31.0
29
+ Description-Content-Type: text/markdown
30
+
31
+ # aigroup-stata-mcp
32
+
33
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
34
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
35
+ [![MCP Protocol](https://img.shields.io/badge/MCP-Protocol-blueviolet)](https://spec.modelcontextprotocol.io/)
36
+ [![PyPI version](https://img.shields.io/pypi/v/aigroup-stata-mcp.svg)](https://pypi.org/project/aigroup-stata-mcp/)
37
+
38
+ 一个基于 Model Context Protocol (MCP) 的 Stata 集成服务器,允许 AI 助手执行 Stata 脚本、获取数据信息和运行统计分析。
39
+
40
+ ## 功能特性
41
+
42
+ ### 🚀 核心功能
43
+ - **Stata 脚本执行**: 执行 `.do` 文件并捕获日志输出
44
+ - **数据信息获取**: 支持 `.dta` 和 `.csv` 文件的描述性统计
45
+ - **Stata 命令帮助**: 获取 Stata 内置命令的帮助文档
46
+ - **SSC 包管理**: 从 SSC 仓库安装和管理 Stata 包
47
+ - **文件操作**: 创建、读取和写入 Stata 脚本文件
48
+
49
+ ### 🔧 技术特性
50
+ - **跨平台支持**: Windows、macOS 和 Linux
51
+ - **自动 Stata 检测**: 自动查找系统上的 Stata 安装路径
52
+ - **多传输协议**: 支持 stdio、SSE、HTTP 和 streamable-http
53
+ - **结构化输出**: 使用 Pydantic 模型提供类型安全的响应
54
+ - **多语言支持**: 中英文界面和提示
55
+
56
+ ### 📊 数据处理
57
+ - **数据格式支持**: Stata (.dta)、CSV (.csv) 文件
58
+ - **统计分析**: 描述性统计、变量分析
59
+ - **URL 数据源**: 支持从 URL 直接读取数据文件
60
+ - **智能编码检测**: 自动检测文件编码和分隔符
61
+
62
+ ## 快速开始
63
+
64
+ ### 系统要求
65
+
66
+ - **Python**: 3.11 或更高版本
67
+ - **Stata**: 已安装并配置好环境变量
68
+ - **MCP 客户端**: Claude Desktop、Cherry Studio 或其他兼容 MCP 的客户端
69
+
70
+ ### 安装
71
+
72
+ ```bash
73
+ # 使用 pip 安装
74
+ pip install aigroup-stata-mcp
75
+
76
+ # 或使用 uv 安装
77
+ uv add aigroup-stata-mcp
78
+
79
+ # 或使用 uvx 直接运行(无需安装)
80
+ uvx aigroup-stata-mcp
81
+ ```
82
+
83
+ ### 配置
84
+
85
+ #### Claude Desktop 配置
86
+
87
+ 在 Claude Desktop 配置文件中添加以下内容:
88
+
89
+ **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
90
+ **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
91
+
92
+ ```json
93
+ {
94
+ "mcpServers": {
95
+ "stata-mcp": {
96
+ "command": "uvx",
97
+ "args": ["aigroup-stata-mcp"],
98
+ "env": {
99
+ "STATA_CLI": "/path/to/your/stata/executable"
100
+ }
101
+ }
102
+ }
103
+ }
104
+ ```
105
+
106
+ #### 使用安装器
107
+
108
+ 项目提供了自动安装工具:
109
+
110
+ ```bash
111
+ # 检查系统兼容性
112
+ stata-mcp --usable
113
+
114
+ # 自动安装到 Claude Desktop
115
+ stata-mcp --install
116
+ ```
117
+
118
+ ## 可用工具
119
+
120
+ ### Stata 工具
121
+
122
+ #### `stata_do`
123
+ 执行 Stata do 文件并返回执行结果。
124
+
125
+ **参数:**
126
+ - `dofile_path`: do 文件路径
127
+ - `log_file_name`: 日志文件名(可选)
128
+ - `is_read_log`: 是否读取日志内容(默认: true)
129
+
130
+ **示例:**
131
+ ```stata
132
+ regress price mpg weight
133
+ outreg2 using "results", replace
134
+ ```
135
+
136
+ #### `get_data_info`
137
+ 获取数据文件的描述性统计信息。
138
+
139
+ **参数:**
140
+ - `data_path`: 数据文件路径
141
+ - `vars_list`: 变量列表(可选)
142
+ - `encoding`: 文件编码(默认: utf-8)
143
+ - `file_extension`: 文件扩展名(可选)
144
+ - `is_save`: 是否保存结果到文件(默认: true)
145
+
146
+ **支持格式:**
147
+ - Stata 文件 (.dta)
148
+ - CSV 文件 (.csv, .txt, .tsv)
149
+
150
+ #### `help`
151
+ 获取 Stata 命令的帮助文档。
152
+
153
+ **参数:**
154
+ - `cmd`: Stata 命令名称
155
+
156
+ **示例:**
157
+ ```stata
158
+ help regress
159
+ help summarize
160
+ ```
161
+
162
+ #### `ssc_install`
163
+ 从 SSC 仓库安装 Stata 包。
164
+
165
+ **参数:**
166
+ - `command`: 包名称
167
+ - `is_replace`: 是否替换已安装版本(默认: true)
168
+
169
+ ### 文件工具
170
+
171
+ #### `write_dofile`
172
+ 创建新的 Stata do 文件。
173
+
174
+ **参数:**
175
+ - `content`: Stata 代码内容
176
+ - `encoding`: 文件编码(默认: utf-8)
177
+
178
+ #### `append_dofile`
179
+ 向现有 do 文件追加内容或创建新文件。
180
+
181
+ **参数:**
182
+ - `original_dofile_path`: 原始 do 文件路径
183
+ - `content`: 要追加的 Stata 代码
184
+ - `encoding`: 文件编码(默认: utf-8)
185
+
186
+ #### `read_file`
187
+ 读取文件内容。
188
+
189
+ **参数:**
190
+ - `file_path`: 文件路径
191
+ - `encoding`: 文件编码(默认: utf-8)
192
+
193
+ #### `load_figure`
194
+ 加载图片文件。
195
+
196
+ **参数:**
197
+ - `figure_path`: 图片文件路径(支持 png、jpg 格式)
198
+
199
+ ### 核心工具
200
+
201
+ #### `mk_dir`
202
+ 安全创建目录。
203
+
204
+ **参数:**
205
+ - `path`: 目录路径
206
+
207
+ ## 可用提示
208
+
209
+ ### `stata_assistant_role`
210
+ 获取 Stata 助手角色定义提示。
211
+
212
+ **参数:**
213
+ - `lang`: 语言代码(en/cn,可选)
214
+
215
+ ### `stata_analysis_strategy`
216
+ 获取 Stata 分析策略指南。
217
+
218
+ **参数:**
219
+ - `lang`: 语言代码(en/cn,可选)
220
+
221
+ ### `results_doc_path`
222
+ 生成结果文档存储路径。
223
+
224
+ ## 项目结构
225
+
226
+ ```
227
+ stata_mcp/
228
+ ├── core/ # 核心功能模块
229
+ │ ├── data_info/ # 数据信息处理
230
+ │ │ ├── _base.py # 数据信息基类
231
+ │ │ ├── dta.py # Stata 文件处理
232
+ │ │ └── csv.py # CSV 文件处理
233
+ │ └── stata/ # Stata 集成
234
+ │ ├── stata_controller/ # Stata 会话控制
235
+ │ ├── stata_do/ # do 文件执行器
236
+ │ └── stata_finder/ # Stata 路径查找器
237
+ ├── server/ # MCP 服务器实现
238
+ │ ├── tools/ # MCP 工具定义
239
+ │ │ ├── core_tools.py # 核心工具
240
+ │ │ ├── file_tools.py # 文件工具
241
+ │ │ └── stata_tools.py # Stata 工具
242
+ │ ├── prompts/ # MCP 提示定义
243
+ │ └── main.py # 服务器主程序
244
+ ├── utils/ # 工具类
245
+ │ ├── Installer/ # 安装器
246
+ │ ├── Prompt/ # 提示管理
247
+ │ └── usable.py # 系统兼容性检查
248
+ └── cli/ # 命令行接口
249
+ ```
250
+
251
+ ## 开发指南
252
+
253
+ ### 环境设置
254
+
255
+ 1. 克隆仓库:
256
+ ```bash
257
+ git clone https://github.com/jackdark425/aigroup-stata-mcp.git
258
+ cd aigroup-stata-mcp
259
+ ```
260
+
261
+ 2. 安装开发依赖:
262
+ ```bash
263
+ pip install -e ".[dev]"
264
+ ```
265
+
266
+ 3. 运行测试:
267
+ ```bash
268
+ python -m pytest
269
+ ```
270
+
271
+ ### 添加新工具
272
+
273
+ 在 `src/stata_mcp/server/tools/` 目录下创建新的工具文件:
274
+
275
+ ```python
276
+ from mcp.server.fastmcp import Context, FastMCP
277
+ from pydantic import BaseModel, Field
278
+
279
+ class MyToolResult(BaseModel):
280
+ result: str = Field(description="Tool execution result")
281
+
282
+ def register_my_tools(server: FastMCP) -> None:
283
+ @server.tool()
284
+ def my_tool(ctx: Context, param: str) -> MyToolResult:
285
+ """Tool description."""
286
+ # Tool implementation
287
+ return MyToolResult(result="Success")
288
+ ```
289
+
290
+ 然后在 `src/stata_mcp/server/main.py` 中注册新工具。
291
+
292
+ ## 故障排除
293
+
294
+ ### 常见问题
295
+
296
+ 1. **Stata 未找到**
297
+ - 确保 Stata 已正确安装
298
+ - 手动设置 `STATA_CLI` 环境变量
299
+ - 使用 `stata-mcp --usable` 检查配置
300
+
301
+ 2. **权限错误**
302
+ - 确保对工作目录有读写权限
303
+ - 检查防火墙设置
304
+
305
+ 3. **编码问题**
306
+ - 指定正确的文件编码
307
+ - 使用 UTF-8 编码处理中文数据
308
+
309
+ ### 调试模式
310
+
311
+ 启用详细日志输出:
312
+
313
+ ```bash
314
+ stata-mcp --verbose
315
+ ```
316
+
317
+ ## 贡献指南
318
+
319
+ 我们欢迎贡献!请参阅 [CONTRIBUTING.md](CONTRIBUTING.md) 了解详细信息。
320
+
321
+ 1. Fork 项目
322
+ 2. 创建功能分支 (`git checkout -b feature/AmazingFeature`)
323
+ 3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)
324
+ 4. 推送到分支 (`git push origin feature/AmazingFeature`)
325
+ 5. 打开 Pull Request
326
+
327
+ ## 许可证
328
+
329
+ 本项目基于 MIT 许可证 - 查看 [LICENSE](LICENSE) 文件了解详细信息。
330
+
331
+ ## 致谢
332
+
333
+ - [Model Context Protocol](https://spec.modelcontextprotocol.io/) - 提供协议规范
334
+ - [Stata](https://www.stata.com/) - 统计分析软件
335
+ - [FastMCP](https://github.com/modelcontextprotocol/python-sdk) - Python MCP SDK
336
+
337
+ ## 支持
338
+
339
+ 如果您遇到问题或有建议,请:
340
+
341
+ 1. 查看 [问题页面](https://github.com/jackdark425/aigroup-stata-mcp/issues)
342
+ 2. 创建新的 issue
343
+ 3. 联系维护者: jackdark425@gmail.com
344
+
345
+ ---
346
+
347
+ **注意**: 本项目与 StataCorp LLC 无关,Stata 是 StataCorp LLC 的注册商标。