cancel_flow_run
Stop an active workflow execution in Prefect by providing the flow run ID to halt processing and free resources.
Instructions
Cancel a flow run.
Args:
flow_run_id: ID of the flow run to cancel.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"flow_run_id": "<flow_run_id>"
},
"name": "cancel_flow_run"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| flow_run_id | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- prefect_mcp_server_pkg/server.py:223-239 (handler)The handler function for the 'cancel_flow_run' MCP tool. It is decorated with @mcp.tool() for automatic registration. The function validates the flow_run_id input, uses the Prefect client to cancel the flow run by UUID, and returns success or error details.
@mcp.tool() async def cancel_flow_run(ctx: Context, flow_run_id: str) -> Dict[str, Any]: """Cancel a flow run. Args: flow_run_id: ID of the flow run to cancel. """ if not flow_run_id: return {"error": "Missing required argument: flow_run_id"} async with get_client() as client: try: result = await client.cancel_flow_run(UUID(flow_run_id)) return {"success": True, "result": str(result)} except Exception as e: return {"error": f"Failed to cancel flow run: {str(e)}"}