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

120 lines 3.94 kB
/** * Create Record By Field Name MCP Tool * * NEW implementation using BCCrudService with automatic field name resolution. * This tool demonstrates the complete LoadForm → Field Resolution → SaveValue flow. * * Advantages over create_record: * - Uses field names/captions instead of internal identifiers * - Automatic LoadForm and field metadata parsing * - Proper oldValue handling from FormState * - Single-flight request safety with CompletedInteractions barriers * - Multi-index field resolution (Caption, ScopedCaption, SourceExpr, Name) */ 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 { AuditLogger } from '../services/audit-logger.js'; /** * Input schema for create_record_by_field_name */ interface CreateRecordByFieldNameInput { /** Page ID to open */ pageId: string; /** Fields to set: fieldName/caption → value */ fields: Record<string, string>; /** Form ID if already open (optional) */ formId?: string; /** Control path of New button (optional, will use systemAction 10 if not provided) */ newButtonPath?: string; } /** * Output schema */ interface CreateRecordByFieldNameOutput { success: boolean; formId: string; pageId: string; setFields: string[]; failedFields?: Array<{ field: string; error: string; }>; message: string; } /** * MCP Tool: create_record_by_field_name * * Creates a new record using field names/captions for addressing. * Demonstrates the full BCCrudService flow with LoadForm and field resolution. */ export declare class CreateRecordByFieldNameTool extends BaseMCPTool { private readonly connection; private readonly bcConfig?; readonly name = "create_record_by_field_name"; readonly description: string; readonly inputSchema: { type: string; properties: { pageId: { type: string[]; description: string; }; fields: { type: string; description: string; additionalProperties: { type: string; }; }; formId: { type: string; description: string; }; newButtonPath: { type: string; description: string; }; }; required: string[]; }; readonly requiresConsent = true; readonly sensitivityLevel: "medium"; readonly consentPrompt: string; private crudService; constructor(connection: IBCConnection, bcConfig?: { baseUrl: string; username: string; password: string; tenantId: string; } | undefined, auditLogger?: AuditLogger); /** * Initialize BCCrudService lazily */ private initCrudService; /** * Validates input */ protected validateInput(input: unknown): Result<CreateRecordByFieldNameInput, BCError>; /** * Executes the tool */ protected executeInternal(input: unknown): Promise<Result<CreateRecordByFieldNameOutput, BCError>>; /** Ensure page is open and return list form ID */ private ensurePageOpen; /** Handler structure for predicate type safety */ private static isFormToShowHandler; /** Create predicate for FormToShow detection */ private createFormToShowPredicate; /** Click New button and wait for card form */ private createNewRecord; /** Create predicate for new card form detection */ private createCardFormPredicate; /** Set field values and collect results */ private setFieldValues; /** Build success result object */ private buildSuccessResult; } export {}; //# sourceMappingURL=create-record-by-field-name-tool.d.ts.map