import { Server, type Resource, type ServerContext, type Tool, type Transport } from '@modelcontextprotocol/server'; import winston from 'winston'; /** * Plugin interface for extending MCP server functionality */ export interface MCPPlugin { name: string; initialize(server: MCPServer): Promise; shutdown?(): Promise; /** * Optional hook invoked when a new conversation starts. * Servers typically receive a tools listing at the beginning of a session, * so this hook is called from the ListTools handler. */ onNewConversation?(): Promise; } /** * Prompt registry entry */ interface PromptEntry { name: string; description?: string; arguments?: Array<{ name: string; description?: string; required?: boolean; }>; getMessages: (args?: Record) => Promise>; } /** * Core MCP Server implementation for Kubernetes operations */ export interface MCPServerOptions { skipTransportErrorHandling?: boolean; skipGracefulShutdown?: boolean; toolListCacheHint?: { ttlMs: number; cacheScope: 'public' | 'private'; }; } export declare class MCPServer { private static readonly MAX_MALFORMED_STDIN_LOGS; private server; private transport?; private logger; private hasLoggedStartupBegin; private hasLoggedStartupSuccess; private tools; private resources; private resourceTemplates; private plugins; private prompts; private isShuttingDown; private stdinChunkBuffer; private malformedStdinCount; private readonly stdinDecoder; private readonly logMalformedPayloadPreview; private options; private eventListeners; constructor(options?: MCPServerOptions); /** * Add an event listener and track it for cleanup */ private addTrackedListener; /** * Remove all tracked event listeners */ private removeAllListeners; private isStdioTransport; /** * Set up stdio-specific error handling for the transport. */ private setupStdioTransportErrorHandling; /** * Attempt to gracefully restart the stdio server connection */ private gracefulRestart; /** * Set up request handlers for MCP protocol */ private setupHandlers; /** * Register a tool with the MCP server */ registerTool(tool: Tool, handler: (params: any, context?: ServerContext) => Promise): void; /** * Get all registered tools */ getTools(): Tool[]; /** * Execute a tool directly (for internal use, e.g., from run_code sandbox) */ executeTool(toolName: string, params: unknown): Promise; /** * Register a resource with the MCP server */ registerResource(resource: Resource): void; /** * Register a prompt with the MCP server */ registerPrompt(prompt: PromptEntry): void; /** * Load and initialize a plugin */ loadPlugin(plugin: MCPPlugin): Promise; /** * Get a loaded plugin by name */ getPlugin(name: string): MCPPlugin | undefined; /** * Start the MCP server */ start(): Promise; /** * Start the MCP server with an explicit transport. */ startWithTransport(transport: Transport): Promise; /** * Connect to stdio with improved error handling */ private connectStdioWithErrorHandling; /** * Inspect newline-delimited JSON-RPC messages and emit user-friendly diagnostics. */ private inspectIncomingTransportData; private inspectTransportLine; /** * Stop the MCP server */ stop(): Promise; /** * Release application resources after a per-request transport has already closed. */ cleanupAfterTransportClose(): Promise; private shutdown; /** * Set up graceful shutdown handling */ private setupGracefulShutdown; /** * Get the logger instance */ getLogger(): winston.Logger; /** * Get the underlying MCP server instance */ getServer(): Server; /** * Clean up resources and event listeners (useful for tests) */ cleanup(): void; /** * Emit the standard startup-begin log once, even if startup is split across phases. */ logStartupBegin(): void; /** * Emit the standard startup-success log once, even if startup is split across phases. */ logStartupSuccess(): void; /** Build a stderr-only logger with optional file output. */ private createLogger; private normalizeToolDefinition; private asStructuredContent; private withStructuredContent; private withJsonTextFallback; private isExecutionErrorPayload; private validateToolOutput; private executionErrorResult; } export {}; //# sourceMappingURL=MCPServer.d.ts.map