Skip to main content
Glama

set_task_run_state

Update the execution status of a Prefect workflow task run by setting it to states like SCHEDULED, RUNNING, COMPLETED, or FAILED to manage task lifecycle and track progress.

Instructions

Set a task run's state.

Args: task_run_id: The task run UUID state: The new state to set (e.g., "SCHEDULED", "RUNNING", "COMPLETED", "FAILED") message: An optional message explaining the state change

Returns: Result of the state change operation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
messageNo
stateYes
task_run_idYes

Implementation Reference

  • The main handler function for the 'set_task_run_state' tool, decorated with @mcp.tool for registration. It maps string state names to Prefect state objects and calls the Prefect client's set_task_run_state method to update the task run state.
    @mcp.tool
    async def set_task_run_state(
        task_run_id: str,
        state: str,
        message: Optional[str] = None,
        force: bool = False,
    ) -> List[Union[types.TextContent, types.ImageContent, types.EmbeddedResource]]:
        """
        Set a task run's state.
        
        Args:
            task_run_id: The task run UUID
            state: The new state to set (e.g., "SCHEDULED", "RUNNING", "COMPLETED", "FAILED")
            message: An optional message explaining the state change
            force: If True, disregard orchestration logic when setting the state
            
        Returns:
            Result of the state change operation
        """
        async with get_client() as client:
            state_obj = None
            if state.upper() == "SCHEDULED":
                state_obj = Scheduled(message=message)
            elif state.upper() == "RUNNING":
                state_obj = Running(message=message)
            elif state.upper() == "COMPLETED":
                state_obj = Completed(message=message)
            elif state.upper() == "FAILED":
                state_obj = Failed(message=message)
            elif state.upper() == "PENDING":
                state_obj = Pending(message=message)
            elif state.upper() == "CANCELLED":
                state_obj = Cancelled(message=message)
            else:
                return [types.TextContent(
                    type="text", 
                    text=f"Invalid state '{state}'. Must be one of: SCHEDULED, RUNNING, COMPLETED, FAILED, PENDING, CANCELLED"
                )]
            
            result = await client.set_task_run_state(
                task_run_id=UUID(task_run_id),
                state=state_obj,
                force=force
            )
            
            return [types.TextContent(type="text", text=str(result.model_dump()))]
  • The @mcp.tool decorator registers the set_task_run_state function as an MCP tool.
    @mcp.tool
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states this is a state-setting operation (implying mutation) but doesn't mention permission requirements, whether the operation is idempotent, rate limits, or what happens on invalid state transitions. The 'Returns' line is vague ('Result of the state change operation') and provides no insight into success/failure responses.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (Args, Returns) and front-loaded the core purpose. Every sentence adds value: the first states what the tool does, and the parameter explanations are necessary given 0% schema coverage. It could be slightly more concise by integrating the parameter explanations into a single paragraph.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with 3 parameters, 0% schema coverage, no annotations, and no output schema, the description is incomplete. It doesn't address critical behavioral aspects like error conditions, side effects, or response format. While it explains parameters adequately, it lacks context about how this tool fits into the broader workflow system (e.g., relationship to flow runs).

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It provides clear semantics for all three parameters: task_run_id is explained as 'The task run UUID', state includes helpful examples ('SCHEDULED', 'RUNNING', etc.), and message is described as 'optional' with purpose. This adds significant value beyond the bare schema, though it doesn't specify format constraints or validation rules.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Set') and the resource ('a task run's state'), making the purpose immediately understandable. It distinguishes this tool from siblings like 'set_flow_run_state' by specifying it operates on task runs rather than flow runs. However, it doesn't explicitly contrast with other state-setting tools in the sibling list.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a valid task_run_id), constraints (e.g., valid state transitions), or relationships with sibling tools like 'set_flow_run_state' or 'restart_flow_run'. The agent must infer usage from context alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/allen-munsch/mcp-prefect'

If you have feedback or need assistance with the MCP directory API, please join our Discord server