Skip to main content
Glama

VS Code 和 Cursor 的 Stata MCP 扩展

VS Code 市场 GitHub 许可证

此扩展使用模型上下文协议 (MCP) 为 Visual Studio Code 和 Cursor IDE 提供 Stata 集成。此扩展允许您:

  • 直接从 VS Code 或 Cursor 运行 Stata 命令

  • 执行选择或整个 .do 文件

  • 在编辑器中实时查看 Stata 输出

  • 通过MCP协议获取AI助手集成

  • 使用 Cursor 或 Cline 体验增强的 AI 编码

特征

  • 运行 Stata 命令:直接从编辑器执行选择或整个 .do 文件

  • 语法高亮:完全支持 Stata .do、.ado、.mata 和 .doh 文件的语法

  • AI 助手集成:通过 MCP 提供上下文帮助和代码建议

  • 跨平台:适用于 Windows、macOS 和 Linux

  • 自动 Stata 检测:自动查找您的 Stata 安装

  • 实时输出:在编辑器中立即查看 Stata 结果

演示

观看此扩展如何通过 Cursor(或 VS Code)和 AI 辅助增强您的 Stata 工作流程:

Stata MCP 扩展演示

🎬 完整视频版本| 📄 查看生成的 PDF 报告

演示提示:“编写并执行 Stata do 文件,确保在所有情况下都使用完整的绝对文件路径。加载自动数据集 (webuse auto) 并生成每个变量的汇总统计数据。识别并提取数据集中的关键特征,生成相关图表,并将其保存在名为 plots 的文件夹中。进行回归分析,以检验汽车价格的主要决定因素。将所有输出导出为 LaTeX 文件并进行编译。自动处理任何编译错误,并确保 LaTeX 编译时间不超过 10 秒。所有代码错误都应在工作流程中识别和解决。”

正在寻找其他 Stata 集成?

  • 将 Stata 与 Notepad++ 和 Sublime Text 3 一起使用?请参阅此处

  • 无需安装此扩展程序即可在 Claude Desktop 中使用 Stata MCP?请参阅此处

  • 通过 Jupyter 使用 Stata?看这里

要求

  • 您的机器上安装了 Stata 17 或更高版本

  • UV包管理器(自动安装或可根据需要手动安装)

安装

**注意:**初始安装需要设置依赖项,最多可能需要 2 分钟才能完成。请耐心等待此一次性设置过程。所有后续运行将立即开始。

VS Code 安装

选项 1:来自 VS Code 市场

直接从VS Code Marketplace安装此扩展。

code --install-extension DeepEcon.stata-mcp

或者:

  1. 打开 VS Code

  2. 转到扩展视图(Ctrl+Shift+X)

  3. 搜索“Stata MCP”

  4. 点击“安装”

选项 2:从 .vsix 文件

  1. 发布页面下载扩展包stata-mcp-0.2.1.vsix

  2. 使用以下方法之一进行安装:

code --install-extension path/to/stata-mcp-0.2.1.vsix

或者:

  1. 打开 VS Code

  2. 转到扩展视图(Ctrl+Shift+X)

  3. 点击右上角的“...”菜单

  4. 选择“从 VSIX 安装...”

  5. 导航到并选择下载的 .vsix 文件

光标安装

  1. 发布页面下载扩展包stata-mcp-0.2.2.vsix

  2. 使用以下方法之一进行安装:

cursor --install-extension path/to/stata-mcp-0.2.2.vsix

或者:

  1. 打开游标

  2. 转到扩展视图

  3. 点击“...”菜单

  4. 选择“从 VSIX 安装”

  5. 导航到并选择下载的 .vsix 文件

从 0.1.8 版本开始,该扩展集成了一个名为uv的快速 Python 包安装程序来设置环境。如果您的系统上未找到 uv,该扩展将尝试自动安装它。

扩展设置

您可以通过 VS Code 设置自定义扩展行为:

  • stata-vscode.stataPath :Stata 安装目录的路径

  • stata-vscode.mcpServerHost :MCP 服务器的主机(默认值:localhost)

  • stata-vscode.mcpServerPort :MCP 服务器的端口(默认值:4000)

  • stata-vscode.autoStartServer :扩展激活时自动启动 MCP 服务器(默认值:true)

  • stata-vscode.debugMode :在输出面板中显示详细的调试信息(默认值:false)

  • stata-vscode.forcePort :强制 MCP 服务器使用指定端口,即使该端口已被使用(默认值:false)

  • stata-vscode.clineConfigPath :Cline 配置文件的自定义路径(可选,默认为标准位置)

  • stata-vscode.runFileTimeout :'运行文件'操作的超时时间(秒)(默认值:600 秒/10 分钟)

用法

  1. 打开 Stata .do 文件

  2. 使用以下命令运行命令:

    • 运行选择:选择 Stata 代码并按Ctrl+Shift+Enter (或在 Mac 上Cmd+Shift+Enter

    • 运行文件:按Ctrl+Shift+D (或 Mac 上的Cmd+Shift+D )运行整个 .do 文件

  3. 在编辑器面板中查看输出

工作原理

该扩展创建一个本地 MCP 服务器,将您的编辑器连接到 Stata,从而实现:

  1. 命令执行:运行 Stata 命令并立即查看结果

  2. 上下文感知:AI 助手了解您的 Stata 数据和命令

  3. 提高生产力:获得智能代码建议和文档

光标 MCP 配置

该扩展程序会自动配置 Cursor MCP 集成。要验证其是否正常工作,请执行以下操作:

  1. 打开游标

  2. Ctrl+Shift+P (或 Mac 上的Cmd+Shift+P )打开命令面板

  3. 输入“Stata:测试 MCP 服务器连接”并按 Enter 键

  4. 如果服务器连接正确,您应该会看到一条成功消息

游标配置文件路径

Cursor MCP 配置文件的位置因操作系统而异:

  • macOS 系统

    • 主要位置: ~/.cursor/mcp.json

    • 备用位置: ~/Library/Application Support/Cursor/User/mcp.json

  • 窗户

    • 主要位置: %USERPROFILE%\.cursor\mcp.json

    • 备用位置: %APPDATA%\Cursor\User\mcp.json

  • Linux

    • 主要位置: ~/.cursor/mcp.json

    • 备用位置: ~/.config/Cursor/User/mcp.json

手动光标配置

如果需要手动配置Cursor MCP:

  1. 创建或编辑 MCP 配置文件:

    • macOS/Linux~/.cursor/mcp.json

    • Windows%USERPROFILE%\.cursor\mcp.json

  2. 添加Stata MCP服务器配置:

    { "mcpServers": { "stata-mcp": { "url": "http://localhost:4000/mcp", "transport": "sse" } } }
  3. 如果该文件已经包含其他 MCP 服务器,只需将"stata-mcp"条目添加到现有的"mcpServers"对象。

  4. 保存文件并重新启动 Cursor。

光标配置故障排除

如果 Cursor 无法识别 Stata MCP 服务器:

  1. 验证 MCP 服务器是否正在运行

  2. 检查配置文件是否存在且内容正确

  3. 尝试重新启动 Cursor

  4. 确保没有与其他正在运行的应用程序的端口冲突

Cline MCP 配置

  1. 打开您的 Cline MCP 设置文件:

    • macOS~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json

    • Windows%APPDATA%/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json

    • Linux~/.config/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json

  2. 添加Stata MCP服务器配置:

    { "mcpServers": { "stata-mcp": { "url": "http://localhost:4000/mcp", "transport": "sse" } } }
  3. 如果该文件已经包含其他 MCP 服务器,只需将"stata-mcp"条目添加到现有的"mcpServers"对象。

  4. 保存文件并重新启动 VS Code。

您还可以通过 VS Code 设置配置 Cline:

"cline.mcpSettings": { "stata-mcp": { "url": "http://localhost:4000/mcp", "transport": "sse" } }

Cline 配置故障排除

如果 Cline 无法识别 Stata MCP 服务器:

  1. 验证 MCP 服务器正在运行(状态栏应显示“Stata”)

  2. 检查配置文件是否存在且内容正确

  3. 尝试重启 VS Code

  4. 检查扩展输出面板(视图 > 输出 > Stata MCP)是否有任何错误

Claude Desktop MCP 配置

您可以通过 mcp-proxy 与 Claude Desktop 一起使用此扩展:

  1. 在尝试配置 Claude Desktop 之前,请确保 Stata MCP 扩展已安装在 VS Code 或 Cursor 中并且正在运行

  2. 安装 mcp-proxy:

    # Using pip pip install mcp-proxy # Or using uv (faster) uv install mcp-proxy
  3. 找到 mcp-proxy 的路径:

    # On Mac/Linux which mcp-proxy # On Windows (PowerShell) (Get-Command mcp-proxy).Path
  4. 通过编辑 MCP 配置文件来配置 Claude Desktop:

    在 Windows 上(通常位于%APPDATA%\Claude Desktop\claude_desktop_config.json ):

    { "mcpServers": { "stata-mcp": { "command": "mcp-proxy", "args": ["http://127.0.0.1:4000/mcp"] } } }

    在 macOS 上(通常位于~/Library/Application Support/Claude Desktop/claude_desktop_config.json ):

    { "mcpServers": { "stata-mcp": { "command": "/path/to/mcp-proxy", "args": ["http://127.0.0.1:4000/mcp"] } } }

    /path/to/mcp-proxy替换为您在步骤 3 中找到的实际路径。

  5. 重启Claude桌面

  6. Claude Desktop 将自动发现可用的 Stata 工具,允许您运行 Stata 命令并直接从对话中分析数据。

**注意:**还有另一种方法可以在 Claude Desktop 中使用 Stata MCP,而无需安装此扩展程序。请参阅此处

Python环境管理

此扩展使用uv (一个用 Rust 构建的快速 Python 包安装程序)来管理 Python 依赖项。主要功能:

  • 自动 Python 设置和依赖项管理

  • 创建不会与您的系统冲突的隔离环境

  • 适用于 Windows、macOS 和 Linux

  • 比传统 pip 安装速度快 10-100 倍

如果您在安装过程中遇到任何与 UV 相关的错误:

  1. 手动安装UV:

    # Windows (PowerShell as Administrator) powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" # macOS/Linux curl -LsSf https://astral.sh/uv/install.sh | sh
  2. 按照故障排除步骤重新安装扩展程序

从 0.1.8 版本开始,此扩展集成了快速 Python 包安装程序uv来设置环境。如果您的系统上未找到 uv,扩展将尝试自动安装。

故障排除

如果您遇到扩展问题,请按照以下步骤执行全新重新安装:

视窗

  1. 关闭所有 VS Code/Cursor 窗口

  2. 打开任务管理器(Ctrl+Shift+Esc):

    • 转到“进程”选项卡

    • 查找任何正在运行的 Python 或uvicorn进程

    • 选择每个并单击“结束任务”

  3. 删除扩展文件夹:

    • 按 Win+R,输入%USERPROFILE%\.vscode\extensions并按 Enter

    • 删除文件夹deepecon.stata-mcp-0.xx (其中xx是版本号)

    • 对于 Cursor:路径为%USERPROFILE%\.cursor\extensions

  4. 手动安装 UV(如果需要):

    # Open PowerShell as Administrator and run: powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
  5. 重新启动计算机(推荐但可选)

  6. 从市场安装最新版本的扩展程序

macOS/Linux

  1. 关闭所有 VS Code/Cursor 窗口

  2. 终止所有正在运行的 Python 进程:

    # Find Python processes ps aux | grep python # Kill them (replace <PID> with the process numbers you found) kill -9 <PID>
  3. 删除扩展文件夹:

    # For VS Code: rm -rf ~/.vscode/extensions/deepecon.stata-mcp-0.x.x # For Cursor: rm -rf ~/.cursor/extensions/deepecon.stata-mcp-0.x.x
  4. 手动安装 UV(如果需要):

    # Using curl: curl -LsSf https://astral.sh/uv/install.sh | sh # Or using wget: wget -qO- https://astral.sh/uv/install.sh | sh
  5. 重新启动终端或计算机(推荐但可选)

  6. 从市场安装最新版本的扩展程序

其他故障排除提示

  • 如果您看到有关未找到 Python 或 UV 的错误,请确保它们位于系统的 PATH 中:

    • Windows:在开始菜单中输入“环境变量”并添加安装路径

    • macOS/Linux:将路径添加到~/.bashrc~/.zshrc或等效文件

  • 如果出现权限错误:

    • Windows:以管理员身份运行 VS Code/Cursor

    • macOS/Linux:使用ls -la检查文件夹权限,并根据需要使用chmod进行修复

  • 如果扩展仍然无法初始化:

    1. 打开输出面板(视图->输出)

    2. 从下拉菜单中选择“Stata-MCP”

    3. 检查日志中的具体错误消息

    4. 如果您看到与 Python 相关的错误,请尝试手动创建 Python 3.11 虚拟环境:

      # Windows py -3.11 -m venv .venv # macOS/Linux python3.11 -m venv .venv
  • 对于持续存在的问题:

    1. 检查系统的 Python 安装: python --versionpython3 --version

    2. 验证 UV 安装: uv --version

    3. 确保安装了 Python 3.11 或更高版本

    4. 检查你的防病毒软件是否阻止了 Python 或 UV 可执行文件

在 GitHub 上打开问题时,请提供:

  • 输出面板中的完整错误消息(视图 -> 输出 -> Stata-MCP)

  • 您的操作系统和版本

  • VS Code/光标版本

  • Python 版本( python --version

  • UV 版本( uv --version

  • 重现问题的步骤

  • 任何相关的日志文件或屏幕截图

  • 您的 MCP 配置文件的内容(如果适用)

这些详细信息将有助于我们更快地识别并修复问题。您可以在GitHub Issues上提交问题。

执照

麻省理工学院

致谢

作者:鹿晗 发布者:DeepEcon

-
security - not tested
-
license - not tested
-
quality - not tested

Related MCP Servers

  • -
    security
    A
    license
    -
    quality
    Facilitates integration with the Cursor code editor by enabling real-time code indexing, analysis, and bi-directional communication with Claude, supporting concurrent sessions and automatic reconnection.
    Last updated -
    4
    38
    MIT License
  • -
    security
    -
    license
    -
    quality
    An AI-powered development toolkit for Cursor providing intelligent coding assistance through advanced reasoning, UI screenshot analysis, and code review tools.
    Last updated -
    429
    337
    MIT License
  • -
    security
    -
    license
    -
    quality
    A Cursor-compatible toolkit that provides intelligent coding assistance through custom AI tools for code architecture planning, screenshot analysis, code review, and file reading capabilities.
    Last updated -
    429
    11
    MIT License
  • -
    security
    -
    license
    -
    quality
    A collection of Laravel helper tools for integration with Cursor IDE, providing features like log viewing, error searching, artisan command execution, and model information display directly within the editor.
    Last updated -
    12
    MIT License

View all related MCP servers

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/hanlulong/stata-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server