Skip to main content

MCP server for interacting with Prefect

Project description

prefect-mcp-server

[!WARNING] This project is under active development and may change drastically at any time.

This is an experimental MCP server for Prefect. APIs, features, and behaviors are subject to change without notice. We encourage you to try it out, provide feedback, and contribute. Please create issues or open PRs with your ideas and suggestions.

An MCP server for interacting with prefect resources.

The server gives MCP clients read-only tools for inspecting Prefect Cloud and self-hosted Prefect instances, plus a docs proxy so assistants can look up current Prefect CLI, SDK, and deployment guidance.

Choose Your Setup

Use case Recommended setup Authentication
Claude Code on your machine Claude Code plugin Active local Prefect profile
Local MCP client uvx stdio server Active local Prefect profile or env vars
Self-hosted Prefect or custom Cloud workspace Self-hosted HTTP or stdio server API key, basic auth, env vars, or headers
Team-operated shared server HTTP deployment with per-request headers User or service-account credentials in headers

Claude Code Plugin

The easiest local setup for Claude Code is the Prefect plugin:

# 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 local uvx setup below.

Run Locally

When running the MCP server locally with stdio transport, it automatically uses your local Prefect configuration from ~/.prefect/profiles.toml if available.

# minimal setup - inherits from local Prefect profile
claude mcp add prefect \
  -- uvx --from prefect-mcp prefect-mcp-server

# or explicitly set 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

[!NOTE] For self-hosted Prefect servers with basic auth, use PREFECT_API_AUTH_STRING instead of PREFECT_API_KEY.

[!TIP] Prefect Cloud users on Team, Pro, and Enterprise plans can use service accounts for API authentication. Pro and Enterprise users can restrict service accounts to read-only access since this MCP server requires no write permissions.

Deploy Your Own Server

Deploy your own server when you need a custom Prefect API target, self-hosted Prefect, a private network, or an API-key-based team deployment.

  1. Fork this repository on GitHub:

    gh repo fork prefecthq/prefect-mcp-server
    
  2. Deploy it on Prefect Horizon or FastMCP Cloud.

  3. Configure the server:

    • server path: src/prefect_mcp_server/server.py
    • requirements: pyproject.toml
    • environment variables:
      • PREFECT_API_URL: https://api.prefect.cloud/api/accounts/[ACCOUNT_ID]/workspaces/[WORKSPACE_ID]
      • PREFECT_API_KEY: your Prefect Cloud API key
      • PREFECT_API_AUTH_STRING: basic auth credentials for self-hosted Prefect, if needed
  4. Add the deployed HTTP URL to your MCP client:

    claude mcp add prefect --transport http https://your-server-name.fastmcp.app/mcp
    

[!NOTE] For self-hosted deployments, environment variables are configured on the deployed MCP server, not in your MCP client configuration. The MCP host authenticates access to the MCP server, while this server uses the configured Prefect credentials to access Prefect.

Experimental Prefect Cloud OAuth MCP

Prefect is experimenting with a hosted Prefect Cloud MCP deployment that uses HTTP MCP OAuth instead of asking users to create or paste API keys. This is not the default setup path yet, and it is only available where Prefect Cloud MCP OAuth has been enabled.

When enabled, a user can add the hosted MCP URL to their client:

claude mcp add prefect-cloud \
  --transport http https://prefect-cloud-mcp-server.fastmcp.app/mcp

The MCP client discovers OAuth metadata from the server, opens a browser for Prefect Cloud authentication, and asks the user to choose the workspaces this MCP client may read. After authentication, the assistant can list the consented workspaces and call the same read-only Prefect tools against those workspaces.

Cloud OAuth mode:

  • uses HTTP MCP OAuth, not stdio credentials
  • does not require PREFECT_API_KEY in the MCP client
  • limits workspace-scoped tools to the workspaces selected during consent
  • requires workspace-scoped tool calls to include a workspace_id
  • keeps the shared read-only tool definitions from this repository

Useful first prompts:

  • "Tell me what Prefect workspaces you can access."
  • "Look across all authorized workspaces and summarize recent failed flow runs."
  • "Compare deployment health between my staging and production workspaces."

Unattended Service-Account Clients

Browser OAuth is the right flow for human-operated MCP clients. Workflow agents and other noninteractive runtimes should use service-account MCP OAuth credentials issued by Prefect Cloud, exchange those credentials for an MCP bearer token, and connect to the hosted MCP URL with an Authorization header.

export PREFECT_MCP_CLOUD_CLIENT_ID=...
export PREFECT_MCP_CLOUD_CLIENT_SECRET=...

uvx --from prefect-mcp prefect-mcp-cloud-token

Agents can also exchange credentials in process before constructing their MCP client:

from fastmcp import Client
from fastmcp.client.transports import StreamableHttpTransport
from prefect_mcp_server.cloud_oauth import exchange_client_credentials_token

token = await exchange_client_credentials_token()
transport = StreamableHttpTransport(
    url="https://prefect-cloud-mcp-server.fastmcp.app/mcp",
    headers={"Authorization": f"Bearer {token.access_token}"},
)

async with Client(transport) as client:
    print(await client.list_tools())

The token response includes expires_in. Treat an agent as long-running if it may keep using the MCP connection longer than that returned lifetime. In that case, request a new token with the same client credentials before reusing the MCP connection. This follows the OAuth client-credentials pattern: the client credentials are the renewable secret, and the access token is the time-limited bearer credential sent to the MCP server.

Cloud OAuth Deployment Entrypoint

Prefect-operated Cloud OAuth deployments use a dedicated entrypoint:

  • server path: src/prefect_mcp_server/cloud.py
  • required runtime secret: PREFECT_MCP_CLOUD_AUTH_TOKEN_KEY

This entrypoint reuses the same read-only tool definitions as the local/API-key server, adds Prefect Cloud OAuth, and adds Cloud OAuth-only workspace discovery. If OAuth is not configured, the Cloud OAuth entrypoint fails at import time instead of starting an unprotected server.

Cloud OAuth mode is selected by deploying src/prefect_mcp_server/cloud.py. The token key is the required runtime secret for validating Prefect Cloud-issued MCP OAuth access tokens; it is not a user-provided Prefect API key.

Cloud OAuth configuration reference

Cloud OAuth settings use the PREFECT_MCP_CLOUD_ prefix:

Environment variable Purpose
PREFECT_MCP_CLOUD_AUTH_TOKEN_KEY Required signing/verification key for Prefect Cloud issued MCP OAuth access tokens
PREFECT_MCP_CLOUD_API_BASE_URL Optional override for the Prefect API base URL
PREFECT_MCP_CLOUD_AUTH_BASE_URL Optional override for auth helper endpoints
PREFECT_MCP_CLOUD_AUTHORIZATION_SERVER Optional override for advertised OAuth authorization server
PREFECT_MCP_CLOUD_CLIENT_ID Optional service-account MCP OAuth client id for unattended token exchange
PREFECT_MCP_CLOUD_CLIENT_SECRET Optional service-account MCP OAuth client secret for unattended token exchange
PREFECT_MCP_CLOUD_PUBLIC_BASE_URL Public base URL for the hosted MCP server
PREFECT_MCP_PUBLIC_BASE_URL Legacy alias for the public base URL
Multi-tenant deployments with HTTP headers

For centrally-hosted deployments where multiple users connect to the same MCP server instance, credentials can be passed via HTTP headers instead of environment variables. This enables each request to authenticate with its own Prefect workspace.

Supported headers:

  • X-Prefect-Api-Url: Prefect API URL, required for both Cloud and self-hosted Prefect
  • X-Prefect-Api-Key: Prefect Cloud API key
  • X-Prefect-Api-Auth-String: basic auth credentials for self-hosted Prefect, formatted as username:password

Claude Code CLI:

claude mcp add-json prefect '{
  "type": "http",
  "url": "https://your-server.fastmcp.app/mcp",
  "headers": {
    "X-Prefect-Api-Url": "https://api.prefect.cloud/api/accounts/[ACCOUNT_ID]/workspaces/[WORKSPACE_ID]",
    "X-Prefect-Api-Key": "your-api-key"
  }
}'

Claude Desktop app:

{
  "mcpServers": {
    "prefect": {
      "type": "http",
      "url": "https://your-server.fastmcp.app/mcp",
      "headers": {
        "X-Prefect-Api-Url": "https://api.prefect.cloud/api/accounts/[ACCOUNT_ID]/workspaces/[WORKSPACE_ID]",
        "X-Prefect-Api-Key": "your-api-key"
      }
    }
  }
}

Python with FastMCP client:

from fastmcp.client import Client
from fastmcp.client.transports import StreamableHttpTransport

headers = {
    "X-Prefect-Api-Url": "https://api.prefect.cloud/api/accounts/[ACCOUNT_ID]/workspaces/[WORKSPACE_ID]",
    "X-Prefect-Api-Key": "your-api-key",
}

transport = StreamableHttpTransport(
    url="https://your-server.fastmcp.app/mcp",
    headers=headers,
)
client = Client(transport=transport)

async with client:
    result = await client.call_tool("get_identity", {})
    print(result)

[!NOTE] When HTTP headers are provided, they take precedence over environment variables. If no headers are present, the server falls back to the configured environment variables or local Prefect profile.

Other MCP Clients

Configuration examples

This MCP server works with any MCP-compatible client. Most local clients use the same stdio command and optional environment variables.

Cursor (.cursor/mcp.json):

{
  "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-api-key"
      }
    }
  }
}

Codex CLI:

codex mcp add prefect -- uvx --from prefect-mcp prefect-mcp-server

codex mcp add prefect \
  --env PREFECT_API_URL=https://api.prefect.cloud/api/accounts/[ACCOUNT_ID]/workspaces/[WORKSPACE_ID] \
  --env PREFECT_API_KEY=your-api-key \
  -- uvx --from prefect-mcp prefect-mcp-server

Or edit ~/.codex/config.toml directly:

[mcp.prefect]
command = "uvx"
args = ["--from", "prefect-mcp", "prefect-mcp-server"]

[mcp.prefect.env]
PREFECT_API_URL = "https://api.prefect.cloud/api/accounts/[ACCOUNT_ID]/workspaces/[WORKSPACE_ID]"
PREFECT_API_KEY = "your-api-key"

Gemini CLI:

gemini mcp add prefect uvx --from prefect-mcp prefect-mcp-server

gemini mcp add prefect \
  -e PREFECT_API_URL=https://api.prefect.cloud/api/accounts/[ACCOUNT_ID]/workspaces/[WORKSPACE_ID] \
  -e PREFECT_API_KEY=your-api-key \
  uvx --from prefect-mcp prefect-mcp-server

Or edit ~/.gemini/settings.json directly:

{
  "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-api-key"
      }
    }
  }
}

Kiro (~/.kiro/settings/mcp.json):

{
  "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-api-key"
      }
    }
  }
}

VS Code with GitHub Copilot (.vscode/mcp.json):

{
  "servers": {
    "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-api-key"
      }
    }
  }
}

Windsurf (~/.codeium/windsurf/mcp_config.json):

{
  "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-api-key"
      }
    }
  }
}

[!TIP] Most MCP clients follow a similar configuration pattern. If your client is not listed here, check its documentation for MCP server configuration. The command, args, and env values above usually work with minor adjustments to the config format.

Capabilities

This server enables MCP clients to interact with Prefect read-only APIs:

Monitoring and inspection

  • View dashboard overviews with flow run statistics and work pool status
  • Query deployments, flows, flow runs, task runs, work pools, and automations with advanced filtering
  • Retrieve detailed execution logs from flow runs
  • Track events across your workflow ecosystem
  • Review rate limit usage for Prefect Cloud

Documentation access

  • Search current Prefect documentation through the mounted docs MCP server
  • Find current CLI and SDK syntax for write operations
  • Look up deployment, work pool, and automation patterns

Intelligent debugging

  • Get contextual guidance for troubleshooting failed flow runs
  • Diagnose deployment issues, including concurrency problems and unhealthy work pools
  • Identify root causes of workflow failures

Development

Setup and testing
# clone the repo
gh repo clone prefecthq/prefect-mcp-server && cd prefect-mcp-server

# install dev deps and pre-commit hooks
just setup

# run tests
just test

Evals

This project includes scenario tests that connect Pydantic AI agents to the MCP server and validate that they can solve realistic Prefect support tasks. See evals/README.md.

Evals should be written like support case reproductions: set up a workspace state that represents a real customer problem, ask the agent the kind of question a user or support engineer would ask, and verify the final answer identifies the concrete cause or next action. Protocol behavior such as OAuth token validation belongs in unit tests; evals should prove that the MCP server helps an agent solve user-facing Prefect problems.

uv run pytest evals

Links


mcp-name: io.github.PrefectHQ/prefect-mcp-server

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prefect_mcp-0.0.1b12.tar.gz (433.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prefect_mcp-0.0.1b12-py3-none-any.whl (45.5 kB view details)

Uploaded Python 3

File details

Details for the file prefect_mcp-0.0.1b12.tar.gz.

File metadata

  • Download URL: prefect_mcp-0.0.1b12.tar.gz
  • Upload date:
  • Size: 433.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for prefect_mcp-0.0.1b12.tar.gz
Algorithm Hash digest
SHA256 aa5e77022352117ad6d548b362b242262da30a49fc7273d6574932b58d7b4485
MD5 b43001e171ebe27fba353dd669d5e784
BLAKE2b-256 d539baa199e6ba0f2cbc54e3138ab9276e9f21e30aff0c4e6e8a02fea7b9971a

See more details on using hashes here.

File details

Details for the file prefect_mcp-0.0.1b12-py3-none-any.whl.

File metadata

  • Download URL: prefect_mcp-0.0.1b12-py3-none-any.whl
  • Upload date:
  • Size: 45.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for prefect_mcp-0.0.1b12-py3-none-any.whl
Algorithm Hash digest
SHA256 29a1959a25c091dde735a5223ac6b4ff8348570780bac797d69ab825bc4b09d5
MD5 25346950421bd111d2dea3d60d7683f7
BLAKE2b-256 4bd9cf29a0239ff12180caa7568154b74c372695843eb95958b1638e52260989

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page