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

244 lines 6.48 kB
/** * MCP Server Implementation * * Implements the Model Context Protocol server for Business Central integration. * Handles JSON-RPC 2.0 communication over stdio with Claude Desktop. * * Features: * - Tool registration and execution * - Resource registration and serving * - Initialize/shutdown lifecycle * - Error handling and logging * - Protocol compliance */ import type { Result } from '../core/result.js'; import type { BCError } from '../core/errors.js'; import type { IMCPServer, IMCPTool, IMCPResource, ILogger } from '../core/interfaces.js'; /** * JSON-RPC 2.0 request from client. */ export interface JSONRPCRequest { readonly jsonrpc: '2.0'; readonly id?: string | number; readonly method: string; readonly params?: unknown; } /** * JSON-RPC 2.0 response to client. */ export interface JSONRPCResponse { readonly jsonrpc: '2.0'; readonly id?: string | number; readonly result?: unknown; readonly error?: JSONRPCError; } /** * JSON-RPC 2.0 error. */ export interface JSONRPCError { readonly code: number; readonly message: string; readonly data?: unknown; } /** * MCP initialize request parameters. */ export interface InitializeParams { readonly protocolVersion: string; readonly capabilities: { readonly tools?: Record<string, unknown>; readonly resources?: Record<string, unknown>; readonly prompts?: Record<string, unknown>; }; readonly clientInfo: { readonly name: string; readonly version: string; }; } /** * MCP initialize result. */ export interface InitializeResult { readonly protocolVersion: string; readonly capabilities: { readonly tools?: Record<string, unknown>; readonly resources?: Record<string, unknown>; readonly prompts?: Record<string, unknown>; }; readonly serverInfo: { readonly name: string; readonly version: string; }; } /** * MCP tool call parameters. */ export interface ToolCallParams { readonly name: string; readonly arguments?: unknown; } /** * Tool list item for MCP protocol. */ export interface ToolListItem { readonly name: string; readonly description: string; readonly inputSchema: unknown; readonly annotations?: { readonly requiresConsent?: boolean; readonly consentPrompt?: string; readonly sensitivityLevel?: 'low' | 'medium' | 'high'; }; } /** * Resource list item for MCP protocol. */ export interface ResourceListItem { readonly uri: string; readonly name: string; readonly description: string; readonly mimeType: string; } /** * Prompt argument for MCP protocol. */ export interface PromptArgument { readonly name: string; readonly description: string; readonly required?: boolean; readonly default?: string; } /** * Prompt list item for MCP protocol. */ export interface PromptListItem { readonly name: string; readonly description: string; readonly arguments: readonly PromptArgument[]; } /** * Parameters for prompts/get request. */ export interface GetPromptParams { readonly name: string; readonly arguments?: Record<string, string>; } /** * Result for prompts/get request. */ export interface GetPromptResult { /** * Human-readable prompt text (markdown). */ readonly prompt: string; readonly name: string; readonly description: string; readonly arguments: readonly PromptArgument[]; } /** * MCP Server for Business Central. * * Implements the Model Context Protocol server specification. * Communicates with Claude Desktop via JSON-RPC 2.0 over stdio. */ export declare class MCPServer implements IMCPServer { private readonly logger?; private readonly tools; private readonly resources; private initialized; private running; private clientInfo; constructor(logger?: ILogger | undefined); /** * Initializes the server. * Must be called before start(). */ initialize(): Promise<Result<void, BCError>>; /** * Registers a tool with the server. * Tools can be registered before or after initialization. */ registerTool(tool: IMCPTool): void; /** * Registers a resource with the server. * Resources can be registered before or after initialization. */ registerResource(resource: IMCPResource): void; /** * Starts the server. * Begins listening for JSON-RPC requests on stdin. */ start(): Promise<Result<void, BCError>>; /** * Stops the server gracefully. * Closes all connections and cleans up resources. */ stop(): Promise<Result<void, BCError>>; /** * Gets all registered tools. */ getTools(): readonly IMCPTool[]; /** * Gets all registered resources. */ getResources(): readonly IMCPResource[]; /** * Handles MCP initialize request. */ handleInitialize(params: InitializeParams): Promise<Result<InitializeResult, BCError>>; /** * Handles tools/list request. * Includes consent metadata via annotations for MCP 2025 compliance. */ handleToolsList(): Promise<Result<{ tools: readonly ToolListItem[]; }, BCError>>; /** * Handles tools/call request. */ handleToolCall(params: ToolCallParams): Promise<Result<unknown, BCError>>; /** * Handles resources/list request. */ handleResourcesList(): Promise<Result<{ resources: readonly ResourceListItem[]; }, BCError>>; /** * Handles resources/read request. */ handleResourceRead(params: { uri: string; }): Promise<Result<{ contents: Array<{ uri: string; mimeType: string; text: string; }>; }, BCError>>; /** * Handles prompts/list request. */ handlePromptsList(): Promise<Result<{ prompts: readonly PromptListItem[]; }, BCError>>; /** * Handles prompts/get request. */ handlePromptGet(params: GetPromptParams): Promise<Result<GetPromptResult, BCError>>; /** * Checks if server is initialized. */ isInitialized(): boolean; /** * Checks if server is running. */ isRunning(): boolean; /** * Gets client information (available after initialize). */ getClientInfo(): { name: string; version: string; } | undefined; } //# sourceMappingURL=mcp-server.d.ts.map