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
127 lines • 3.32 kB
TypeScript
/**
* Stdio Transport for MCP Protocol
*
* Implements JSON-RPC 2.0 communication over stdio.
* Handles reading requests from stdin and writing responses to stdout.
*
* Features:
* - Line-by-line JSON-RPC message parsing
* - Request routing to MCP server
* - Response serialization
* - Error handling
* - Graceful shutdown
*/
import type { Result } from '../core/result.js';
import type { BCError } from '../core/errors.js';
import type { ILogger } from '../core/interfaces.js';
import type { MCPServer } from './mcp-server.js';
/**
* Options for stdio transport.
*/
export interface StdioTransportOptions {
readonly logger?: ILogger;
readonly enableDebugLogging?: boolean;
}
/**
* Stdio transport for MCP protocol.
*
* Reads JSON-RPC requests from stdin, routes them to the server,
* and writes responses to stdout.
*/
export declare class StdioTransport {
private readonly server;
private readonly options;
private readonly reader;
private running;
private stdoutClosed;
private stdioLogStream?;
private messageCounter;
constructor(server: MCPServer, options?: StdioTransportOptions);
/**
* Initializes STDIO logging to file if MCP_STDIO_LOG_FILE environment variable is set.
* @private
*/
private initializeStdioLogging;
/**
* Logs a message to the STDIO log file.
* @private
*/
private logStdioMessage;
/**
* Starts the transport.
* Begins listening for JSON-RPC requests on stdin.
*/
start(): Promise<Result<void, BCError>>;
/**
* Stops the transport gracefully.
*/
stop(): Promise<Result<void, BCError>>;
/**
* Handles a line from stdin.
*/
private handleLine;
/** Known notification methods that don't require a response */
private static readonly NOTIFICATION_METHODS;
/** Method to handler lookup table */
private readonly methodHandlers;
/**
* Routes a request to the appropriate handler.
*/
private routeRequest;
/** Handle unknown method - notification vs request */
private handleUnknownMethod;
/**
* Handles initialize request.
*/
private handleInitialize;
/**
* Handles tools/list request.
*/
private handleToolsList;
/**
* Handles tools/call request.
*/
private handleToolCall;
/**
* Handles resources/list request.
*/
private handleResourcesList;
/**
* Handles resources/read request.
*/
private handleResourceRead;
/**
* Handles prompts/list request.
*/
private handlePromptsList;
/**
* Handles prompts/get request.
*/
private handlePromptGet;
/**
* Handles ping request (keepalive).
*/
private handlePing;
/**
* Sends a success response.
*/
private sendSuccess;
/**
* Sends an error response from BCError.
* Uses centralized error mapping to convert BCError to appropriate JSON-RPC error codes.
*/
private sendErrorFromBCError;
/**
* Sends an error response.
*/
private sendError;
/**
* Sends a JSON-RPC response to stdout.
*/
private sendResponse;
/**
* Checks if transport is running.
*/
isRunning(): boolean;
}
//# sourceMappingURL=stdio-transport.d.ts.map