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
133 lines • 4.94 kB
TypeScript
/**
* Read Page Data MCP Tool
*
* Reads data records from a BC page (both card and list types).
* Extracts field values using PageDataExtractor.
*/
import { BaseMCPTool } from './base-tool.js';
import type { Result } from '../core/result.js';
import type { BCError } from '../core/errors.js';
import type { IBCConnection } from '../core/interfaces.js';
import type { ReadPageDataOutput } from '../types/mcp-types.js';
import { PageDataExtractor } from '../parsers/page-data-extractor.js';
import { HandlerParser } from '../parsers/handler-parser.js';
/**
* MCP Tool: read_page_data
*
* Reads data records from a BC page with optional filtering.
*/
export declare class ReadPageDataTool extends BaseMCPTool {
private readonly connection;
private readonly bcConfig?;
private readonly dataExtractor;
private readonly handlerParser;
readonly name = "read_page_data";
readonly description: string;
readonly inputSchema: {
type: string;
properties: {
pageContextId: {
type: string;
description: string;
};
filters: {
type: string;
description: string;
additionalProperties: boolean;
};
setCurrent: {
type: string;
description: string;
default: boolean;
};
limit: {
type: string;
description: string;
};
offset: {
type: string;
description: string;
};
workflowId: {
type: string;
description: string;
};
};
required: string[];
};
readonly requiresConsent = false;
readonly sensitivityLevel: "low";
constructor(connection: IBCConnection, bcConfig?: {
baseUrl: string;
username: string;
password: string;
tenantId: string;
} | undefined, dataExtractor?: PageDataExtractor, handlerParser?: HandlerParser);
/**
* Finds the repeater control path in a LogicalForm.
* Returns the control path for the main list repeater.
*/
private findRepeaterControlPath;
/**
* Extracts field metadata from a LogicalForm.
* Returns a map of field name to FieldMetadata for all filterable fields.
*
* Walks the LogicalForm tree and extracts metadata from RepeaterColumnControls
* and other field controls. This metadata is used for filter pre-validation.
*/
/**
* Finds the FilterLogicalControl in the LogicalForm metadata.
* In BC27, this control has type 'filc' and is typically at server:c[2].
*
* @param logicalForm The root LogicalForm object
* @returns Path to FilterLogicalControl (e.g., "server:c[2]") or null if not found
*/
private findFilterLogicalControl;
private extractFieldMetadata;
/**
* Builds filterColumnId in BC's format: "{tableId}_{tableName}.{fieldId}"
*
* Examples:
* - "18_Customer.1" (Customer No.)
* - "36_Sales Header.3" (Sales Order No.)
* - "36_Sales Header.79.79" (Sales Order Sell-to Customer No.)
*
* Format rules:
* - If fieldId === dataColumnNo: single segment ".{fieldId}"
* - If fieldId !== dataColumnNo: double segment ".{dataColumnNo}.{fieldId}"
*/
private buildFilterColumnId;
/**
* Applies filters to a list page before reading data.
* Uses BC's Filter + SaveValue protocol.
*
* OPTIMIZATION: Caches filter state to skip redundant Filter/SaveValue calls.
* This is the highest-value optimization (validated by GPT-5.1 analysis).
*
* Filter format:
* - Simple: { "No.": "10000" } → equality filter
* - Advanced: { "No.": { operator: "=", value: "10000" } }
*
* Supported operators: =, !=, contains, startsWith, >=, <=, between
*/
private applyFilters;
/**
* Applies setCurrent functionality by navigating BC to a specific record using bookmark-based SetSelection.
* Enforces "single match" requirement and calls SetCurrentRowAndRowsSelection interaction.
*
* @param connection BC WebSocket connection
* @param records Array of flat records with bookmark field
* @param filters Filter criteria to identify the target record
* @param repeaterPath Control path to the repeater (from findRepeaterControlPath)
* @param formId Form ID containing the list
* @param logger Logger instance
* @returns Result with bookmark on success, or error if validation fails
*/
private applySetCurrent;
/**
* Executes the tool to read page data.
* Input is pre-validated by BaseMCPTool using Zod schema.
*/
protected executeInternal(input: unknown): Promise<Result<ReadPageDataOutput, BCError>>;
}
//# sourceMappingURL=read-page-data-tool.d.ts.map