bc-webclient-mcp
Version:
Model Context Protocol (MCP) server for Microsoft Dynamics 365 Business Central via WebUI protocol. Enables AI assistants to interact with BC through the web client protocol, supporting Card, List, and Document pages with full line item support and server
120 lines • 4.32 kB
TypeScript
/**
* Workflow Integration Helper
*
* Provides utilities for tools to automatically participate in workflow tracking.
* This helper abstracts workflow state updates so tools don't need to know
* WorkflowStateManager internals.
*
* Usage in tools:
* ```typescript
* const integration = new WorkflowIntegration(workflowId);
* integration.recordOperation(toolName, input);
* integration.updateCurrentPage(pageId);
* integration.recordError(errorMessage);
* ```
*/
import type { Result } from '../core/result.js';
import type { BCError } from '../core/errors.js';
import type { WorkflowContext } from './workflow-state-manager.js';
/**
* Helper class for tools to integrate with workflow tracking.
* Handles all workflow state updates so tools don't need to know
* WorkflowStateManager API details.
*/
export declare class WorkflowIntegration {
private readonly workflowId;
private readonly manager;
private workflow;
constructor(workflowId: string);
/**
* Check if workflow exists and is active.
* Tools should check this before attempting workflow operations.
*
* NOTE: Always fetches fresh state from manager to avoid stale cached status.
*/
isActive(): boolean;
/**
* Get current workflow context (read-only).
*/
getWorkflow(): WorkflowContext | null;
/**
* Record a tool operation in the workflow.
* Call this at the END of tool execution with the result.
*
* @param tool - Name of the tool being executed
* @param parameters - Tool input parameters
* @param result - Operation result (success/failure with data/error)
* @returns Result indicating success or failure
*/
recordOperation(tool: string, parameters: Record<string, unknown>, result: {
success: boolean;
data?: unknown;
error?: string;
}): Result<void, BCError>;
/**
* Update current page in workflow.
* Call this when a tool opens or switches to a new page.
*
* @param pageId - BC page ID
* @returns Result indicating success or failure
*/
updateCurrentPage(pageId: string): Result<void, BCError>;
/**
* Update focused record in workflow.
* Call this when a tool navigates to or focuses a specific record.
*
* @param recordKeys - Primary key fields identifying the record
* @returns Result indicating success or failure
*/
updateFocusedRecord(recordKeys: Record<string, unknown>): Result<void, BCError>;
/**
* Track unsaved changes in workflow.
* Call this when a tool modifies fields but hasn't saved yet.
*
* @param changes - Field names and values that have changed
* @returns Result indicating success or failure
*/
trackUnsavedChanges(changes: Record<string, unknown>): Result<void, BCError>;
/**
* Clear unsaved changes in workflow.
* Call this after successfully saving/posting changes.
*
* @returns Result indicating success or failure
*/
clearUnsavedChanges(): Result<void, BCError>;
/**
* Record an error in the workflow.
* Call this when a tool operation fails.
*
* @param errorMessage - Description of the error
* @returns Result indicating success or failure
*/
recordError(errorMessage: string): Result<void, BCError>;
/**
* Update multiple workflow fields atomically.
* Use this when you need to update several fields at once.
*
* @param updates - Object with fields to update
* @returns Result indicating success or failure
*/
updateWorkflowState(updates: {
currentPageId?: string;
focusedRecordKeys?: Record<string, unknown>;
unsavedChanges?: Record<string, unknown>;
appendError?: string;
}): Result<void, BCError>;
}
/**
* Factory function to create WorkflowIntegration if workflowId is provided.
* Returns null if workflowId is not provided (tool running without workflow).
*
* Usage:
* ```typescript
* const integration = createWorkflowIntegration(input.workflowId);
* if (integration) {
* integration.recordOperation(toolName, input);
* }
* ```
*/
export declare function createWorkflowIntegration(workflowId?: string): WorkflowIntegration | null;
//# sourceMappingURL=workflow-integration.d.ts.map