servers / stata-code

stata-code MCP server

communitystdiolocaldestructive capablehealthy

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 跨栈交叉验证。


01Tools · 18

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.

ToolRiskSide effectsApproval
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.
writetrueunknown
stata_info
Report installed Stata edition, version, backend, and whether the runtime is initialized.
readfalseunknown
list_sessions
Enumerate live sessions. Each entry has session_id, frame (Stata frame name), and n_obs.
readfalseunknown
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.
readfalseunknown
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.
destructivetruetrue
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}.
readfalseunknown
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}.
destructivetruetrue
get_graph
Fetch graph bytes behind a graph:// ref. Returns an ImageContent (base64 bytes + mimeType) suitable for direct display by vision-capable clients.
readfalseunknown
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.
unknownunknownunknown
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}.
readfalseunknown
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.
readfalseunknown
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'.
writetrueunknown
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.
readfalseunknown
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.
writetrueunknown
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.
readfalseunknown
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).
readfalseunknown
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.
readfalseunknown
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.
readfalseunknown

02Install & source
uvx --from stata-code[mcp] stata-code-mcp
uvx

05Provenance & freshness
sourcesGitHub repo search [p4]
last_checked2026-07-26 08:47Z
next_check2026-07-27 13:29Z
cadenceevery 29h
verifiedtools_list:passed handshake:passed metadata:passed
index_statusindex8 unique facts >= 5

06Badge

Add the “as seen on MCPExplorer” badge to your README. stata-code MCP — as seen on mcpexplorer.com

[![stata-code MCP — as seen on mcpexplorer.com](https://mcpexplorer.com/badge/stata-code.svg)](https://mcpexplorer.com/servers/stata-code)

Next step

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 →