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

60 lines 2.34 kB
/** * Tell Me Parser * * Parses Business Central Tell Me search results from handler responses. */ import { ok, err, isOk } from '../core/result.js'; import { ProtocolError } from '../core/errors.js'; import { extractTellMeResults, extractTellMeResultsFromChangeHandler, } from './logical-form-parser.js'; /** * Parser for Tell Me search results */ export class TellMeParser { /** * Parse Tell Me results from handler responses */ parseTellMeResults(handlers) { try { // Cast to handler array for type checking const typedHandlers = handlers; // Try BC27+ format first (DataRefreshChange) const changeHandler = typedHandlers.find((h) => h?.handlerType === 'DN.LogicalClientChangeHandler'); if (changeHandler) { // Create mutable array for extractTellMeResultsFromChangeHandler const handlersArray = [changeHandler]; const resultsResult = extractTellMeResultsFromChangeHandler(handlersArray); if (isOk(resultsResult)) { const results = resultsResult.value; if (results && results.length > 0) { return ok(results.map(this.transformResult)); } } } // Fall back to legacy format const legacyInput = handlers; const resultsResult = extractTellMeResults(legacyInput); if (isOk(resultsResult)) { const results = resultsResult.value; if (results && results.length > 0) { return ok(results.map(this.transformResult)); } } return ok([]); // No results found, but not an error } catch (error) { return err(new ProtocolError(`Failed to parse Tell Me results: ${String(error)}`, { error: String(error) })); } } /** * Transform raw result to TellMePage format */ transformResult(result) { return { id: String(result.objectId || ''), caption: String(result.name || ''), tooltip: result.tooltip || result.context, badges: undefined, // TellMeSearchResultRow doesn't have badges }; } } //# sourceMappingURL=tellme-parser.js.map