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
158 lines • 5.1 kB
TypeScript
/**
* Session State Manager
*
* Tracks BC sessions and open pages for session introspection.
* This is a singleton service that maintains in-memory state.
*
* NOTE: This is ephemeral (in-memory) and will reset when the process restarts.
* For production use, you could back this with PageContextCache or a database.
*/
import type { ILogger } from '../core/interfaces.js';
/**
* Information about an open page in a session.
*/
export interface OpenPageInfo {
readonly pageContextId: string;
readonly pageId: string;
readonly pageType?: string;
readonly openedAt: string;
}
/**
* Information about an active dialog in a session.
*/
export interface DialogInfo {
readonly dialogId: string;
readonly caption: string;
readonly designName?: string;
readonly isTaskDialog: boolean;
readonly isModal: boolean;
readonly originatingFormId?: string;
readonly originatingControlPath?: string;
readonly openedAt: string;
}
/**
* Information about a BC session.
*/
export interface SessionInfo {
readonly sessionId: string;
readonly openPages: OpenPageInfo[];
readonly activeDialogs: DialogInfo[];
}
/**
* Snapshot of all sessions and their state.
*/
export interface SessionStateSnapshot {
readonly sessions: SessionInfo[];
}
/**
* SessionStateManager tracks BC sessions and open pages.
*
* This is a singleton to maintain consistent state across the application.
*/
export declare class SessionStateManager {
private readonly logger?;
private static instance;
/**
* Gets the singleton instance.
* @param logger - Optional logger for debug logging
*/
static getInstance(logger?: ILogger): SessionStateManager;
/**
* Resets the singleton instance (primarily for testing).
*/
static resetInstance(): void;
private readonly sessions;
private constructor();
/**
* Creates a new session.
* @returns The newly created session info
*/
createSession(): SessionInfo;
/**
* Creates a session with a specific ID (for existing sessions).
* @param sessionId - The session ID to use
* @returns The session info
*/
createSessionWithId(sessionId: string): SessionInfo;
/**
* Gets a session by ID.
* @param sessionId - The session ID
* @returns The session info or undefined
*/
getSession(sessionId: string): SessionInfo | undefined;
/**
* Adds an open page to a session.
* If the session doesn't exist, it will be created.
* @param sessionId - The session ID
* @param pageContextId - The page context ID
* @param pageId - The BC page ID
* @param pageType - Optional page type (Card, List, Document, etc.)
*/
addOpenPage(sessionId: string, pageContextId: string, pageId: string, pageType?: string): void;
/**
* Closes a page in all sessions.
* @param pageContextId - The page context ID to close
*/
closePage(pageContextId: string): void;
/**
* Closes a session and all its pages.
* @param sessionId - The session ID to close
*/
closeSession(sessionId: string): void;
/**
* Gets a snapshot of all sessions and their state.
* @returns Immutable snapshot of current state
*/
getSnapshot(): SessionStateSnapshot;
/**
* Adds an active dialog to a session.
* If the session doesn't exist, it will be created.
* Dialogs are stacked (last added is topmost).
* @param sessionId - The session ID
* @param dialogInfo - Dialog information
*/
addDialog(sessionId: string, dialogInfo: Omit<DialogInfo, 'openedAt'>): void;
/**
* Closes a dialog in a session.
* If dialogId is not provided, closes the topmost dialog.
* @param sessionId - The session ID
* @param dialogId - Optional dialog ID to close (defaults to topmost)
*/
closeDialog(sessionId: string, dialogId?: string): void;
/**
* Gets the topmost (currently active) dialog for a session.
* @param sessionId - The session ID
* @returns The topmost dialog or undefined if no dialogs
*/
getActiveDialog(sessionId: string): DialogInfo | undefined;
/**
* Gets all active dialogs for a session (in stack order).
* @param sessionId - The session ID
* @returns Array of dialogs (last = topmost)
*/
getDialogs(sessionId: string): DialogInfo[];
/**
* Checks if a session has any active dialogs.
* @param sessionId - The session ID
* @returns True if session has active dialogs
*/
hasDialogs(sessionId: string): boolean;
/**
* Gets all open pages across all sessions.
* @returns Array of all open pages
*/
getAllOpenPages(): OpenPageInfo[];
/**
* Gets the number of active sessions.
*/
getSessionCount(): number;
/**
* Gets the total number of open pages across all sessions.
*/
getTotalOpenPages(): number;
/**
* Clears all sessions (primarily for testing).
*/
clear(): void;
}
//# sourceMappingURL=session-state-manager.d.ts.map