mcp-stata 1.0.1__py3-none-any.whl
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.
Potentially problematic release.
This version of mcp-stata might be problematic. Click here for more details.
- mcp_stata/__init__.py +4 -0
- mcp_stata/discovery.py +124 -0
- mcp_stata/models.py +57 -0
- mcp_stata/server.py +202 -0
- mcp_stata/smcl/smcl2html.py +80 -0
- mcp_stata/stata_client.py +524 -0
- mcp_stata-1.0.1.dist-info/METADATA +240 -0
- mcp_stata-1.0.1.dist-info/RECORD +11 -0
- mcp_stata-1.0.1.dist-info/WHEEL +4 -0
- mcp_stata-1.0.1.dist-info/entry_points.txt +2 -0
- mcp_stata-1.0.1.dist-info/licenses/LICENSE +661 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mcp-stata
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: A lightweight Model Context Protocol (MCP) server for Stata. Execute commands, inspect data, retrieve stored results (`r()`/`e()`), and view graphs in your chat interface. Built for economists who want to integrate LLM assistance into their Stata workflow.
|
|
5
|
+
Project-URL: Homepage, https://github.com/tmonk/mcp-stata
|
|
6
|
+
Project-URL: Repository, https://github.com/tmonk/mcp-stata
|
|
7
|
+
Project-URL: Issues, https://github.com/tmonk/mcp-stata/issues
|
|
8
|
+
Author-email: Thomas Monk <t.d.monk@lse.ac.uk>
|
|
9
|
+
License-Expression: AGPL-3.0-or-later
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: ai,econometrics,llm,mcp,stata,statistics
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Requires-Dist: mcp[cli]>=1.0.0
|
|
21
|
+
Requires-Dist: pandas>=2.0.0
|
|
22
|
+
Requires-Dist: pydantic>=2.0.0
|
|
23
|
+
Requires-Dist: pystata>=0.0.1
|
|
24
|
+
Requires-Dist: stata-setup>=0.1.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: build>=1.3.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: hatch>=1.16.2; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: ruff>=0.4.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: twine>=6.2.0; extra == 'dev'
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# Stata MCP Server
|
|
35
|
+
|
|
36
|
+
A [Model Context Protocol](https://github.com/modelcontextprotocol) (MCP) server that connects AI assistants to a local Stata installation.
|
|
37
|
+
|
|
38
|
+
Built by <a href="https://tdmonk.com">Thomas Monk</a>, London School of Economics.
|
|
39
|
+
|
|
40
|
+
This server enables LLMs to:
|
|
41
|
+
- **Execute Stata code**: run any Stata command (e.g. `sysuse auto`, `regress price mpg`).
|
|
42
|
+
- **Inspect data**: retrieve dataset summaries and variable codebooks.
|
|
43
|
+
- **Export graphics**: generate and view Stata graphs (histograms, scatterplots).
|
|
44
|
+
- **Verify results**: programmatically check stored results (`r()`, `e()`) for accurate validation.
|
|
45
|
+
|
|
46
|
+
## Prerequisites
|
|
47
|
+
|
|
48
|
+
- **Stata 17+** (required for `pystata` integration)
|
|
49
|
+
- **Python 3.11+** (recommended)
|
|
50
|
+
- **uv** (recommended for install/run)
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
### Run as a published tool with `uvx`
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
uvx --from mcp-stata mcp-stata
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`uvx` is an alias for `uv tool run` and runs the tool in an isolated, cached environment.
|
|
61
|
+
|
|
62
|
+
> Tip: You can pin a version (example): `uvx --from mcp-stata==0.1.0 mcp-stata`
|
|
63
|
+
|
|
64
|
+
## Configuration
|
|
65
|
+
|
|
66
|
+
This server attempts to automatically discover your Stata installation (supporting standard paths and StataNow).
|
|
67
|
+
|
|
68
|
+
If auto-discovery fails, set the `STATA_PATH` environment variable to your Stata executable:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
# macOS example
|
|
72
|
+
export STATA_PATH="/Applications/StataNow/StataMP.app/Contents/MacOS/stata-mp"
|
|
73
|
+
|
|
74
|
+
# Windows example (cmd.exe)
|
|
75
|
+
set STATA_PATH="C:\Program Files\Stata18\StataMP-64.exe"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## IDE Setup (MCP)
|
|
79
|
+
|
|
80
|
+
This MCP server uses the **stdio** transport (the IDE launches the process and communicates over stdin/stdout).
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
### Claude Desktop
|
|
85
|
+
|
|
86
|
+
Open Claude Desktop → **Settings** → **Developer** → **Edit Config**.
|
|
87
|
+
Config file locations include:
|
|
88
|
+
|
|
89
|
+
* macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
90
|
+
* Windows: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
91
|
+
|
|
92
|
+
#### Published tool (uvx)
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"mcpServers": {
|
|
97
|
+
"stata": {
|
|
98
|
+
"command": "uvx",
|
|
99
|
+
"args": ["--from", "mcp-stata", "mcp-stata"],
|
|
100
|
+
"env": {
|
|
101
|
+
"STATA_PATH": "/Applications/StataNow/StataMP.app/Contents/MacOS/stata-mp"
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
After editing, fully quit and restart Claude Desktop to reload MCP servers.
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
### Cursor
|
|
113
|
+
|
|
114
|
+
Cursor supports MCP config at:
|
|
115
|
+
|
|
116
|
+
* Global: `~/.cursor/mcp.json`
|
|
117
|
+
* Project: `.cursor/mcp.json`
|
|
118
|
+
|
|
119
|
+
#### Published tool (uvx)
|
|
120
|
+
|
|
121
|
+
```json
|
|
122
|
+
{
|
|
123
|
+
"mcpServers": {
|
|
124
|
+
"stata": {
|
|
125
|
+
"command": "uvx",
|
|
126
|
+
"args": ["--from", "mcp-stata", "mcp-stata"],
|
|
127
|
+
"env": {
|
|
128
|
+
"STATA_PATH": "/Applications/StataNow/StataMP.app/Contents/MacOS/stata-mp"
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
### Windsurf
|
|
138
|
+
|
|
139
|
+
Windsurf supports MCP plugins and also allows manual editing of `mcp_config.json`. After adding/editing a server, use the UI’s refresh so it re-reads the config.
|
|
140
|
+
|
|
141
|
+
A common location is `~/.codeium/windsurf/mcp_config.json`.
|
|
142
|
+
#### Published tool (uvx)
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"mcpServers": {
|
|
147
|
+
"stata": {
|
|
148
|
+
"command": "uvx",
|
|
149
|
+
"args": ["--from", "mcp-stata", "mcp-stata"],
|
|
150
|
+
"env": {
|
|
151
|
+
"STATA_PATH": "/Applications/StataNow/StataMP.app/Contents/MacOS/stata-mp"
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
### Google Antigravity
|
|
161
|
+
|
|
162
|
+
In Antigravity, MCP servers are managed from the MCP store/menu; you can open **Manage MCP Servers** and then **View raw config** to edit `mcp_config.json`.
|
|
163
|
+
|
|
164
|
+
#### Published tool (uvx)
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"mcpServers": {
|
|
169
|
+
"stata": {
|
|
170
|
+
"command": "uvx",
|
|
171
|
+
"args": ["--from", "mcp-stata", "mcp-stata"],
|
|
172
|
+
"env": {
|
|
173
|
+
"STATA_PATH": "/Applications/StataNow/StataMP.app/Contents/MacOS/stata-mp"
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
### Visual Studio Code
|
|
183
|
+
|
|
184
|
+
VS Code supports MCP servers via a `.vscode/mcp.json` file. The top-level key is **`servers`** (not `mcpServers`).
|
|
185
|
+
|
|
186
|
+
Create `.vscode/mcp.json`:
|
|
187
|
+
|
|
188
|
+
#### Published tool (uvx)
|
|
189
|
+
|
|
190
|
+
```json
|
|
191
|
+
{
|
|
192
|
+
"servers": {
|
|
193
|
+
"stata": {
|
|
194
|
+
"type": "stdio",
|
|
195
|
+
"command": "uvx",
|
|
196
|
+
"args": ["--from", "mcp-stata", "mcp-stata"],
|
|
197
|
+
"env": {
|
|
198
|
+
"STATA_PATH": "/Applications/StataNow/StataMP.app/Contents/MacOS/stata-mp"
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
VS Code documents `.vscode/mcp.json` and the `servers` schema, including `type` and `command`/`args`.
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## Tools Available
|
|
210
|
+
|
|
211
|
+
* `run_command(code, raw=false)`: Execute Stata syntax. Returns a structured JSON envelope by default; set `raw=true` for plain stdout/stderr. `trace=true` temporarily enables `set trace on`.
|
|
212
|
+
* `load_data(source, clear=True, raw=false)`: Heuristic loader (sysuse/webuse/use/path/URL) with JSON envelope.
|
|
213
|
+
* `get_data(start, count)`: View dataset rows (JSON response, capped to 500 rows).
|
|
214
|
+
* `describe()`: View dataset structure.
|
|
215
|
+
* `codebook(variable, raw=false)`: Variable-level metadata (JSON envelope by default).
|
|
216
|
+
* `run_do_file(path, trace=false, raw=false)`: Execute a .do file with rich error capture (JSON by default).
|
|
217
|
+
* `export_graph(name)`: Export a graph as an image.
|
|
218
|
+
* `export_graphs_all()`: Export all in-memory graphs as base64-encoded PNGs (JSON response).
|
|
219
|
+
* `list_graphs()`: See available graphs in memory (JSON list with an `active` flag).
|
|
220
|
+
* `get_stored_results()`: Get `r()` and `e()` scalars/macros.
|
|
221
|
+
* `get_help(topic, plain_text=false)`: Returns Markdown-rendered Stata help (default). Use `plain_text=true` for stripped text. Falls back to the Stata online help URL if missing.
|
|
222
|
+
* `get_variable_list()`: JSON list of variables and labels.
|
|
223
|
+
|
|
224
|
+
## License
|
|
225
|
+
|
|
226
|
+
This project is licensed under the GNU Affero General Public License v3.0 or later.
|
|
227
|
+
See the LICENSE file for the full text.
|
|
228
|
+
|
|
229
|
+
## Error reporting
|
|
230
|
+
|
|
231
|
+
- All tools that execute Stata commands support JSON envelopes (`as_json=true`) carrying:
|
|
232
|
+
- `rc` (from r()/c(rc)), `stdout`, `stderr`, `message`, optional `line` (when Stata reports it), `command`, and a `snippet` excerpt of error output.
|
|
233
|
+
- Stata-specific cues are preserved:
|
|
234
|
+
- `r(XXX)` codes are parsed when present in output.
|
|
235
|
+
- “Red text” is captured via stderr where available.
|
|
236
|
+
- `trace=true` adds `set trace on` around the command/do-file to surface program-defined errors; the trace is turned off afterward.
|
|
237
|
+
|
|
238
|
+
## Logging
|
|
239
|
+
|
|
240
|
+
Set `STATA_MCP_LOGLEVEL` (e.g., `DEBUG`, `INFO`) to control server logging. Logs include discovery details (edition/path) and command-init traces for easier troubleshooting.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
mcp_stata/__init__.py,sha256=kJKKRn7lGuVCuS2-GaN5VoVcvnxtNlfuswW_VOlYqwg,98
|
|
2
|
+
mcp_stata/discovery.py,sha256=_tkZJyvYQujR4sEbbnKCWbs2l-gIfO6TZcdI6Xbdk94,4482
|
|
3
|
+
mcp_stata/models.py,sha256=mVRvZYZMeXf1o5MLcD0bSwd0xO16ldEWaY6qXsJehRc,1078
|
|
4
|
+
mcp_stata/server.py,sha256=uj6n8Uyo5L6_AUnYlKo3PS7bFwMYkQpg7Y0VefRmZuc,7392
|
|
5
|
+
mcp_stata/stata_client.py,sha256=4UmMa74HDKxDC9Y0viFyZrEXsUntBLWqOA3nU4jNvnM,20054
|
|
6
|
+
mcp_stata/smcl/smcl2html.py,sha256=wi91mOMeV9MCmHtNr0toihNbaiDCNZ_NP6a6xEAzWLM,2624
|
|
7
|
+
mcp_stata-1.0.1.dist-info/METADATA,sha256=tEWUYreccqVPe8YW2vfYi3lzr3jfLs3S7AilYFJFqfs,7736
|
|
8
|
+
mcp_stata-1.0.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
9
|
+
mcp_stata-1.0.1.dist-info/entry_points.txt,sha256=TcOgrtiTL4LGFEDb1pCrQWA-fUZvIujDOvQ-bWFh5Z8,52
|
|
10
|
+
mcp_stata-1.0.1.dist-info/licenses/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
|
|
11
|
+
mcp_stata-1.0.1.dist-info/RECORD,,
|