Prototype · Preview: every server in the official registry, synced every 30 minutes. Sign in with Google to write reviews.Prototype · updated every 30 min
PopNx MCPMCP servers for people who use AI · explained in plain words

Stata MCP Server

by aliveranmeversion 1.0.10i★ 0iRuns on your computerRepository ↗
Registry nameio.github.aliveranme/stata-mcp

How to install

What it does

通过 pystata 驱动真实 Stata 的 MCP 服务器:数据加载/清洗/建模/诊断/图形导出,75 个工具覆盖完整计量工作流。

  • Connects Runs on your computer
  • Account or key No key needed · 1 setting to fill in (STATA_HOME)
  • Category Other

Why it ranks here

Lists are ordered by a usage score (out of 100) built from these parts

Popularity0/80GitHub stars or weekly downloads: the larger counts 60, the smaller 20
Freshness7/12Full marks for a release or code change within 30 days
Still answering0/8The cloud endpoint answered at the last check
Usage score7/100

Quality: Passed 3/3 basic checks (shown, not used for ordering) · Momentum: No data yet (Used only on the Trending tab)

Install

Pick the AI app you use, then copy the settings.

Let your AI install it with one sentence

Please install Stata MCP Server. Follow https://mcp.popnx.com/i/aliveranme-stata-mcp.md, show me the commands and wait for my OK before running them.

Paste it into an AI that can work on your computer (such as Claude Code or Cursor). It reads our steps, shows you the commands and waits for your OK. No key, no sign-up. · See the full text your AI reads

Passed 3/3 checks · Runs on your computer · ✓ Commands checked Nov 14, 2026

First: which AI do you use?

Pick your app and the steps appear below.

Works with Claude, with some setup first

1 setting(s) to fill in (STATA_HOME) · Install Node.js on your computer first (one time) · Only the Claude desktop app (Windows or Mac), not the web or phone

Let AI install it

Copy this message into a Claude chat. The AI checks your computer, tells you which file it will change, and waits for your OK every time.

Please install the MCP server Stata MCP Server for Claude on this computer, in this order: 1) Check Node.js with node -v. If it is missing, tell me to install it from https://nodejs.org/en/download; do not install it yourself. 2) Use only this config (already checked by PopNx MCP): { "mcpServers": { "stata": { "command": "npx", "args": [ "-y", "@aliveranme/stata-mcp" ], "env": { "STATA_HOME": "your-value" } } } } 3) Tell me the full path of the file you will change, or the command you will run, and wait for my OK. 4) For STATA_HOME, leave "your-value" in place and tell me to paste the real value myself into the file or the app’s field. Never ask me to type a key in chat. 5) Do what we agreed, then check that the Stata MCP Server tools really show up.

This message has no key in it. If a key is needed, the AI will ask you to paste it yourself into the file or the app’s field.

  1. Install Node.js (if you don’t have it)

    Already installed? Check first · Open Terminal, type this command and press Enter

    node -v
    • A version number such as v26.13.1 = installed, skip this step
    • "command not found" (on Windows: "is not recognized") = not installed yet, or installed but Terminal needs to be closed and reopened
    How to open Terminal

    Mac: press ⌘ + Space, type Terminal, press Enter

    Windows: open Start, type Windows PowerShell, then Open

    Not installed: Open the official download page, pick the LTS version and the click-through installer: .pkg on Mac · .msi on Windows. Double-click and follow it to the end. No curl command needed

    Open the Node.js download page ↗

    When it’s done, close Terminal, open it again and run the same command. You should see a version number: node -v

    Install once; it works for everything that needs Node.js

  2. Fill in 1 setting(s)

    These are program settings, not keys. No sign-up needed; fill them in as the maker describes.

    • STATA_HOME Stata 安装目录(含 utilities/pystata),如 /Applications/StataNow

    Descriptions are as written by the maker.

  3. Open the Claude desktop app’s settings file

    SettingsDeveloperEdit Config

  4. Paste these settings and save the file

    {
      "mcpServers": {
        "stata": {
          "command": "npx",
          "args": [
            "-y",
            "@aliveranme/stata-mcp"
          ],
          "env": {
            "STATA_HOME": "your-value"
          }
        }
      }
    }
  5. Quit Claude and open it again

  6. Try it

    Use Stata MCP Server and tell me what you can do for me, then show me one thing

    ✓ If Claude says it is using Stata MCP Server or shows a Stata MCP Server tool in the answer, you are connected

2 optional setting(s) (works without them)

The command above works without these. Add them only if you want to change something, following the maker’s description.

  • STATA_EDITION Stata 版本 mp|se|be · default mp
  • STATA_ALLOWED_ROOTS 路径沙箱白名单(分号分隔);可选

Descriptions are as written by the maker.

Menu names checked against Anthropic’s help page on Nov 11, 2026 · your screen may differ slightly by app version

ChatGPT cannot connect Stata MCP Server yet

Stata MCP Server runs on your computer, but ChatGPT can only connect servers that run on the web

What you can do instead

A · Use an app that can connect Stata MCP Server

  • 1 setting(s) to fill in (STATA_HOME) · Install Node.js on your computer first (one time) · Only the Claude desktop app (Windows or Mac), not the web or phone
  • 1 setting(s) to fill in (STATA_HOME) · Install Node.js on your computer first (one time)
  • 1 setting(s) to fill in (STATA_HOME) · Install Node.js on your computer first (one time)
  • 1 setting(s) to fill in (STATA_HOME) · Install Node.js on your computer first (one time)

B · Others in Other that work with ChatGPT

Picked from the most used in the same category, only ones that connect by address with no key

Works with Claude Code, with some setup first

1 setting(s) to fill in (STATA_HOME) · Install Node.js on your computer first (one time)

Let AI install it

Copy this message into a Claude Code chat. The AI checks your computer, tells you which file it will change, and waits for your OK every time.

Please install the MCP server Stata MCP Server for Claude Code on this computer, in this order: 1) Check Node.js with node -v. If it is missing, tell me to install it from https://nodejs.org/en/download; do not install it yourself. 2) Use only this config (already checked by PopNx MCP): claude mcp add --scope user stata --env STATA_HOME=your-value -- npx -y @aliveranme/stata-mcp 3) Tell me the full path of the file you will change, or the command you will run, and wait for my OK. 4) For STATA_HOME, leave "your-value" in place and tell me to paste the real value myself into the file or the app’s field. Never ask me to type a key in chat. 5) Do what we agreed, then check that the Stata MCP Server tools really show up.

This message has no key in it. If a key is needed, the AI will ask you to paste it yourself into the file or the app’s field.

  1. Install Node.js (if you don’t have it)

    Already installed? Check first · Open Terminal, type this command and press Enter

    node -v
    • A version number such as v26.13.1 = installed, skip this step
    • "command not found" (on Windows: "is not recognized") = not installed yet, or installed but Terminal needs to be closed and reopened
    How to open Terminal

    Mac: press ⌘ + Space, type Terminal, press Enter

    Windows: open Start, type Windows PowerShell, then Open

    Not installed: Open the official download page, pick the LTS version and the click-through installer: .pkg on Mac · .msi on Windows. Double-click and follow it to the end. No curl command needed

    Open the Node.js download page ↗

    When it’s done, close Terminal, open it again and run the same command. You should see a version number: node -v

    Install once; it works for everything that needs Node.js

  2. Fill in 1 setting(s)

    These are program settings, not keys. No sign-up needed; fill them in as the maker describes.

    • STATA_HOME Stata 安装目录(含 utilities/pystata),如 /Applications/StataNow

    Descriptions are as written by the maker.

  3. Open Terminal

    Mac: press Command+Space and type Terminal · Windows: open PowerShell

  4. Paste this command and press Enter

    claude mcp add --scope user stata --env STATA_HOME=your-value -- npx -y @aliveranme/stata-mcp
  5. Type /mcp in Claude Code

    You should see Stata MCP Server listed as connected

  6. Try it

    Use Stata MCP Server and tell me what you can do for me, then show me one thing

    ✓ If Claude Code says it is using Stata MCP Server or shows a Stata MCP Server tool in the answer, you are connected

2 optional setting(s) (works without them)

The command above works without these. Add them only if you want to change something, following the maker’s description.

  • STATA_EDITION Stata 版本 mp|se|be · default mp
  • STATA_ALLOWED_ROOTS 路径沙箱白名单(分号分隔);可选

Descriptions are as written by the maker.

Menu names checked against Anthropic’s help page on Nov 11, 2026 · your screen may differ slightly by app version

Works with Cursor, with some setup first

1 setting(s) to fill in (STATA_HOME) · Install Node.js on your computer first (one time)

Let AI install it

Copy this message into a Cursor chat. The AI checks your computer, tells you which file it will change, and waits for your OK every time.

Please install the MCP server Stata MCP Server for Cursor on this computer, in this order: 1) Check Node.js with node -v. If it is missing, tell me to install it from https://nodejs.org/en/download; do not install it yourself. 2) Use only this config (already checked by PopNx MCP): { "mcpServers": { "stata": { "command": "npx", "args": [ "-y", "@aliveranme/stata-mcp" ], "env": { "STATA_HOME": "your-value" } } } } 3) Tell me the full path of the file you will change, or the command you will run, and wait for my OK. 4) For STATA_HOME, leave "your-value" in place and tell me to paste the real value myself into the file or the app’s field. Never ask me to type a key in chat. 5) Do what we agreed, then check that the Stata MCP Server tools really show up.

This message has no key in it. If a key is needed, the AI will ask you to paste it yourself into the file or the app’s field.

  1. Install Node.js (if you don’t have it)

    Already installed? Check first · Open Terminal, type this command and press Enter

    node -v
    • A version number such as v26.13.1 = installed, skip this step
    • "command not found" (on Windows: "is not recognized") = not installed yet, or installed but Terminal needs to be closed and reopened
    How to open Terminal

    Mac: press ⌘ + Space, type Terminal, press Enter

    Windows: open Start, type Windows PowerShell, then Open

    Not installed: Open the official download page, pick the LTS version and the click-through installer: .pkg on Mac · .msi on Windows. Double-click and follow it to the end. No curl command needed

    Open the Node.js download page ↗

    When it’s done, close Terminal, open it again and run the same command. You should see a version number: node -v

    Install once; it works for everything that needs Node.js

  2. Fill in 1 setting(s)

    These are program settings, not keys. No sign-up needed; fill them in as the maker describes.

    • STATA_HOME Stata 安装目录(含 utilities/pystata),如 /Applications/StataNow

    Descriptions are as written by the maker.

  3. Click this button to open Cursor

    Open in Cursor

    Cursor asks you to confirm; click Install

  4. Fill in your key

    In the Stata MCP Server settings, STATA_HOME is empty; add your key and save

  5. Open the AI chat in Cursor in Agent mode

  6. Try it

    Use Stata MCP Server and tell me what you can do for me, then show me one thing

    ✓ If Cursor says it is using Stata MCP Server or shows a Stata MCP Server tool in the answer, you are connected

2 optional setting(s) (works without them)

The command above works without these. Add them only if you want to change something, following the maker’s description.

  • STATA_EDITION Stata 版本 mp|se|be · default mp
  • STATA_ALLOWED_ROOTS 路径沙箱白名单(分号分隔);可选

Descriptions are as written by the maker.

Menu names checked against Cursor’s help page on Nov 11, 2026 · your screen may differ slightly by app version

Works with VS Code, with some setup first

1 setting(s) to fill in (STATA_HOME) · Install Node.js on your computer first (one time)

Let AI install it

Copy this message into a VS Code chat. The AI checks your computer, tells you which file it will change, and waits for your OK every time.

Please install the MCP server Stata MCP Server for VS Code on this computer, in this order: 1) Check Node.js with node -v. If it is missing, tell me to install it from https://nodejs.org/en/download; do not install it yourself. 2) Use only this config (already checked by PopNx MCP): { "servers": { "stata": { "type": "stdio", "command": "npx", "args": [ "-y", "@aliveranme/stata-mcp" ], "env": { "STATA_HOME": "your-value" } } } } 3) Tell me the full path of the file you will change, or the command you will run, and wait for my OK. 4) For STATA_HOME, leave "your-value" in place and tell me to paste the real value myself into the file or the app’s field. Never ask me to type a key in chat. 5) Do what we agreed, then check that the Stata MCP Server tools really show up.

This message has no key in it. If a key is needed, the AI will ask you to paste it yourself into the file or the app’s field.

  1. Install Node.js (if you don’t have it)

    Already installed? Check first · Open Terminal, type this command and press Enter

    node -v
    • A version number such as v26.13.1 = installed, skip this step
    • "command not found" (on Windows: "is not recognized") = not installed yet, or installed but Terminal needs to be closed and reopened
    How to open Terminal

    Mac: press ⌘ + Space, type Terminal, press Enter

    Windows: open Start, type Windows PowerShell, then Open

    Not installed: Open the official download page, pick the LTS version and the click-through installer: .pkg on Mac · .msi on Windows. Double-click and follow it to the end. No curl command needed

    Open the Node.js download page ↗

    When it’s done, close Terminal, open it again and run the same command. You should see a version number: node -v

    Install once; it works for everything that needs Node.js

  2. Fill in 1 setting(s)

    These are program settings, not keys. No sign-up needed; fill them in as the maker describes.

    • STATA_HOME Stata 安装目录(含 utilities/pystata),如 /Applications/StataNow

    Descriptions are as written by the maker.

  3. Click this button to open VS Code

    Open in VS Code

    VS Code asks you to confirm; click Install

  4. Fill in your key

    In the Stata MCP Server settings, STATA_HOME is empty; add your key and save

  5. Open the AI chat in VS Code in Agent mode

  6. Try it

    Use Stata MCP Server and tell me what you can do for me, then show me one thing

    ✓ If VS Code says it is using Stata MCP Server or shows a Stata MCP Server tool in the answer, you are connected

2 optional setting(s) (works without them)

The command above works without these. Add them only if you want to change something, following the maker’s description.

  • STATA_EDITION Stata 版本 mp|se|be · default mp
  • STATA_ALLOWED_ROOTS 路径沙箱白名单(分号分隔);可选

Descriptions are as written by the maker.

Menu names checked against VS Code’s help page on Nov 11, 2026 · your screen may differ slightly by app version

Other apps that use MCP, such as Windsurf, Zed or Gemini CLI, each add servers differently. See how in the app list.

See every app that uses MCP →

JSON settings are under “For developers” below

Stuck? Ask people who use Stata MCP Server💬 Discussion →
For developers: Terminal commands and JSON settings

Installed on your computer

Claude Code

claude mcp add --scope user stata --env STATA_HOME=your-value -- npx -y @aliveranme/stata-mcp

Claude Desktop (claude_desktop_config.json)

{
  "mcpServers": {
    "stata": {
      "command": "npx",
      "args": [
        "-y",
        "@aliveranme/stata-mcp"
      ],
      "env": {
        "STATA_HOME": "your-value"
      }
    }
  }
}

Cursor (~/.cursor/mcp.json)

{
  "mcpServers": {
    "stata": {
      "command": "npx",
      "args": [
        "-y",
        "@aliveranme/stata-mcp"
      ],
      "env": {
        "STATA_HOME": "your-value"
      }
    }
  }
}

VS Code (mcp.json)

{
  "servers": {
    "stata": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@aliveranme/stata-mcp"
      ],
      "env": {
        "STATA_HOME": "your-value"
      }
    }
  }
}

Values you fill in

  • STATA_HOME required env
    Stata 安装目录(含 utilities/pystata),如 /Applications/StataNow
  • STATA_EDITION env
    Stata 版本 mp|se|be
  • STATA_ALLOWED_ROOTS env
    路径沙箱白名单(分号分隔);可选

Descriptions are as written by the maker.

These settings are generated from the maker’s registry entry. If the README says otherwise, follow the README.

At a glance

Downloads per weeki
53/wk
Connection
Runs on your computer
Latest versioni
1.0.10
Categoryi
Other
Published to registryi
Aug 17, 2026
Code last changedi
Aug 31, 2026
Maker
aliveranme
Packages
npm: @aliveranme/stata-mcp
Registry status
Active

Which apps can use it

Based on how this server connects and on each app’s own docs, checked Nov 10, 2026.

Run on your computer in

ClaudeGooseLM StudioMsty StudioCherry StudioCursorVS Code + GitHub CopilotVisual StudioWindsurf (Devin Desktop)ZedKiroClineContinueJetBrains AI AssistantClaude CodeCodex CLIGemini CLIOpenCodenodecodeWarpLibreChatRaycast

All apps, with pros and cons →

Related guides

What it can do

Runs on your computer; the tool list appears in your AI app after you install it.

Basic checksi

We check information anyone can see; we have not read the code. Checks that do not apply are left out of the count. · Checked Nov 19, 2026

  • ✓ Pass

    Maker matches the repo

    The registry name was verified with the GitHub account aliveranme, which owns the repo

  • ✓ Pass

    Still maintained

    Code last changed 3 months ago

  • ✓ Pass

    Has a licence

    Uses MIT

  • – Not applicable

    Endpoint responds

    This one runs on your computer; there is no internet endpoint

  • – Not applicable

    Sign-in with OAuth

    Runs on your computer and uses local settings instead

  • … Not checked yet

    No hidden instructions in tool descriptions

    Runs on your computer; we can only read tool lists from internet endpoints

Published vulnerabilities (OSV.dev)

No entries on OSV.dev for @aliveranme/stata-mcp@1.0.10

Checks only this package version, not every dependency · checked Nov 16, 2026

What we check → · JSON

Makers: ask for a re-check or report wrong info
For makers: add a badge to your README

If you made this, paste this code into your README. The badge links back to this page.

[![Featured on PopNx MCP](https://mcp.popnx.com/badge/aliveranme-stata-mcp.svg)](https://mcp.popnx.com/en/servers/aliveranme-stata-mcp)

Discussion

Ask, share a tip or report that it does not work. Sorted by what people marked helpful.

No posts yet. Be the first to ask or share.

Posts here are written by users, not the PopNx team.

Sign in to post

User reviews

No reviews yet

Sign in to write a review

Compared with others in Otheri

  • More stars than 0% of the other 20613 servers in this category
  • Published to the registry more recently than 18% of the other 20613 servers in this category
  • Basic checks equal to or better than 99% of the other 20613 servers in this category

Compared with every active server in this category in the registry. Stars count only when the publisher owns the repo.

Common questions

Is Stata MCP Server safe?

It passed 3 of 3 applicable basic checks. We have not read the code. Before adding a key or token, see what access the server asks for and use a key with only the permissions you need.

What keys or codes does it need?

The registry does not list a required key, though some servers ask you to sign in on first use.

Does it run on my computer or in the cloud?

It runs on your computer. Your AI app starts it when needed, and data does not pass through the maker’s servers (unless it calls an online service itself).

Is it still maintained?

The GitHub repo last changed 3 months ago, and the latest version (1.0.10) reached the registry 3 months ago.

Which apps can use it?

Apps that support MCP, such as Claude Desktop, Claude Code, Cursor and VS Code. You also need Node.js on your computer.

What can I use instead?

In the same category: World Monitor, openstatus, Oh My Posh Validator, Strata, Jitsu

Similar alternatives

Same category, other makers, commands already checked. Official ones first, then by stars.

Reading a card:↓ Downloads per weeki★ GitHub starsiThree pillars: reviews · checks · usageiUpdated = latest version published to the registryi

World Monitor

Real-time global intelligence on conflict, markets, energy, trade, shipping and cyber. 100 tools.

by koala73Widely used★ 90.9KUpdated 3 days ago

Runs in the cloud✓ service owner · worldmonitor.app

openstatus

Manage monitors, status pages, incidents and maintenances in your openstatus workspace.

by openstatusHQWidely used★ 9.3KUpdated 2 months ago

Runs in the cloud✓ service owner · openstatus.dev

Oh My Posh Validator

Validate oh-my-posh configurations and segment snippets against the official schema.

by JanDeDobbeleerWidely used★ 23.8K Stars for the whole repoUpdated 30 days ago

Runs in the cloud✓ service owner · ohmyposh.dev

Strata

MCP server for progressive tool usage at any scale (see https://klavis.ai)

by Klavis-AIGrowing★ 5.8KUpdated 14 months ago

Runs in the cloudRepo archived✓ klavis.ai

Jitsu

Manage Jitsu data pipelines: destinations, streams, connections, functions, live events.

by jitsucomWidely used★ 5.1KUpdated 4 months ago

Runs in the cloud✓ service owner · jitsu.com
Compared with similar ones
This one
Stata MCP Server
World MonitoropenstatusOh My Posh ValidatorStrataJitsu
Runs whereInstalls on your computerRuns in the cloud, nothing to installRuns in the cloud, nothing to installRuns in the cloud, nothing to installRuns in the cloud, nothing to installRuns in the cloud, nothing to install
Needs a keyNoNoNoNoNoNo
Add with + in ClaudeNoNoNoNoNoNo
Basic checks3/34/44/44/41/44/4
LicenseMITAGPL-3.0AGPL-3.0MITApache-2.0MIT
PriceNo cost listed in the registryNo cost listed in the registryNo cost listed in the registryNo cost listed in the registryNo cost listed in the registryNo cost listed in the registry

README from the maker

Open the README

Copied from the maker’s repo as written. PopNx MCP has not reviewed or endorsed it. HTML, images and scripts are removed. Links lead off this site.

在 Claude Code 里用自然语言做 Stata 分析。你描述要什么,Agent 自己写命令、执行、 读结果、继续下一步 —— 加载数据、清洗、建模、诊断、导出,全在一个持久的 Stata 会话里完成,数据不用反复载入。

一句话,跑完整个分析

你: 加载 auto.dta,用 weight 和 mpg 回归 price,并检查异方差

Agent 自动完成(无需你写任何 Stata 命令):

stata_use_dataset("auto.dta")          →  74 obs, 12 vars 已载入

stata_regress("price", "weight mpg") → R² = 0.293 ; weight 1.75 (p=0.008) stata_run("estat hettest") → Breusch–Pagan χ² 检验异方差 stata_graph("rvfplot", export="…png") → 残差图导出为文件

数据从第一步起就留在内存里,后面每一步都接着用 —— 这正是 stata_run("regress …") 之外还值得有一个 MCP Server 的原因。

这是什么

两部分组成,一起装进 Claude Code:

  • 执行层(MCP Server) —— 经 pystata 直接调用 Stata 的运行时,把 75 个工具 暴露给 Agent。stata_run 执行任意命令、stata_help 查任意命令的官方语法,二者 合起来即「全量内置命令支持」;其余专用工具(回归 / 面板 / IV / 生成变量 / 数据 清洗 / 后估计 / 文件资源 / 后台任务 …)是给高频命令加结构化参数与校验的便利层。
  • 知识层(Skill) —— 一份 Stata 编程指南:语法要点、分析模板、常见陷阱、命令 地图与常用外置包。Agent 据此知道该用什么命令,而不是靠猜。

为什么是 pystata,而不是 subprocess

pystata 通过 ctypes 在进程内加载 Stata 运行时,而非每条命令起一个子进程:

  • 真会话持久 —— Stata 在 MCP Server 启动时初始化一次,数据集、估计结果、局部 宏在所有工具调用之间保持。多步分析(加载 → 清洗 → 回归 → 诊断)就是自然的对话。
  • 低延迟 —— 无进程启动开销,单条命令约 12ms。
  • 输出可控 —— 直接读 Stata 输出缓冲;大输出自动分页(stata_more 翻页), 硬上限 120K 字符防止撑爆 MCP 通道;长命令有 60s 超时看门狗(可显式调大)。

架构

快速开始

前置条件
  • Stata:StataNow 19 或 Stata 18+(MP / SE / BE 均可)——需含 utilities/pystata
  • Python 3.10+(推荐 3.12+)
  • Claude Code 最新版
  • 操作系统:Windows 或 macOS(见下方「兼容性」)
一键安装
git clone https://gitea.aliveranme.space/aliveranme/stata-mcp.git

cd stata-mcp python setup.py

装在非标准位置(如外置卷 /Volumes/xxx/Applications/StataNow)时自动检测会失败 ——

先 export STATA_HOME=/你的/Stata路径 再跑 setup.py 即可。

setup.py 会:检测 Stata 安装(常见路径 + STATA_HOME 环境变量,跨平台)→ 创建虚拟环境并安装 fastmcp → 生成 .mcp.json(保留你已有的其他 MCP Server 配置) → 验证 Server 可启动。

手动安装(自动检测失败时)

# 1. 指定 Stata 路径(替换为你本机实际路径)

export STATA_HOME="C:/Program Files/StataNow/StataNow19" # Windows

export STATA_HOME="/Applications/Stata" # macOS

export STATA_EDITION=mp # mp / se / be

2. 建虚拟环境并装依赖

cd mcp-stata-server uv venv source .venv/Scripts/activate # Windows Git Bash

source .venv/bin/activate # macOS / Linux

uv pip install "fastmcp>=3.2.0"

3. 生成配置

cd .. cp .mcp.json.example .mcp.json # 编辑其中的

</details>
通过 npm 安装(无需 clone 仓库)

若你已有 Node.js ≥ 18 与 uv(无 uv 时需 Python 3.10+ 且已装 fastmcp>=3.2.0),可直接使用已发布的 npm 包 @aliveranme/stata-mcp:

export STATA_HOME="/你的/Stata路径"     # 含 utilities/pystata

export STATA_EDITION=mp

直接跑通(首次启动经 uv 拉取 fastmcp,请给客户端 90s 超时)

npx -y @aliveranme/stata-mcp

Claude Code .mcp.json 配置:

{

"mcpServers": { "stata": { "command": "npx", "args": ["-y", "@aliveranme/stata-mcp"], "env": { "STATA_HOME": "/Applications/StataNow", "STATA_EDITION": "mp" } } } }

npx @aliveranme/stata-mcp 与 npx stata-mcp-server(bin 名)等价,二者都触发同一个启动器。

连接并验证

重启 Claude Code(或 /reload-plugins),.mcp.json 里的 stata Server 会自动连接。 然后在对话里直接说:

帮我加载 auto.dta 并做描述统计

Agent 会自动走 stata_use_dataset → stata_describe → stata_summarize。

各 Agent 安装教程

除 Claude Code 外,本 MCP 可接入所有支持 MCP 的客户端/Agent。逐平台教程见 docs/agent-setup/:

Agent / 客户端配置位置教程
Claude Code.mcp.json / claude mcp addclaude-code.md
Claude Desktopclaude_desktop_config.jsonclaude-desktop.md
Cursor.cursor/mcp.jsoncursor.md
Cline / Roo Code / Continue / Zed / Windsurf通用 mcpServers schema(Zed 用 context_servers)other-clients.md

插件 / 扩展市场分发(Claude Code 插件、Cursor 扩展、Claude Desktop .mcpb)的可行性

评估见 plugin-distribution.md。

MCP 工具(75 个)

能力边界不在工具数量上:stata_run + stata_help 已覆盖全部内置命令。下面的

专用工具是给高频命令加结构化参数与校验的便利层。

类别工具
核心执行stata_run(任意命令,含危险前缀拦截;save_output= 完整输出落盘并登记为资源)· stata_run_do_file(执行前自动拆出 ssc install 单独安装,已装跳过)
数据管理stata_use_dataset · stata_import(excel/csv/sas/spss/dbase/parquet)· stata_use_example(sysuse/webuse)· stata_save_dataset · stata_set_cwd · stata_generate · stata_egen · stata_xtset(面板/时序声明)
数据重构 / 校验stata_merge · stata_append · stata_reshape · stata_collapse · stata_frame(多数据集)· stata_verify(count/assert/duplicates/isid/missing)· stata_replace · stata_drop · stata_keep · stata_rename · stata_recode · stata_destring
数据探索stata_describe · stata_codebook · stata_summarize · stata_list · stata_tabulate · stata_correlate · stata_display
估计stata_regress · stata_logistic · stata_probit · stata_poisson · stata_ttest · stata_xtreg · stata_ivregress · stata_logit · stata_mlogit · stata_nbreg · stata_qreg · stata_mixed
后估计stata_margins · stata_test · stata_predict · stata_estat(vif/hettest/ovtest/ic)· stata_estimates(存取与并排比较)· stata_lincom · stata_nlcom · stata_hausman · stata_return_list
图形 / 导出stata_graph(导出即验证文件写入)· stata_scheme(主题)· stata_export_excel · stata_export_delimited · stata_etable(回归表直出 Word/Excel)
文件资源回传stata_list_resources · stata_read_file(info/base64)· stata_register_file —— 导出产物经资源协议(resources/read 读 stata-file:///)取回二进制
包管理与帮助stata_help(查任意命令帮助)· stata_install_package · stata_uninstall_package · stata_describe_package · stata_find_package · stata_list_packages
会话生命周期stata_clear(scope 重置)· stata_snapshot(save/list/restore/erase)· stata_more(翻页)· stata_status · stata_ping
长任务控制stata_background(后台执行,单块上限 3600s)· stata_task_status · stata_task_cancel · stata_task_result · stata_task_list
服务器日志stata_read_log(tail/path)

各工具的参数与说明

数据管理 — stata_use_dataset 加载 .dta(可只载入子集);stata_import 覆盖官方 import 命令族,按扩展名推断格式;stata_save_dataset 保存;stata_set_cwd 改工作目录; stata_generate / stata_egen 创建变量(支持官方 [type] 存储类型与 [if] [in]); stata_xtset 声明面板 / 时序结构 —— 它是 stata_xtreg 的前提。

数据探索 — stata_summarize / stata_codebook / stata_list / stata_tabulate 均支持 condition;stata_correlate 可选 pairwise 走 pwcorr;stata_display 算表达式 / 看返回值。

估计 — stata_regress(OLS)、stata_logistic、stata_probit(可选 marginal_effects)、stata_poisson(可选 irr)、stata_ttest(可按组)、 stata_xtreg(effects = fe/re/be/mle/pa,需先 xtset)、stata_ivregress (2sls/liml/gmm)。扩展族:stata_logit(报告原始系数,OR 用 logistic)、 stata_mlogit(多分类,baseoutcome 定基准)、stata_nbreg(负二项)、 stata_qreg(分位,quantile 默认 0.5)、stata_mixed(多水平,random="|| id:")。

数据清洗 — stata_replace 覆盖变量值、stata_drop/stata_keep 删/留变量或观测 (两种形态二选一)、stata_rename 重命名(单个或批量)、stata_recode 重编码 (values="(1=0) (2/4=1)" 官方规则组)、stata_destring 字符串转数值(必须 replace=True 或 generate())。

后估计(须先跑估计命令)— stata_margins(dydx / at)、stata_test (Wald 检验)、stata_predict(预测值 / 残差,会创建变量)、stata_lincom / stata_nlcom(线性 / 非线性组合检验)、stata_hausman(模型比较,需先 stata_estimates action="store" 存两个模型)。

图形 / 导出 — stata_graph 把 graph 与 export 原子执行,以文件是否真被写入判定 成败。导出选项按格式自动适配官方边界:尺寸单位(位图与 svg 用像素、pdf 用英寸、 eps/ps/emf 不支持)、quality(仅 jpg)、mag(仅 pdf/eps/ps)、fontface (仅矢量格式)—— 不适用的选项被丢弃并在返回信息中说明,而非让 Stata 静默失败。 stata_scheme 列出 / 查询 / 设置主题(不传 scheme 时不会改动你当前的主题)。 stata_export_excel 导数据为 .xlsx(支持 sheet_mode / cell / firstrow / if-in 筛选);stata_export_delimited 导 CSV / TSV / 自定义分隔符。 回归表用 stata_etable(官方 etable,Stata 17+,无第三方依赖): estimates="m1 m2 m3" 并排多模型,直出 .docx / .xlsx / .pdf / .tex / .html / .md, 并以文件是否真被写入判定成败 —— etable 会先把表打印出来再报导出错误,只看输出 很容易把失败当成功。

包管理与帮助 — stata_help("命令") 查任意内置 / 已装外置命令的官方语法; stata_find_package 走 net search 联网找包;stata_install_package 装(ssc 或 URL); stata_uninstall_package 卸载(ado uninstall,纯本地);stata_describe_package 查包详情(默认本地 ado describe,source="ssc" 走联网 ssc describe 供装前了解); stata_list_packages 列已装。

会话 — stata_more 翻上一条命令的完整输出;stata_status 一次给出数据集、工作目录、 frame、面板/时序设定、已存与活跃的估计结果、内存 —— 即 Agent 调 xtreg / margins / predict 前需要确认的全部前提;stata_ping 心跳。stata_clear 按 scope 重置会话(data/estimates/graphs/panels/all);stata_snapshot 用 Stata 原生快照在数据 阶段间快速回退(save/list/restore/erase)。

文件资源回传 — 导出工具(stata_graph / stata_export_* / stata_etable / stata_save_dataset / stata_run save_output=)成功后把文件登记为 MCP 资源。远程 客户端经 resources/read 读 stata-file:///<路径> 取回图表 / Excel / CSV / dta 的 二进制,或 stata_read_file 取 base64 / 元信息;stata_list_resources 列出全部登记 文件,stata_register_file 登记已有的磁盘文件。安全边界:只读登记过的文件。

长任务控制 — stata_background 把耗时长命令放到后台(立即返回任务号,单块超时 上限 3600s,运行期间其他调用会等待共享的 _stata_lock);stata_task_status 查进度、 stata_task_cancel 显式取消、stata_task_result 取结果、stata_task_list 列全部。 stata_read_log 读本服务器运行日志排查问题。

Stata 知识 Skill

.claude/skills/stata/SKILL.md 是 Agent 的 Stata 编程参考:

模块内容
核心原则分析前先探数据、变量名大小写、路径规范、返回值检查
语法要点命令结构、if 条件陷阱、因子变量、循环与条件块、egen 函数
命令地图3500+ 内置命令按族归类,语法一律指向 stata_help
分析模板数据探索、OLS / Logit、面板、工具变量、DID —— 均经真实 Stata 验证
外置命令表reghdfe / ivreg2 / estout / coefplot / did / rdrobust … 按计量方向组织
常见陷阱变量名冲突、缺失值、字符串转换、路径、do 文件

兼容性

组件要求
StataStataNow 19 / Stata 18(MP / SE / BE),需含 utilities/pystata
Python3.10+
Claude Code最新版(支持 MCP stdio)
操作系统Windows、macOS(setup.py 跨平台检测;Linux 亦受 setup.py 支持但未实测)

pystata 是 Stata 官方的 Python 集成,随 Stata 一同分发,Windows / macOS / Linux

均提供。本项目在 Windows 与 macOS(StataNow 19.5 MP)上均实测可用。

配置

环境变量

变量默认值说明
STATA_HOMEC:\Program Files\StataNow\StataNow19Stata 安装目录。环境变量优先级最高;未设置时由 setup.py 自动检测。
STATA_EDITIONmpStata 版本(mp / se / be)
STATA_ALLOWED_ROOTS未设置路径沙箱白名单,分号分隔(例 C:/data;D:/projects)。两重限制:未设置时不限制绝对路径;设置后既校验工具的路径参数,也审计 stata_run / stata_run_do_file / stata_background 自由文本命令里的引号路径(use "越界路径" 同样被拒)。宏路径 fail-open,未配置白名单时不启用。
STATA_ALLOW_UNC未设置设为 1 允许 UNC 网络路径,默认拒绝。
JAVA_TOOL_OPTIONS自动追加 -Djava.awt.headless=trueMCP 无 GUI 会话时自动启用 Java headless,避免图形导出触发 AWT 渲染错误。若已显式设置 -Djava.awt.headless=true/false,则保留原值。

开发 / 调试

# 调试模式启动 Server

cd mcp-stata-server source .venv/bin/activate # 或 .venv/Scripts/activate (Windows) python server.py

单元测试(无需 Stata)

python -m pytest tests/ -q

端到端测试(需真实 Stata;未检测到安装时整目录跳过;网络用例需可访问 Stata 官网)

必须与 tests/ 分开跑:tests/conftest.py 会把 pystata 换成 mock,同进程内换不回来

STATA_HOME=/path/to/StataNow python -m pytest tests_e2e/ -q

#

Only the beginning is shown; read the rest in the repo