stata-code MCP server
Agent-native Stata bridge for empirical research — run DiD/IV/RDD and publication-ready tables from Claude Code, Jupyter, or VS Code on one token-economy result schema, with StatsPAI cross-validation. | 面向实证研究的智能体 Stata 桥接器——在 Claude Code、Jupyter、VS Code 中用一套省 token 的结果格式跑 DiD/IV/RDD 与出版级表格,并支持 StatsPAI 跨栈交叉验证。
How to read this: tool names here are observed from a live tools/list handshake. The Risk label is a heuristic inferred from the tool name (write/destructive verbs), not from executing the tool — a conservative guess, not a verified capability. We never escalate risk from a description. Found one that's wrong? Tell us — we fix on report.
| Tool | Risk | Side effects | Approval |
|---|---|---|---|
| stata_run Execute Stata code and return a v1.0 stata_code RunResult (see SCHEMA.md). The result is a JSON object with ok, rc, error (typed), log (head+tail+ref by default), results.r/e (scalars/macros/matrices, native types), dataset metadata, graphs, warnings, and capabilities. Use the structured fields rather than parsing the log. On ok=false, surface error.kind/message/line/suggestions. Use suggestions for iterative debug/fix loops only when the user asked for that or approved changes; for run/validate-only requests, report diagnostics without rewriting source code. | write | true | unknown |
| stata_info Report installed Stata edition, version, backend, and whether the runtime is initialized. | read | false | unknown |
| list_sessions Enumerate live sessions. Each entry has session_id, frame (Stata frame name), and n_obs. | read | false | unknown |
| notebook_get_cell Read one cell of a .ipynb by cell_id (preferred) or cell_index. Returns the cell's full source plus a token-economic outputs summary (count, types, whether an image is present, head/tail of stream/text outputs, error ename/evalue with truncated traceback). Read-only; does not execute or modify the notebook. | read | false | unknown |
| notebook_delete_cell Remove a cell by id. Returns the deleted cell's source so the caller can announce or undo. Optionally pass expected_source for optimistic-concurrency. | destructive | true | true |
| get_log Fetch the full log text behind a log:// ref returned by a prior stata_run call. Returns JSON {text, lines_total, bytes_total}. | read | false | unknown |
| cancel_session Request cancellation for this subprocess-backed session. If a run is in flight, the worker process is terminated; otherwise the flag is consumed by the next call and returns a RunResult with ok=false, rc=-3, error.kind='cancelled'. Returns JSON {session_id, was_pending, is_pending, killed_worker}. | destructive | true | true |
| get_graph Fetch graph bytes behind a graph:// ref. Returns an ImageContent (base64 bytes + mimeType) suitable for direct display by vision-capable clients. | read | false | unknown |
| reset_session Drop a session's data. session_id='main' performs `clear all` in place (default frame cannot be dropped); other names drop the corresponding Stata frame. | unknown | unknown | unknown |
| get_matrix Fetch a matrix's values, rows, and cols behind a matrix:// ref. Producers emit a ref instead of inlining values when the matrix exceeds ~10,000 cells. Returns JSON {rows, cols, values}. | read | false | unknown |
| notebook_outline Read a .ipynb file and return a compact per-cell index: cell_id (nbformat 4.5+ UUID, or a synthesized fallback for older notebooks), index, cell_type, source preview, line/char counts, execution_count, and whether outputs/error outputs are present. Read-only; does not execute or modify the notebook. Use this before notebook_get_cell to avoid pulling the full notebook into context. | read | false | unknown |
| notebook_insert_cell Insert a new cell with a fresh nbformat 4.5+ UUID. Pass exactly one anchor: after_cell_id, before_cell_id, at_start, or at_end. Default cell_type is 'code'. | write | true | unknown |
| notebook_locate Find cells in a .ipynb by content. Pass exactly one of snippet (literal substring with whitespace-tolerant fall-back), regex (Python regex, multiline), or error_text (pasted Stata/traceback text — the longest code-like line is used as a fingerprint). Returns up to `limit` candidates ranked by match score, each with cell_id, line_in_cell, and a short preview. Read-only. | read | false | unknown |
| notebook_edit_cell Atomically replace one cell's source. Preserves cell.id and metadata. For code cells, clears outputs and execution_count. Optionally pass expected_source for optimistic-concurrency: the call fails with 'edit_source_drift' if the on-disk source no longer matches. Writes the whole notebook via temp file + rename. Note: if the cell was addressed by a synthesised id (pre-nbformat-4.5 notebook), the cell is upgraded to a real UUID during this call. The old synth id is no longer valid — use the cell_id returned in this result for follow-up calls. | write | true | unknown |
| list_runs Query the on-disk run-bundle manifests under a log-files directory. Pass either log_dir directly or origin_path (then the dir is inferred as <origin_path parent>/log-files). Filters compose with AND: cell_id, session_id, ok, since (ISO 8601 UTC, lexicographic compare on started_at), limit, and offset. Read-only; never re-runs anything. Returns compact summaries newest-first; callers fetch the full manifest from the returned manifest_path if needed. | read | false | unknown |
| install_package Install a community-contributed Stata package (e.g. reghdfe, coefplot, estout, ftools) without the agent having to remember `ssc install` / `net install` syntax. Runs the install in the named session, then verifies the package resolves with `which`. Returns a compact JSON summary: {name, source, command, ok, verified, rc, stata, log, error}. On failure the typed error block (kind: network / permission / file_not_found / ...) is surfaced so the agent can react. Idempotent by default (replace). | read | false | unknown |
| search_log Grep within a `log://` payload returned by a truncated stata_run (log.ref). Returns only the matching lines (with optional surrounding context) instead of pulling the whole log back via get_log — the token-economy way to inspect a long log. Substring match by default; set is_regex=true for a Python regular expression. | read | false | unknown |
| inspect_data One-call 'what is in this dataset' for the in-memory data of a session. Runs `describe` + `codebook` (compact unless detail=true) and returns the structured dataset block (frame, n_obs, n_vars, variables) plus the codebook log so the agent does not have to remember the command. Branch on the structured `dataset` field; the `log` is human-oriented detail (head + ref). Read-only: it never modifies data. | read | false | unknown |
- repohttps://github.com/brycewang-stanford/stata-code
- licenseMIT
- adoption27 stars · 4 forks
Add the “as seen on MCPExplorer” badge to your README.
This is one server. A loadout combines the right servers, governance, and proven plays for a whole job — assembled deliberately, not tool-dumped.
Explore loadouts →