<@ULVA73B9P> can you point me to some good example...
# ask-marvin
a
@Marvin can you point me to some good example of specific use cases for prefect mcp server?
m
thought for 129.7 seconds
Absolutely—here are concrete, high‑signal examples you can use today with the Prefect MCP server, plus links to working demos and docs. Key links - Repo: prefect-mcp-server - How‑to guide: Use the Prefect MCP server - End‑to‑end demo project (human‑in‑the‑loop cleanup with optional AI): prefect-mcp-server-demo - MCP spec: Model Context Protocol Specific, practical use cases 1) Human‑in‑the‑loop maintenance (safe cleanup, approvals) - What: Propose and preview cleanup of old flow runs, get human approval, then execute. - Why: Reduces toil while staying safe in prod. - How: Demo shows staged approval + optional AI confidence scoring. - Link: prefect-mcp-server-demo 2) “Why did this fail?” post‑mortem pack - Ask your assistant: - “Find the last failed run of X, summarize the failure, and attach the logs.” - Behind the scenes: -
get_flow_runs
get_flow_run_logs
read_events
- Example filter you can reference:
Copy code
{
  "state": {
    "type": {
      "any_": [
        "FAILED",
        "CRASHED"
      ]
    }
  },
  "flow_name": {
    "eq_": "my-flow"
  },
  "limit": 1
}
3) Deployment not running / delayed triage - Ask: - “Which work pools are missing active workers?” - “Show me deployments that are paused or starved by concurrency.” - Behind the scenes: -
get_work_pools
for worker status and concurrency limits -
get_deployments
for paused/tagged queues - Handy filters:
Copy code
{"paused": {"eq_": true}}        # paused deployments
  {"concurrency_limit": {"gt_": 0}} # pools with limits
4) SLA breach and latency diagnostics - Ask: - “List runs started in the last 24h that took >30m or retried >3 times.” - Tools: -
get_flow_runs
with duration/retries filters;
get_task_runs
for hotspots - Example filter:
Copy code
{
  "start_time": {
    "after_": "2025-01-01T00:00:00Z"
  },
  "total_run_time_seconds": {
    "gt_": 1800
  }
}
5) Cloud API rate‑limit root cause (Cloud only) - Ask: - “Were we rate‑limited yesterday? Which operation groups?” - Tool: -
review_rate_limits(since, until)
summarizes throttled periods and groups. 6) Production change audit (what changed, when) - Ask: - “List current automations and any that target my prod deployments.” - Tools: -
get_automations
,
get_deployments
, and
get_object_schema
to interpret payloads. 7) Targeted event timeline reconstruction - Ask: - “Show a concise event timeline for flow run X around failure time.” - Tool: -
read_events(occurred_after, occurred_before, event_type_prefix)
to assemble a narrative. 8) Doc‑guided fix plans (safe + current) - Ask: - “Look up the latest syntax for creating a Docker work pool, then outline the steps to fix this deployment.” - Tool: -
docs:search_prefect
to pull current docs; combine with read‑only inspection for accurate plans. Quickstart (Claude / Cursor) - Claude (stdio, local credentials):
Copy code
claude mcp add prefect -- uvx --from prefect-mcp prefect-mcp-server
- Claude (HTTP via FastMCP Cloud):
Copy code
claude mcp add prefect --transport http <https://your-server-name.fastmcp.app/mcp>
- Cursor `.cursor/mcp.json`:
Copy code
{
  "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"
      }
    }
  }
}
Notes and guardrails - Read‑only by design: the MCP server inspects your Prefect 3.x workspace; changes should be done via the
prefect
CLI or UI. - Great for monitoring, debugging, and generating safe, doc‑backed action plans. - Cloud‑only tool: rate limit review.
If you share your scenario (e.g., type of failures, infra, or goals), I can tailor a couple of prompt templates and filters for your setup.
a
@Marvin im trying to get a simple summary of flow runs in different states in the last 24h; this is what I use with my prefect db :
select state_name, count(*) from flow_run group by 1 order by 2 desc
the problem is mcp server can’t seem to fetch more than 5 flow runs before reaching token limit
m
thought for 220.4 seconds
Got it — you’re running into token blowups because
get_flow_runs
returns full objects (with inlined deployment/work-pool info), so even small pages are “heavy.” Fastest, token‑light way to get counts by state for the last 24h with the Prefect MCP server: - Use
read_events
instead of
get_flow_runs
- Query
prefect.flow-run
events in the last 24h and aggregate by
state_type
- If there are many events, page by time (slice the last 24h into chunks) to stay under token limits Why this works: flow-run state changes are emitted as events, and the event payload is much smaller than full flow run objects. Drop‑in prompt you can use with your MCP‑enabled assistant
Copy code
Goal: Summarize flow run counts by state over the last 24h without fetching full flow run objects.

Plan:
1) Call the Prefect MCP tool `read_events` with:
   - event_type_prefix: "prefect.flow-run"
   - occurred_after: <ISO8601 timestamp for 24h ago, UTC>
   - limit: 500
2) Aggregate counts by state_type from the returned events.
3) If the result hits the limit and appears truncated, page by time:
   - Make additional `read_events` calls with occurred_before set to the oldest 'occurred' timestamp from the prior page, until you cover the 24h window or the page size drops below the limit.
4) Return a compact summary like:
   COMPLETED: N
   FAILED: N
   RUNNING: N
   PENDING: N
   CANCELLED: N
   CRASHED: N
Notes:
- Do NOT call `get_flow_runs` for this summary (too token heavy).
- Keep the tool result parsing minimal: only the fields needed for state counts.
Example tool args to illustrate
Copy code
{
  "event_type_prefix": "prefect.flow-run",
  "occurred_after": "2025-12-08T12:34:56Z",
  "limit": 500
}
Then, if needed:
Copy code
{
  "event_type_prefix": "prefect.flow-run",
  "occurred_after": "2025-12-08T12:34:56Z",
  "occurred_before": "<oldest_occurred_from_previous_page>",
  "limit": 500
}
Notes and alternatives - There isn’t a dedicated MCP tool for
count_flow_runs
yet (the Prefect API has it, but the MCP server doesn’t expose it). If you want, I can open a feature request for a lightweight
count_flow_runs
MCP tool that would solve this directly. -
get_dashboard()
returns some counts but not a 24h breakdown. - If you truly need exact counts without paging, a one‑off script using the Prefect Python client’s
count_flow_runs
per state is an option outside MCP. Refs - MCP server repo: prefect-mcp-server - MCP how‑to: Use the Prefect MCP server If you share whether you’re on Cloud or OSS and any tag filters you care about, I can tailor the exact
read_events
calls (timestamps, prefixes, and chunking strategy) for your workspace volume.