stata-mcp
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@stata-mcpLoad auto.dta and run regress mpg weight; give me the coefficient table."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
stata-mcp
A Windows-first, production-oriented Stata execution server for LLM / agent applications (Model Context Protocol). 面向 LLM/agent 应用、Windows 优先的 Stata 执行工具服务器(MCP)。
GitHub · MIT License · Python 3.12 · Stata 17+ (pystata)
It embeds pystata (Stata 17+) in-process and exposes Stata as machine-readable MCP tools: run code, load data, inspect data, read structured results, export graphs, background long jobs with interruption, data preview and command help. 它进程内嵌 pystata,把 Stata 暴露成一组机器可读的 MCP 工具:执行代码、载入数据、查看数据、读结构化结果、导出图、后台长任务与中断、数据预览、命令帮助。
Built after a code-level review of the 4 mainstream open-source Stata MCP projects (tmonk/mcp-stata, SepineTam/mcp-for-stata, haoyu-haoyu/stata-ai-fusion, hanlulong/stata-mcp), to close their shared gaps. Passed 7 rounds of adversarial audit (167 tests). 本仓库是在代码级调研 4 个主流开源 Stata MCP 之后自研的,用于补它们共同的缺口;历经 7 轮对抗式审计(167 个测试全绿)。
1. Features / 特性
EN | CN |
Universal structured results — any e-class estimation command ( | 通用结构化结果——任意估计命令自动产出回归 JSON(系数/se/t/p/ci、N、r2、全量 e() 标量),无需枚举命令名。 |
Session isolation + self-healing — each session is a worker subprocess; lazy start, idle reclamation, crash auto-rebuild, Windows Job Object kills orphans on parent death (no license leak). | 会话隔离 + 自愈——每会话一个 worker 子进程;懒启动、空闲回收、崩溃自动重建;父进程死亡时 Windows Job Object 自动清理孤儿进程(防 license 泄漏)。 |
Provenance / reproducibility — every result carries | 来源追溯 / 可复现——每个结果带 command_hash、数据指纹、执行序号和可复现的 do_file。 |
Command journal + replay — session keeps a command log; on crash/reset it returns the history so an agent can rebuild state. | 命令日志 + 重放——会话保留命令日志;崩溃/重置时随结果返回历史,供 agent 重建状态。 |
Rich error object — unified | 统一错误对象——error(command_failed/timeout/crashed/start_failed)+ rc + error_class + session_reset + replay。 |
Background tasks — submit a long command, poll status, interrupt; per-session routing; bounded table (TTL/caps). | 后台任务——提交长命令、轮询状态、可中断;按会话路由;任务表有界(TTL/上限)。 |
Multi-session routing — real | 多会话路由——session_id 端到端贯通(schema→解析→后台),严格校验(非法不再静默回退)。 |
Security — variable-name whitelist, path auditor (fail-closed), restricted mode, DNS-aware SSRF guard on URLs. | 安全——变量名白名单、路径审计(fail-closed)、受限模式、URL 的 DNS-aware SSRF 守卫。 |
Graphs back to agent — exported images returned as base64 | 图直接给 agent——导出图片以 base64 ImageContent 返回(多模态 agent 能直接看到)。 |
Chinese-Windows tuned — UTF-8 primary with GBK fallback, forward-slash Stata paths, Chinese filenames tested. | 中文 Windows 适配——UTF-8 主路 + GBK 回退、Stata 正斜杠路径、中文文件名实测。 |
Pluggable — Backend / Tool / ResultParser registries; swap driver = one assembly point. | 可插拔——Backend / Tool / ResultParser 注册表;换驱动只改一处装配。 |
Related MCP server: MCP Python Interpreter
2. Strengths vs. open-source alternatives / 相对开源的优点
Structured results, not log text. All 4 OSS projects return cleaned log text; this one returns regression JSON straight from Stata memory (
sfi+ Mata), generic over every estimation command. 结构化结果而非 log 文本:4 个开源项目都只回清洗文本;本项目用 sfi+Mata 直读内存产出回归 JSON,对任意估计命令通用。Survives Windows. Orphan-process and license-leak handling, crash fail-fast, GBK-aware — where others ship Unix-only assumptions or half-baked Windows. Windows 上真正能跑:孤儿进程/license 泄漏处理、崩溃 fail-fast、GBK 适配——其它项目多带 Unix 假设或 Windows 半成品。
Reliability as a feature. Worker ready-handshake, per-command timeout + alive-poll (no 300s hangs), replay on reset. 可靠性当功能做:worker 启动握手、超时 + 存活轮询(不再 300s 干等)、重置带重放。
Thin by design. ~3.7k lines vs mcp-stata's 8.6k+; no UI-HTTP channel, no Rust, no research-orchestration bloat. 刻意做薄:约 3.7k 行 vs mcp-stata 8.6k+;不带 UI-HTTP 通道、Rust、研究编排膨胀。
Honest about limits. It documents what it is NOT (a sandbox; see §4/§7). 对边界诚实:明确写出它"不是"什么(沙箱;见 §4/§7)。
3. Honest limitations / 诚实的劣势
EN | CN |
restricted mode is NOT a sandbox — it is a best-effort "command whitelist + path audit" injection interceptor. Stata's syntax surface (frame prefix, | 受限模式不是沙箱——它是尽力而为的"命令白名单 + 路径审计"注入拦截器。Stata 语法面(frame 前缀、command()、宏、#delimit)无法被完整静态解析。对真正不可信的内容,正确做法是根本不提供自由代码执行(只用白名单结构化工具)。 |
URL guard cannot stop DNS-rebinding end-to-end — static + DNS-resolution filtering is a pre-filter; full defense needs connection-layer re-validation (trusted download/proxy). | URL 守卫无法端到端防 DNS rebinding——静态 + DNS 解析过滤只是前置;完整防御需连接层二次校验(可信下载/代理)。 |
stdio only (single client) — no HTTP transport yet (official mcp 2.x supports it; not wired in). | 只有 stdio(单客户端)——暂无 HTTP 传输(官方 mcp 2.x 支持,未接入)。 |
One machine / one process model — sessions are local workers; no remote serving, no multi-user auth. | 单机/单进程模型——会话是本机 worker;无远程服务、无多用户鉴权。 |
Requires licensed local Stata 17+ and per-session license seats; real-engine tests need Stata present (CI mock-only). | 需本地正版 Stata 17+ 且每会话占一个 license 席位;真引擎测试需本机有 Stata(CI 仅跑 mock)。 |
pystata/embedded coupling — depends on Stata's pystata; Windows-only tested, macOS/Linux untested. | 与 pystata/内嵌耦合——依赖 Stata 的 pystata;仅 Windows 实测,macOS/Linux 未测。 |
Output capture is in-process stdout swap — fine for MCP (fd-based), but background tasks can't interleave other threads' prints. | 输出捕获是进程内 stdout 交换——对 MCP 无碍(基于 fd),但后台任务期间其他线程 print 会被占用。 |
4. Security posture / 安全定位
L1 variable-name whitelist; L3 centralized path auditor (fail-closed); URL guard (https, no IP-literal/userinfo/localhost, DNS-resolve rejects private/loopback, optional host whitelist).
restricted mode (
stata_run(restricted=true)orsecurity.restricted_mode=true): command whitelist for in-memory analysis on already-loaded data; blocks shell/erase, externaldo/run/include, network imports (webuse,import fred/haver), nested-command carriers (frame:/table, command()), macro/compound-quote paths, and out-of-directory file access. Best-effort, not a sandbox. Load data throughstata_load_data, not free code.Audit log records each tool call (code hashed, not stored raw); privacy-hashed diagnostics.
中文:L1 变量名白名单;L3 集中路径审计(fail-closed);URL 守卫(强制 https、拒 IP/userinfo/localhost、DNS 解析拒私网/回环、可选域名白名单)。restricted 模式 = 对"已载入内存的数据"做分析的命令白名单;拦 shell/erase、外部 do/run/include、网络 import、嵌套命令载体(frame:/table, command())、宏/复合引号路径、目录外读写。尽力而为,非沙箱。载数据请走 stata_load_data,别用自由代码。
5. Requirements / 环境
Windows (tested on Windows 11) · Stata 17+ with pystata (
utilities/pystata) · Python 3.12+ · dep: only officialmcp中文 Windows 同样支持(编码与中文文件名已测)。
6. Install / 安装
pip install -e .
python -m stata_mcp.serverStata 根目录默认 C:\Program Files\Stata18,可用环境变量 STATA_HOME 覆盖。Lazy start:列工具不占 license,首次执行才拉起引擎。
7. Claude Code
claude mcp add stata-mcp -- python -m stata_mcp.server或 .mcp.json 的 stdio 配置(见仓库 config 示例)。Most tools accept session_id to target a session.
8. Tools / 工具(10)
Tool | 说明 |
| 执行代码;自动附结构化回归 JSON + provenance;后台执行返回 job_id |
| 载入 dta/csv/xlsx(路径审计,限授权目录) |
| describe/summarize/codebook(变量名白名单) |
| 读 e()/r() 结构化 + 数据形状 |
| 读数据集前 N 行(结构化二维数组) |
| 导出图,base64 ImageContent 直接回给 agent |
| 查 Stata 官方帮助(.sthlp) |
| 会话命令日志(重放原料) |
| 打断指定会话当前命令 |
| 后台任务状态/结果(全局 job 查询) |
9. Structured result example / 结构化结果示例
{"cmd":"regress","depvar":"mpg","N":74.0,"r2":0.6515,
"coefs":[{"var":"weight","coef":-0.0060,"se":0.0005,"t":-11.6,"p":1e-18,"ci":[...]}],
"scalars":{...},
"provenance":{"command_hash":"...","data_signature":"74:12(71728):...","exec_seq":2,
"do_file":"sysuse auto, clear\nregress mpg weight"}}通用机制:判 e(b) 存在即可提取,任意估计命令自动覆盖;e() 全量标量通用抓取;provenance 供 agent"数值接地"。
10. Architecture / 架构
server.py MCP stdio;make_context() 装配;审计日志
session.py Session(懒启动 worker 代理)+ SessionManager(上限/回收/自愈/Job Object)+ 命令日志
stata/worker.py worker 子进程(引擎+执行+结构化+break 线程+孤儿看门狗+ready 握手)
results/ 通用系数提取 + 会话快照 + 数据预览(sfi 直读 + Mata 统计量)
guard/ L1 白名单 + L3 路径审计 + restricted(命令白名单注入拦截器)
platform/job.py Windows Job Object(父死子亡)
tools/ 10 个工具 @register;tasks.py 后台任务表(有界)抽象可插拔:ExecutionBackend / Tool / ResultParser。详见 ARCHITECTURE.md、DESIGN.md(含全部踩坑与每轮审计记录)。
11. Testing / 测试
python -m unittest discover -s tests -t . # 167 用例(mock + 真引擎回归;无 Stata 也跑 mock)
python -m unittest tests.test_real_stata -v # 真引擎正确性:比对我们结构化提取 vs Stata 官方数值7 轮对抗式审计 + 每轮回归锁死,过程记在 DESIGN.md(§27a–27h)。
12. Known boundaries / 已知边界(诚实声明)
restricted 非沙箱(见 §3/§4);DNS rebinding 需连接层兜底。
会话状态在内存;跨进程重启的持久化归上层(agent 台账)。
macOS/Linux 未实测;无 CI(真引擎需 Stata license)。
License
MIT —— 自研;仅借鉴开源项目的思路(代码级调研,未复制其实现)。
Available Tools
10 toolsstata_breakA
打断指定会话正在运行的 Stata 命令(若有);打断后命令 rc=1,引擎存活可继续。
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | No | 要打断的会话标识;省略用 'default'。 |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the full behavioral burden and states the key side effect (interrupted command rc=1) and the post-condition (engine remains alive and usable). It does not disclose what happens when no command is running, which is a minor gap.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
A single, well-structured sentence that front-loads the action, then states the condition and consequences. No wasted words.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
The tool is simple with one optional parameter and no output schema, and the description covers the core operation. However, it does not mention the return behavior of the tool or the no-running-command case, leaving those details undocumented.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100% and the schema already documents session_id's meaning and default ('default'). The description only repeats '指定会话' without adding extra semantic value, matching the baseline of 3.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description uses a specific verb ('打断'/'interrupt') and a concrete resource ('指定会话正在运行的 Stata 命令'), which clearly identifies the tool's action. It is easily distinguishable from sibling tools like stata_run or stata_get_results.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The phrase '若有' indicates the tool should be used when a Stata command is currently running in a session, giving clear contextual guidance. It does not mention alternatives or exclusions, but the use case is unambiguous.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
stata_data_rowsA
返回当前数据集前 N 行(结构化二维数组),供 agent 直接查看数据。
| Name | Required | Description | Default |
|---|---|---|---|
| rows | No | 要读的行数(1-50,默认 10)。 | |
| session_id | No | 会话标识;省略用 'default'。 |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full behavioral burden. It correctly implies a read-only retrieval and specifies the output shape, but it does not disclose what happens when no dataset is loaded, whether session state is affected, or how errors are surfaced.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single compact sentence that front-loads the action, target resource, and return format. Every part contributes useful information, with no filler or redundant repetition of the tool name.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a simple read-only row-fetching tool, the description covers the essential purpose and return format, while the schema covers parameters. It does not mention prerequisites such as having a dataset loaded or error behavior, but these are minor for a tool of this simplicity.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The input schema documents both parameters fully, including constraints, defaults, and meaning (rows 1-50 default 10, session_id defaults to 'default'). The description adds no additional parameter semantics, so the schema-based baseline of 3 is appropriate.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Description states a specific verb (返回) and resource (当前数据集前 N 行), and even clarifies the return format as a structured two-dimensional array. It is clear about what the tool does, though it does not explicitly differentiate it from sibling tools like stata_inspect_data.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The phrase '供 agent 直接查看数据' implies this is the tool to use when the agent needs to view the dataset rows directly. However, there is no explicit guidance about when to choose this tool over alternatives, nor any exclusions or prerequisites.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
stata_export_graphB
把内存中的图导出为图片文件,返回绝对路径(正斜杠)与大小。
| Name | Required | Description | Default |
|---|---|---|---|
| name | No | 要导出的图名(graph dir 里列出的名字,如 Graph / g1);省略 = 当前图。 | |
| format | No | 导出格式:png / svg / pdf。 | png |
| filename | No | 输出文件名(不含目录,不含路径分隔符);省略则自动生成。 | |
| session_id | No | 会话标识;省略用 'default'。 |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
没有提供注释,描述应承担完整的行为披露负担。它只说明了导出并返回路径和大小,但未提及文件覆盖行为、错误条件(如无图时)、默认文件名生成或会话的作用。这些缺失的信息对安全调用该工具很重要。
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
一句话包含核心操作和返回值信息,没有冗余。信息前置,简洁高效。
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
在缺少注释和输出模式的情况下,描述提供了基本功能但未覆盖关键行为细节(如默认文件名、覆盖、错误处理)。对于只有4个可选参数的工具来说不算严重缺陷,但可以让调用者更好地准备依赖默认行为。
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
输入模式覆盖率为100%,所有参数在模式中都有描述,包括枚举、默认值和说明。描述本身没有添加额外的参数语义,因此根据基线规则打3分。
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
描述明确说明了动作(导出)、资源(内存中的图)和结果(图片文件,返回路径和大小)。这使它有别于运行或获取结果的兄弟工具。唯一小的不足是“图”没有进一步说明,但总体上足够清晰。
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
描述未提供任何何时使用、何时不用或替代方案的指导。没有提及前置条件(如必须存在图)或与兄弟工具的比较,只能依赖工具名称和语义推断用途。
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
stata_get_helpA
查 Stata 官方帮助(纯文本,从 .sthlp 读)——agent 不必瞎猜命令语法。
| Name | Required | Description | Default |
|---|---|---|---|
| topic | Yes | 要查询的 Stata 命令/主题(如 regress、xtreg、ereturn)。 | |
| session_id | No | 会话标识;省略用 'default'。 |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
There are no annotations, so the description carries the full burden. It discloses the source (.sthlp) and output format (plain text), which is useful. However, it does not describe failure behavior, session dependencies, or whether any state is changed. For a read-only help lookup this is a mild gap, not a contradiction.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The entire description is a single, front-loaded sentence with no filler. It conveys the core function, the output format, and the practical rationale in just a few words.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a simple two-parameter tool with no output schema, the description plus fully documented schema provide enough for an agent to call it correctly. It lacks edge-case information like unknown topics or session requirements, but overall it is adequately complete for the tool's simplicity.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so the schema already documents both 'topic' and 'session_id' adequately. The description adds no parameter-specific detail beyond the schema, so the baseline score of 3 is appropriate.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states a specific verb ('查' / query) and resource ('Stata 官方帮助'), and adds the output format ('纯文本,从 .sthlp 读'). It does not explicitly name or contrast with sibling tools, so it stops short of full sibling differentiation.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The phrase 'agent 不必瞎猜命令语法' gives a clear context for when to use this tool: before running a Stata command when syntax is uncertain. It does not explicitly state when not to use it or name alternative tools, but the usage context is clear.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
stata_get_resultsA
返回当前会话内存里的估计(e())/描述统计(r())/形状 结构化结果(只读)。
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | No | 会话标识;省略用 'default'。 |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the disclosure burden. It explicitly states the tool is read-only and draws from session memory, which covers the main safety trait. However, it does not mention what happens when no results exist, whether a session must first be active, or that results may be overwritten by later commands.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is one dense sentence that front-loads the purpose, the data source, and the read-only nature. Every phrase earns its place with no repetition or filler.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a simple, optional-parameter read-only retrieval tool, the description gives enough information about what is returned and where it comes from. It does not fully explain the result structure, but the absence of an output schema and the low complexity keep this from being a major gap.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 100% and the single session_id parameter is already well documented in the schema. The description adds no parameter-specific meaning, but none is really needed; baseline 3 is appropriate.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description uses a specific verb ('返回') and names a distinct resource: in-memory e()/r()/shape structured results in the current session. This clearly separates it from tools like stata_get_help and stata_session_history, though it does not name a sibling explicitly.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The phrase '当前会话内存' implies it should be used after running Stata commands that produce e() or r() results, but it does not explicitly state when to use it versus alternatives or include exclusions. The usage context is inferable but not fully spelled out.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
stata_inspect_dataA
查看当前数据:describe/summarize/codebook,可限定变量名列表。 返回命令的清洗输出;summarize(单变量)或 describe 附结构化结果。
| Name | Required | Description | Default |
|---|---|---|---|
| action | No | describe: 变量清单(短版);summarize: 描述统计;codebook: 变量编码簿(compact)。 | describe |
| variables | No | 要查看的 Stata 变量名列表;省略/空列表 = 全部变量。名字须为合法 Stata 变量名(字母/下划线开头,长度 1–32)。 | |
| session_id | No | 会话标识;省略用 'default'。 |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are present, so the description must carry the burden. It discloses output behavior: cleaned output, and structured results for summarize/describe. The word '查看' (view) implies read-only inspection, but the description does not explicitly state non-modification, prerequisites like loaded data, or how session_id affects behavior.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Two short sentences with no filler. The core purpose is front-loaded ('查看当前数据'), followed by the available actions and output characteristics. Every phrase contributes useful information.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a 3-parameter tool with no output schema, the description plus a complete schema covers the purpose, parameters, and return behavior adequately. Minor ambiguities remain around '清洗输出' and the exact meaning of 'summarize(单变量)', but they do not prevent correct invocation.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so the baseline is 3. The description adds little beyond the schema; '可限定变量名列表' mirrors the variables parameter, and the action enum is fully documented in the schema with clear per-option explanations.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool lets you 'inspect current data' via describe/summarize/codebook with an optional variable list. The output note about cleaned and structured results helps distinguish it from a generic command runner like stata_run, though it does not explicitly name sibling tools.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The opening phrase '查看当前数据' gives a clear usage context: use this when you need to inspect the current dataset. The three enumerated actions define its scope. However, it does not mention when not to use it or suggest alternatives like stata_run for arbitrary commands.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
stata_load_dataA
载入数据集到 Stata 内存:本地 .dta/.csv/.xlsx(须在工作目录或授权目录内) 或 https URL。返回载入命令的清洗输出与 {source, N, k} 结构化形状。
| Name | Required | Description | Default |
|---|---|---|---|
| clear | No | true 时用 `, clear` 无条件覆盖内存中已有数据;false(默认)时若当前数据未保存,Stata 可能拒绝覆盖。仅影响 .dta。 | |
| source | Yes | 要加载的数据文件路径或 https URL(.dta/.csv/.xlsx/.xls)。本地路径必须位于服务器工作目录或 [security].allowed_data_dirs 之内;路径不含双引号。 | |
| session_id | No | 会话标识;省略用 'default'。 |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of disclosing behavior. It does mention the return value (cleaned output and {source, N, k}), and the act of 'loading into memory' implies a session state change. Yet it does not explicitly disclose the risk of overwriting unsaved data or that the operation mutates the Stata session; this side-effect detail is only present in the schema's clear parameter, not in the description itself.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, compact piece of prose that front-loads the primary action and resource, then states the return shape. Every sentence contributes useful information with no filler, repetition, or unnecessary caveats.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a tool with three parameters, no output schema, and no annotations, the description covers the core invocation details: what data sources are allowed, that it returns structured output, and what that output looks like. It does not explain session_id semantics, but the schema covers that, and the absence of an output schema is compensated by the explicit return shape. The missing explicit mention of memory-replacement side effects is a minor gap.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so the baseline is 3. The description adds no parameter-level meaning beyond what the schema already provides; it summarizes the domain but does not clarify any parameter details beyond the schema's own descriptions. This is acceptable because the schema covers all parameters thoroughly.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description states a specific verb ('载入' / load), a clear resource ('数据集到 Stata 内存'), and enumerates supported formats and sources (.dta/.csv/.xlsx/.xls, local or https URL). It also mentions the return shape, making the tool's purpose unmistakable and easily distinguishable from sibling tools like stata_inspect_data or stata_run.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description gives clear context about what this tool is for and places constraints on where files must live (working directory or authorized directories), which helps an agent decide if it can use it. However, it does not explicitly state when to prefer this over alternatives or when not to use it, leaving the selection logic partially implicit.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
stata_runA
执行一段 Stata 代码(保持会话状态),返回清洗后的输出文本与 rc。
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | 要交给 Stata 执行的命令或代码块(多行可包含循环/临时变量,共享同一持久会话的内存状态)。 | |
| background | No | true 时命令在后台执行、立即返回 job_id,用 stata_task_status 轮询结果、stata_break 打断;false(默认)同步执行。长命令(bootstrap/混合模型等)建议用 true。 | |
| restricted | No | 受限模式:拦截 shell 逃逸(shell/winexec/!)、文件删除(erase)、越权文件路径。省略用 config[security].restricted_mode(默认 false)。 | |
| session_id | No | 会话标识;省略用 'default'。不同 session 相互隔离(各自独立 Stata)。 |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden and reveals substantial behavior: session persistence across calls, cleaned output production, background execution returning job_id immediately, restricted mode intercepting shell escapes (shell/winexec/!), erase, and unauthorized paths, and session isolation via independent Stata instances. Error/exception behavior and the exact result shape are not disclosed, which keeps it from a 5.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The main description is a single front-loaded sentence with zero filler, stating action, key behavior, and return value. The four parameter descriptions are thorough but each sentence earns its place by adding behavioral semantics, defaults, recommendations, or sibling routing.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a moderately complex execution tool with no annotations and no output schema, the definition covers purpose, session-state semantics, async workflow, security interception, and session isolation. The main gap is the lack of a precise return-format/error-behavior description (what the cleaned output object looks like, what happens on a non-zero rc), which matters more because there is no output schema.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100% with rich, behavior-oriented descriptions: code explains multi-line loops and shared memory state, background names the polling/interrupt siblings and suggests async for long commands, restricted details the security config fallback, and session_id explains isolation with independent Stata instances. The tool description adds the rc return concept, complementing the schema. This exceeds the baseline 3 for high coverage.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description uses a specific verb and resource — '执行一段 Stata 代码' (execute a block of Stata code) — and states the distinguishing traits: it maintains session state across calls and returns cleaned output text plus rc. This clearly differentiates it from the sibling tools (stata_break, stata_task_status, stata_get_help, etc.), which are all secondary or query operations.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The main description implies this is the primary execution tool, and the background parameter gives clear operational guidance: use true for long commands (bootstrap/mixed models) and route to stata_task_status/stata_break for polling and interruption. There is no explicit 'when not to use' statement, but the context for choosing sync vs. async is clear.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
stata_session_historyA
返回当前会话的命令日志(seq/cmd/rc),供追溯或崩溃后重放。
| Name | Required | Description | Default |
|---|---|---|---|
| last | No | 只返回最近 N 条(默认全部,上限 100)。 | |
| session_id | No | 会话标识;省略用 'default'。 |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the behavioral burden. It explicitly characterizes this as returning a log with sequence/command/return-code, and the crash-replay mention implies persistence. It does not spell out that it is side-effect-free, but '返回' plus the log/replay framing make the read-only nature evident.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
A single, front-loaded sentence conveys action, resource, content, and purpose without filler. Every element earns its place.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a simple read-only history tool, the description plus fully documented schema covers the essential invocation details: what is returned, when to use it, and the optional parameters. A brief note on output ordering or total size would make it fully complete, but nothing critical is missing.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 100%, and both parameters (last, session_id) have meaningful descriptions in the schema. The tool description adds no extra meaning about these parameters, so the baseline of 3 is appropriate.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description names a specific verb ('返回') and resource ('当前会话的命令日志') and specifies the returned fields (seq/cmd/rc). It does not explicitly contrast with sibling tools like stata_get_results or stata_run, so it misses the strongest form of differentiation.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The phrase '供追溯或崩溃后重放' states clear use cases (tracing and crash replay), which tells an agent when this log-retrieval tool is appropriate. It does not name alternatives or state when not to use it, but the intended context is clear.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
stata_task_statusA
查询后台任务:running / done(带结果文本) / error。未知 job_id 报 rc=1。
| Name | Required | Description | Default |
|---|---|---|---|
| job_id | Yes | stata_run(background=True) 返回的全局 job_id(任务表全局查询,不属某会话)。 |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. It does this well by specifying the three possible return states (running, done with result text, error) and the failure behavior for an unknown job_id (rc=1). This gives the agent concrete expectations beyond just 'query status.' It does not cover every edge case, but the disclosed behavior is meaningful and non-obvious.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single compact sentence that front-loads the core purpose, lists all relevant status outcomes, and includes the key error condition. Every element earns its place, and there is no redundant filler.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a simple one-parameter status-check tool with no output schema, the description is notably complete: it covers the states, the result-text behavior, and the error behavior. Combined with the schema's explanation of job_id's origin, an agent has enough information to invoke the tool correctly and interpret likely outcomes.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so the baseline is 3. The description itself does not add much parameter-level meaning, but the schema already describes job_id as a global id returned by stata_run(background=True). The description and schema together fully clarify the single parameter's meaning.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description states a specific verb ('查询' / query) and a specific resource ('后台任务' / background task), and enumerates the possible statuses: running, done (with result text), and error. It clearly identifies the tool's purpose, though it does not explicitly contrast itself with sibling tools like stata_get_results.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implicitly indicates when to use the tool: when checking the status of a background task. The parameter schema adds the key context that job_id comes from stata_run(background=True) and is global, which helps the agent choose this tool for post-run status checks. However, there is no explicit 'use this instead of...' guidance or exclusions relative to siblings such as stata_get_results.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
10 tool updates
v1.0.0- First observed
stata_break - First observed
stata_data_rows - First observed
stata_export_graph - First observed
stata_get_help - First observed
stata_get_results - First observed
stata_inspect_data - First observed
stata_load_data - First observed
stata_run - First observed
stata_session_history - First observed
stata_task_status
TDQS
Each tool maps to a distinct activity—executing code, loading data, inspecting data, viewing rows, retrieving results, exporting graphs, getting help, and managing sessions/tasks. There is minor potential confusion between inspect_data and get_results since both can return summary-like structured output, but the descriptions clarify the intended use.
The consistent stata_ prefix and snake_case help, but the pattern is mixed: most tools use verb_noun (stata_load_data, stata_inspect_data, stata_export_graph), while others are noun phrases (stata_data_rows, stata_session_history, stata_task_status). This makes the set slightly less predictable.
Ten tools is well-scoped for a Stata MCP server, covering command execution, data access, session management, help, and output export without redundancy or bloat. Each tool earns its place in the analysis workflow.
The tool surface covers the core Stata workflow—load data, inspect it, run commands, retrieve results, export graphs, get help, and manage tasks/sessions. A few optional additions like saving/exporting datasets or managing working directories are absent, but agents can work around these with stata_run, so there are no major dead ends.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Model Context Protocol server for Studex tools, notifications, and profile integrations
Enable secure connectivity between Sentry issues and debugging data, and LLM clients, using a Model Context Protocol (MCP) server.
A Model Context Protocol server for Wix AI tools
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables LLMs to perform statistical analysis and generate ML predictions on user data from databases or CSV files through a Model Context Protocol server.2-
- FlicenseAqualityDmaintenanceEnables LLMs to interact with Python environments, execute code, manage files, and handle packages through the Model Context Protocol.9-
- FlicenseNot gradedqualityDmaintenanceEquips AI coding agents with filesystem, Git, database, and computation tools via the Model Context Protocol.1-
- AlicenseBqualityDmaintenanceProvides AI agents with 40 tools for structured data storage, querying, web search, URL fetching, scheduled jobs, and execution through the Model Context Protocol.44115MIT
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/horizonial/stata-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server