Skip to main content
Glama
michsob

PowerPlatform MCP

Cancel Flow Run

cancel-flow-run

Cancel running or waiting Power Automate flow runs. Stop workflow execution using flow ID and run ID to terminate processes before completion.

Instructions

Cancel a running or waiting flow run. Cannot cancel flows already in a terminal state (Succeeded, Failed, Cancelled).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
flowIdYesThe workflow ID (GUID)
runIdYesThe flow run ID
environmentNoEnvironment name (e.g. DEV, UAT). Uses default if omitted.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
successYes
flowIdYes
runIdYes
previousStatusYes

Implementation Reference

  • Main implementation of cancelFlowRun that checks if flow is in terminal state, calls the Flow API to cancel, and returns the result with previous status
    /**
     * Cancel a running or waiting flow run
     */
    async cancelFlowRun(flowId: string, runId: string): Promise<CancelFlowRunResult> {
      try {
        const environmentId = await this.getEnvironmentId();
        const token = await this.client.getManagementToken();
    
        const runDetails = await this.getFlowRunDetails(flowId, runId) as Record<string, unknown>;
        const status = (runDetails.status as string) || '';
    
        const terminalStates = ['Succeeded', 'Failed', 'Cancelled'];
        if (terminalStates.includes(status)) {
          throw new Error(`Cannot cancel flow run - already in terminal state: ${status}`);
        }
    
        const url = `https://api.flow.microsoft.com/providers/Microsoft.ProcessSimple/environments/${environmentId}/flows/${flowId}/runs/${runId}/cancel?api-version=2016-11-01`;
    
        await axios.post(url, {}, {
          headers: {
            Authorization: `Bearer ${token}`,
            Accept: 'application/json',
          },
        });
    
        return {
          success: true,
          flowId,
          runId,
          previousStatus: status,
        };
      } catch (error: unknown) {
        const err = error as {
          response?: {
            status?: number;
            statusText?: string;
            data?: { error?: unknown };
          };
          message?: string;
        };
        const errorDetails = err.response?.data?.error || err.response?.data || err.message;
        throw new Error(
          `Failed to cancel flow run: ${err.message} - ${JSON.stringify(errorDetails)}`
        );
      }
    }
  • Registration of the 'cancel-flow-run' tool with the MCP server, including input/output schema and handler function that calls the flow service
    // Cancel Flow Run
    server.registerTool(
      "cancel-flow-run",
      {
        title: "Cancel Flow Run",
        description: "Cancel a running or waiting flow run. Cannot cancel flows already in a terminal state (Succeeded, Failed, Cancelled).",
        inputSchema: {
          flowId: z.string().describe("The workflow ID (GUID)"),
          runId: z.string().describe("The flow run ID"),
          environment: z.string().optional().describe("Environment name (e.g. DEV, UAT). Uses default if omitted."),
        },
        outputSchema: z.object({
          success: z.boolean(),
          flowId: z.string(),
          runId: z.string(),
          previousStatus: z.string(),
        }),
      },
      async ({ flowId, runId, environment }) => {
        try {
          const ctx = registry.getContext(environment);
          const service = ctx.getFlowService();
          const result = await service.cancelFlowRun(flowId, runId);
    
          return {
            structuredContent: result,
            content: [
              {
                type: "text",
                text: `Flow run cancelled successfully.\nFlow: ${flowId}\nRun: ${runId}\nPrevious status: ${result.previousStatus}`,
              },
            ],
          };
        } catch (error: any) {
          console.error("Error cancelling flow run:", error);
          return {
            content: [
              {
                type: "text",
                text: `Failed to cancel flow run: ${error.message}`,
              },
            ],
          };
        }
      }
    );
  • TypeScript interface defining the shape of the CancelFlowRunResult returned by the cancelFlowRun method
    export interface CancelFlowRunResult {
      [key: string]: unknown;
      success: boolean;
      flowId: string;
      runId: string;
      previousStatus: string;
    }
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses the important state constraint (terminal states cannot be cancelled), but omits other behavioral traits like idempotency, permission requirements, side effects, or what state the run transitions to upon cancellation.

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

Conciseness5/5

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

Two sentences with zero waste: first establishes the action and valid targets, second establishes the exclusion constraint. Information is front-loaded and every word earns its place.

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

Completeness4/5

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

Given the output schema exists, the description appropriately focuses on the invocation constraint (terminal states). It covers the essential business logic needed to use the tool correctly, though with no annotations, a brief note on the resulting state transition would strengthen completeness.

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

Parameters3/5

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

The input schema has 100% description coverage (flowId, runId, environment all documented). Per rubric guidelines, this establishes a baseline of 3. The description text adds no additional parameter semantics beyond what the schema already provides.

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

Purpose5/5

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

The description clearly states the specific action (Cancel), target resource (flow run), and valid states (running or waiting). It effectively distinguishes this tool from the numerous sibling 'get' tools and from 'resubmit-flow-run' through the specific verb and state constraints.

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

Usage Guidelines4/5

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

Provides explicit negative constraints ('Cannot cancel flows already in a terminal state'), which helps the agent avoid incorrect invocations. However, it lacks explicit positive guidance on when to prefer this over 'resubmit-flow-run' or prerequisites for use.

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/michsob/powerplatform-mcp'

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