UNPKG

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

105 lines 3.9 kB
/** * BC Page Connection - Connection Per Page Architecture * * Creates a NEW WebSocket connection for each page request, matching the real BC client behavior. * This prevents BC's connection-level form caching from affecting different pages. * * Solution for: BC caches forms at the WebSocket connection level, causing all pages * to return the same cached form data when using a single connection. */ import type { Result } from '../core/result.js'; import type { BCError } from '../core/errors.js'; import type { IBCConnection } from '../core/interfaces.js'; import type { BCSession, BCInteraction, Handler } from '../types/bc-types.js'; import { BCRawWebSocketClient } from './clients/BCRawWebSocketClient.js'; import type { ChildFormInfo } from '../util/loadform-helpers.js'; /** * Configuration for BC page connection. */ export interface BCPageConnectionConfig { readonly baseUrl: string; readonly username: string; readonly password: string; readonly tenantId?: string; readonly timeout?: number; } /** * BC Connection that creates a NEW connection for each page request. * This matches the real BC web client behavior to prevent form caching. */ export declare class BCPageConnection implements IBCConnection { private readonly config; private currentClient; private currentSession; private currentPageId; private openForms; private lastAckSequence; constructor(config: BCPageConnectionConfig); /** * Creates a fresh connection for page requests. * For non-page requests, reuses existing connection. */ connect(): Promise<Result<BCSession, BCError>>; /** * Creates a new WebSocket connection and authenticates. * Sets up global dialog listening to automatically track DialogToShow events. */ private createNewConnection; /** * Global handler for DialogToShow events. * Automatically tracks dialogs in SessionStateManager when they appear. */ private handleDialogEvents; /** * Extracts dialog information and tracks it in SessionStateManager. */ private trackDialog; /** * Sends an interaction and waits for response. * Creates fresh connection for each main page OpenForm (Connection Per Page architecture). * Reuses connection for other interactions within the same page context. */ invoke(interaction: BCInteraction): Promise<Result<readonly Handler[], BCError>>; /** * Extracts form ID from OpenForm response. * BC returns form ID in DN.LogicalClientEventRaisingHandler with FormToShow event. */ private extractFormId; /** * Updates ack sequence number from handler responses. * Scans handlers recursively for sequence numbers. */ private updateAckSequenceFromHandlers; /** * Load child forms using the LoadForm interaction. */ loadChildForms(childForms: ChildFormInfo[]): Promise<Result<readonly Handler[], BCError>>; /** * Waits for handlers that match a predicate. * Delegates to the underlying WebSocket client. */ waitForHandlers<T>(predicate: (handlers: Handler[]) => { matched: boolean; data?: T; }, options?: { timeoutMs?: number; signal?: AbortSignal; }): Promise<T>; /** * Gets the underlying raw WebSocket client */ getRawClient(): BCRawWebSocketClient | null; isPageOpen(pageId: string): boolean; getOpenFormId(pageId: string): string | undefined; trackOpenForm(pageId: string, formId: string): void; getAllOpenFormIds(): string[]; getCompanyName(): string | null; getTenantId(): string; isConnected(): boolean; getSession(): BCSession | undefined; /** * Closes the connection gracefully. */ close(): Promise<Result<void, BCError>>; } //# sourceMappingURL=bc-page-connection-with-dialog-listener.d.ts.map