docs/v3/how-to-guides/ai/use-prefect-mcp-server.mdx
The Prefect MCP server enables AI assistants to interact with your Prefect workflows and infrastructure through the Model Context Protocol (MCP). This integration allows AI tools like Claude Code, Cursor, and Codex CLI to help you monitor deployments, debug flow runs, query infrastructure, and more.
<Warning> The Prefect MCP server is currently in beta. APIs, features, and behaviors may change without notice. We encourage you to try it out and provide feedback through [GitHub issues](https://github.com/PrefectHQ/prefect-mcp-server/issues). </Warning>The Prefect MCP server is an MCP server that provides AI assistants with tools to:
The MCP tools are primarily designed for reading data and monitoring your Prefect instance. For creating or updating resources, the integrated docs proxy provides AI assistants with current information on how to use the prefect CLI.
The Prefect MCP server provides read-only access to your Prefect instance. It can only access information available to the account you authenticate with—it cannot access data outside those bounds.
<Warning> **Important:** The MCP server does not operate in isolation. MCP clients (such as Claude Code, Cursor, or Codex CLI) may have additional capabilities beyond the MCP server's read-only tools. For example, an AI assistant with terminal access could execute destructive CLI commands like `prefect deployment delete` independently of the MCP server.When using AI agents autonomously, consider the Prefect Role associated with your API key and what actions the agent could take through other means (CLI, SDK, etc.). </Warning>
For detailed answers to common security questions—including authentication patterns, RBAC, file access requirements, and recommendations for internal pilots—see the Security FAQ.
Install and run the MCP server locally using uvx:
uvx --from prefect-mcp prefect-mcp-server
When running locally with stdio transport, the server automatically inherits credentials from your active Prefect profile (~/.prefect/profiles.toml).
Deploy the MCP server to Prefect Horizon for remote access:
Fork the prefect-mcp-server repository on GitHub
Sign in to horizon.prefect.io
Create a new server pointing to your fork:
src/prefect_mcp_server/server.pypyproject.toml (or leave blank)Configure environment variables in the Prefect Horizon interface:
| Environment Variable | Prefect Cloud | Self-hosted Prefect |
|---|---|---|
PREFECT_API_URL | https://api.prefect.cloud/api/ |
accounts/[ACCOUNT_ID]/
workspaces/[WORKSPACE_ID] | Your Prefect server URL (e.g., http://your-server:4200/api) |
| PREFECT_API_KEY | Your Prefect Cloud API key | Not used |
| PREFECT_API_AUTH_STRING | Not used | Your authentication string (if using basic auth) |
5. Get your server URL (e.g., https://your-server-name.fastmcp.app/mcp)
Configure your AI assistant to connect to the Prefect MCP server.
All MCP clients need three pieces of information to connect to the Prefect MCP server:
uvx--from prefect-mcp prefect-mcp-serverThe configuration format varies by client. Choose your client below for specific setup instructions:
<AccordionGroup> <Accordion title="Claude Code">Marketplace install (recommended)
The easiest way to get started with Claude Code is through the plugin marketplace:
# Add from marketplace
/plugin marketplace add prefecthq/prefect-mcp-server
# Install the plugin
/plugin install prefect
This installs both the MCP server (for read-only diagnostics) and a CLI skill (for mutations like triggering deployments or cancelling runs).
<Note> The plugin uses your local Prefect configuration from `~/.prefect/profiles.toml`. For explicit credentials, use the manual setup below. </Note>Manual setup
Alternatively, add the Prefect MCP server to Claude Code using the CLI:
# Minimal setup - inherits from local Prefect profile
claude mcp add prefect -- uvx --from prefect-mcp prefect-mcp-server
# With explicit Prefect Cloud credentials
claude mcp add prefect \
-e PREFECT_API_URL=https://api.prefect.cloud/api/accounts/[ACCOUNT_ID]/workspaces/[WORKSPACE_ID] \
-e PREFECT_API_KEY=your-cloud-api-key \
-- uvx --from prefect-mcp prefect-mcp-server
# With Prefect Horizon deployment (HTTP transport)
claude mcp add prefect --transport http https://your-server-name.fastmcp.app/mcp
Add the Prefect MCP server to Cursor by creating or editing .cursor/mcp.json in your project:
{
"mcpServers": {
"prefect": {
"command": "uvx",
"args": ["--from", "prefect-mcp", "prefect-mcp-server"]
}
}
}
To use explicit credentials, add an env section:
{
"mcpServers": {
"prefect": {
"command": "uvx",
"args": ["--from", "prefect-mcp", "prefect-mcp-server"],
"env": {
"PREFECT_API_URL": "https://api.prefect.cloud/api/accounts/[ACCOUNT_ID]/workspaces/[WORKSPACE_ID]",
"PREFECT_API_KEY": "your-cloud-api-key"
}
}
}
}
Add the Prefect MCP server to Codex using the CLI:
# Minimal setup - inherits from local Prefect profile
codex mcp add prefect -- uvx --from prefect-mcp prefect-mcp-server
# With explicit Prefect Cloud credentials
codex mcp add prefect \
--env PREFECT_API_URL=https://api.prefect.cloud/api/accounts/[ACCOUNT_ID]/workspaces/[WORKSPACE_ID] \
--env PREFECT_API_KEY=your-cloud-api-key \
-- uvx --from prefect-mcp prefect-mcp-server
Alternatively, edit ~/.codex/config.toml directly:
[mcp.prefect]
command = "uvx"
args = ["--from", "prefect-mcp", "prefect-mcp-server"]
# For explicit credentials, add:
[mcp.prefect.env]
PREFECT_API_URL = "https://api.prefect.cloud/api/accounts/[ACCOUNT_ID]/workspaces/[WORKSPACE_ID]"
PREFECT_API_KEY = "your-cloud-api-key"
Add the Prefect MCP server to Gemini CLI using the CLI:
# STDIO transport - runs locally with uvx
gemini mcp add prefect uvx --from prefect-mcp prefect-mcp-server
# With explicit Prefect Cloud credentials
gemini mcp add prefect \
-e PREFECT_API_URL=https://api.prefect.cloud/api/accounts/[ACCOUNT_ID]/workspaces/[WORKSPACE_ID] \
-e PREFECT_API_KEY=your-cloud-api-key \
uvx --from prefect-mcp prefect-mcp-server
# HTTP transport - for Prefect Horizon deployment
gemini mcp add prefect --transport http https://your-server-name.fastmcp.app/mcp
Alternatively, edit ~/.gemini/settings.json directly:
For STDIO transport (local):
{
"mcpServers": {
"prefect": {
"command": "uvx",
"args": ["--from", "prefect-mcp", "prefect-mcp-server"]
}
}
}
For STDIO transport with explicit credentials:
{
"mcpServers": {
"prefect": {
"command": "uvx",
"args": ["--from", "prefect-mcp", "prefect-mcp-server"],
"env": {
"PREFECT_API_URL": "https://api.prefect.cloud/api/accounts/[ACCOUNT_ID]/workspaces/[WORKSPACE_ID]",
"PREFECT_API_KEY": "your-cloud-api-key"
}
}
}
}
For HTTP transport (Prefect Horizon):
{
"mcpServers": {
"prefect": {
"httpUrl": "https://your-server-name.fastmcp.app/mcp"
}
}
}
The Prefect MCP server authenticates with your Prefect instance using the same configuration as the Prefect SDK.
When running locally without environment variables, the server inherits credentials from your active Prefect profile:
~/.prefect/profiles.tomlprefect CLI commandsOverride the default credentials by setting environment variables:
For Prefect Cloud:
PREFECT_API_URL=https://api.prefect.cloud/api/accounts/[ACCOUNT_ID]/workspaces/[WORKSPACE_ID]
PREFECT_API_KEY=your-cloud-api-key
For self-hosted Prefect with basic auth:
PREFECT_API_URL=http://your-server:4200/api
PREFECT_API_AUTH_STRING=your-auth-string
https://app.prefect.cloud/account/[ACCOUNT-ID]/workspace/[WORKSPACE-ID]/dashboard
</Tip>
Environment variables take precedence over profile settings:
PREFECT_API_URL, PREFECT_API_KEY)~/.prefect/profiles.toml)The Prefect MCP server provides these main capabilities:
The MCP server includes a built-in docs proxy that provides AI assistants with up-to-date information from the Prefect documentation. This enables your AI assistant to:
prefect CLI commands for creating and updating resourcesThe MCP tools are read-only. For create/update operations, use prefect CLI or SDK commands (often guided by docs proxy lookups).
To get the most out of the Prefect MCP server, guide your AI assistant with these patterns:
The MCP tools are optimized for reading and monitoring. For creating or updating resources, prompt your assistant to use the prefect CLI:
Example prompts:
prefect CLI to create a new deployment"prefect"prefect CLI"The integrated docs proxy gives your assistant access to current Prefect documentation:
Example prompts:
The MCP server excels at helping diagnose issues:
Example prompts: