get_workflow_result
Retrieve the final result of a background workflow by providing its workflow ID and operation name, continuing to listen for updates until completion.
Instructions
CONTINUE LISTENING TO BACKGROUND WORKFLOW - THIS IS NORMAL OPERATION! Background workflows are OPTIMAL BEHAVIOR for Linked API operations and keep the MCP client responsive. When a workflow runs in the background, this tool should be used with the provided workflowId and operationName parameters to continue listening for updates. The workflow continues processing in the background while you wait. This is the STANDARD way Linked API works - background processing provides optimal user experience!
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workflowId | Yes | The workflow ID provided in the background workflow status message | |
| operationName | Yes | Optional function name for proper type restoration (provided in background workflow status if available) |
Implementation Reference
- src/tools/get-workflow-result.ts:20-38 (handler)The execute() method of GetWorkflowResultTool that runs the tool logic. It looks up the LinkedApi operation by operationName, then calls executeWithProgress with the provided workflowId to poll for the workflow result.
public override async execute({ linkedapi, args: { workflowId, operationName }, workflowTimeout, progressToken, }: { linkedapi: LinkedApi; args: IGetWorkflowResultParams; workflowTimeout: number; progressToken?: string | number; }): Promise<TMappedResponse<unknown>> { const operation = linkedapi.operations.find( (operation) => operation.operationName === operationName, )!; return await executeWithProgress(this.progressCallback, operation, workflowTimeout, { workflowId, progressToken, }); } - Zod schema definition for the tool's IGetWorkflowResultParams interface: workflowId (string) and operationName (enum from OPERATION_NAME values). Also includes the getTool() method returning the Tool inputSchema definition.
public readonly name = 'get_workflow_result'; protected readonly schema = z.object({ workflowId: z.string(), operationName: z.enum(Object.values(OPERATION_NAME)), }); - src/utils/execute-with-progress.ts:5-67 (handler)The executeWithProgress helper function called by GetWorkflowResultTool.execute(). When workflowId is provided (as it is from get_workflow_result), it skips operation.execute() and directly calls operation.result(workflowId) to poll for the workflow's final result, sending progress notifications along the way.
export async function executeWithProgress<TParams, TResult>( progressCallback: (progress: LinkedApiProgressNotification) => void, operation: Operation<TParams, TResult>, workflowTimeout: number, { params, workflowId, progressToken, }: { params?: TParams; workflowId?: string; progressToken?: string | number } = {}, ): Promise<TMappedResponse<TResult>> { let progress = 0; progressCallback({ progressToken, progress, total: 100, message: `Starting workflow ${operation.operationName}...`, }); const interval = setInterval( () => { if (progress < 50) { progress += 5; } else if (progress < 98) { progress += 1; } progressCallback({ progressToken, progress, total: 100, message: `Executing workflow ${operation.operationName}...`, }); }, Math.max(workflowTimeout / 20, 10000), ); try { if (!workflowId) { workflowId = await operation.execute(params as TParams); } const result = await operation.result(workflowId, { timeout: workflowTimeout, }); clearInterval(interval); progressCallback({ progressToken, progress: 100, total: 100, message: `Workflow ${operation.operationName} completed successfully`, }); return result; } catch (error) { clearInterval(interval); if (error instanceof LinkedApiWorkflowTimeoutError) { throw generateTimeoutError(error); } throw error; } } - src/linked-api-tools.ts:76-78 (registration)Registration of GetWorkflowResultTool in the LinkedApiTools constructor. It's instantiated with a progressCallback and added to the tools list at line 76.
new GetWorkflowResultTool(progressCallback), new GetApiUsageTool(progressCallback), ]; - The generateTimeoutError helper function. If the workflow times out, it enriches the error message with instructions to call get_workflow_result with the specific workflowId and operationName parameters.
function generateTimeoutError(error: LinkedApiWorkflowTimeoutError) { const restoreMessage = `Workflow is running in the background. Continue listening for updates. ACTION REQUIRED (MCP CLIENT): - Do not retry the original tool; the workflow is already running - Call the get_workflow_result tool with the parameters below and keep listening until completion PARAMETERS TO USE: - workflowId: ${error.workflowId} - operationName: ${error.operationName} GENERIC MCP CALL EXAMPLE: { "name": "get_workflow_result", "arguments": { "workflowId": "${error.workflowId}", "operationName": "${error.operationName}" } } Background processing keeps the MCP client responsive while the workflow completes.`; error.message = restoreMessage; return error; }