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
142 lines • 4.7 kB
TypeScript
/**
* Intelligent Metadata Parser
*
* Reduces BC response from ~729KB to ~15-20KB by:
* 1. Filtering non-essential fields (system fields, hidden controls)
* 2. Summarizing actions into simple enabled/disabled lists
* 3. Extracting semantic meaning and key information
* 4. Removing redundant metadata
*
* Goal: Give LLMs only the actionable, semantic data they need.
*/
import type { Result } from '../core/result.js';
import type { Handler } from '../types/bc-types.js';
import type { BCError } from '../core/errors.js';
import { PageMetadataParser } from './page-metadata-parser.js';
/**
* Minimal field metadata optimized for LLM understanding.
*/
export interface OptimizedField {
/** Field name (e.g., "No.") */
readonly name: string;
/** User-friendly type (text, number, date, boolean, option) */
readonly type: string;
/** Whether field can be edited */
readonly editable: boolean;
/** Optional: For option/enum fields */
readonly options?: readonly string[];
}
/**
* Simplified action groups.
*/
export interface OptimizedActions {
/** Actions currently enabled */
readonly enabled: readonly string[];
/** Actions currently disabled (useful for context) */
readonly disabled: readonly string[];
}
/**
* Semantic page summary for LLM understanding.
*/
export interface PageSummary {
/** What this page does in plain language */
readonly purpose: string;
/** Key capabilities (create, read, update, delete, post, etc.) */
readonly capabilities: readonly string[];
/** Most important fields users typically interact with */
readonly keyFields: readonly string[];
}
/**
* Optimized page metadata - 90%+ smaller than raw BC response.
*/
export interface OptimizedPageMetadata {
/** Page ID */
readonly pageId: string;
/** Page title */
readonly title: string;
/** Semantic summary of the page */
readonly summary: PageSummary;
/** Essential visible fields only */
readonly fields: readonly OptimizedField[];
/** Simplified action lists */
readonly actions: OptimizedActions;
/** Total field/action counts for reference */
readonly stats: {
readonly totalFields: number;
readonly visibleFields: number;
readonly totalActions: number;
readonly enabledActions: number;
};
}
/**
* Parses BC metadata and optimizes it for LLM consumption.
* Dramatically reduces size while preserving semantic meaning.
*/
export declare class IntelligentMetadataParser {
private readonly baseParser;
constructor(baseParser?: PageMetadataParser);
/**
* Parses and optimizes page metadata.
*/
parse(handlers: readonly Handler[]): Result<OptimizedPageMetadata, BCError>;
/**
* Filters and optimizes fields for LLM consumption.
* Removes ONLY fields the user cannot see or interact with:
* - System fields (SystemId, timestamps, etc.)
* - Hidden/disabled fields (enabled=false)
* - Internal controls (groups, containers, layout)
*
* Keeps ALL fields a user can see in the BC UI.
* Agent must have same capabilities as human user.
*/
private optimizeFields;
/**
* Determines if a field is essential (not system/hidden).
*/
private isEssentialField;
/**
* Converts raw field metadata to optimized format.
*/
private toOptimizedField;
/**
* Converts BC control type to user-friendly type.
*/
private simplifyFieldType;
/**
* Simplifies actions into enabled/disabled lists.
* Much more concise than full action metadata.
* Keeps ALL actions visible to user (no arbitrary limits).
*/
private optimizeActions;
/** LogicalForm structure from FormToShow handler */
private static asLogicalForm;
/**
* Extracts LogicalForm from handlers (finds FormToShow handler).
*/
private extractLogicalFormFromHandlers;
/**
* Generates semantic summary of the page.
* Helps LLMs understand the page's purpose and capabilities.
*/
private generateSummary;
/**
* Infers page type from BC metadata.
*
* Uses ViewMode and FormStyle from LogicalForm (most accurate).
* Falls back to caption/ID heuristics if metadata unavailable.
*
* ViewMode values:
* - 1 = List/Worksheet (multiple records)
* - 2 = Card/Document (single record)
*
* FormStyle values (when ViewMode=2):
* - 1 = Document
* - undefined/absent = Card
*/
private inferPageType;
/**
* Generates a purpose description.
*/
private generatePurpose;
}
//# sourceMappingURL=intelligent-metadata-parser.d.ts.map