Stata

Provides an MCP bridge to a local Stata installation for code execution, data inspection, and graph export.
  • python

11

GitHub Stars

python

Language

5 months ago

First Indexed

2 months ago

Catalog Refreshed

Documentation & install

Readme and setup notes from the catalogue, plus a client-ready config you can copy for your MCP host.

Installation

Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "tmonk-mcp-stata": {
      "command": "uvx",
      "args": [
        "--refresh",
        "--from",
        "mcp-stata@latest",
        "mcp-stata"
      ],
      "env": {
        "MCP_STATA_LOGLEVEL": "DEBUG"
      }
    }
  }
}

You can run a Stata MCP Server that lets AI agents connect to a local Stata installation, execute Stata commands, inspect data, export graphics, and verify results. It’s designed to work with MCP clients through a standard stdio transport, giving you a streamlined way to automate Stata workflows with AI assistance.

How to use

You will run the server as a local, stdio-based MCP endpoint and connect your MCP client to it. The server exposes commands to execute Stata syntax, load data, describe datasets, view graphs, and fetch stored results. Use the provided MCP client tooling to start the server and issue tasks such as running a regression, generating a summary of a dataset, or exporting a graph for visualization.

How to install

Prerequisites include Stata 17+ and Python 3.12+. You should also have the MCP tool runner available in your environment.

uvx --refresh --from mcp-stata@latest mcp-stata

# uvx is an alias for uv tool run and executes the MCP tool in an isolated, cached environment.

Configuration and usage notes

The server auto-discovers your Stata installation from common paths and StataNow. If discovery fails, set the STATA_PATH environment variable to your Stata executable and include it in your MCP server’s env if needed.

# macOS example
export STATA_PATH="/Applications/StataNow/StataMP.app/Contents/MacOS/stata-mp"

# Windows example (cmd.exe)
set STATA_PATH="C:\Program Files\Stata18\StataMP-64.exe"

Security and data access

Interacting with data and results happens through a controlled interface that exposes dataset summaries, variable metadata, and stored results. The UI data browser is locally hosted, requires a bearer token, and is designed to be loopback only for safety. When you fetch data or run commands, the server provides structured JSON responses that include outputs, logs, and any error messages from Stata.

Troubleshooting and tips

If you need progress updates during long-running tasks, pass a progress token. You can cancel in-flight requests by sending a cancellation notification with the original request ID. Expect partial log data during cancellation, since the operation may terminate before all output is written.

If you run into discovery issues for Stata, verify STATA_PATH points to the correct Stata executable and that Python 3.12+ is available in your environment. Check the server log level to DEBUG for more details if you’re troubleshooting integration problems.

Notes

The MCP server provides a comprehensive set of tools for interacting with Stata, including command execution, data loading, graph export, and access to stored results. You can also obtain dataset descriptions and variable metadata, list and export graphs, and work with filtered views and paging through the local UI API when needed.

End-to-end example workflow

  1. Start the MCP server using your preferred MCP client tooling.
  2. Connect to the server via the MCP client and execute a Stata command like sysuse auto or regress price mpg.
  3. Retrieve a dataset summary and variable codebooks to understand the data structure.
  4. Generate and export a graph to visualize relationships, then fetch stored results (r() and e()) to verify model outputs.

Maintenance and updates

Keep your Stata MCP Server up to date by refreshing the MCP tool and updating the mcp-stata package in your environment as new releases become available. If you use a local install method, re-run the install command to swap to the latest version when prompted.

Available tools

run_command

Execute Stata commands and return output, logs, and optional progress updates via a structured JSON envelope.

read_log

Read a portion of a previously emitted log file, returning path, offset, next_offset, and data.

load_data

Load data from common sources (sysuse, webuse, use, or URL) and return a JSON envelope.

get_data

View dataset rows in JSON, capped to a maximum number of rows.

get_ui_channel

Obtain a short-lived HTTP endpoint and token for UI data browser access.

describe

Return dataset structure information using Stata describe.

list_graphs

Provide a list of in-memory graphs with an active flag.

export_graph

Export a single graph to a file path in PDF or PNG format.

export_graphs_all

Export all in-memory graphs and return their file paths.

get_help

Fetch and render Stata help topics, with an option for plain text.

codebook

Retrieve variable metadata, including labels and formats, in JSON.

run_do_file

Execute a .do file and stream output with a log path for client tailing.

get_stored_results

Fetch r() and e() stored results as JSON for verification.

get_variable_list

Return a JSON list of variables and their labels.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational