UNPKG

mcp-web-ui

Version:

Ultra-lightweight vanilla JavaScript framework for MCP servers - Zero dependencies, perfect security, 2-3KB bundle size

139 lines 3.77 kB
/** * GenericUIServer - Slim, Configuration-Driven UI Server * * This replaces the monolithic UIServer with a modular, extensible architecture: * - Configuration over hardcoding * - Composition over inheritance * - Separation of concerns * - Progressive enhancement * - Plugin-based extensibility * * Key improvements: * - Schema-driven resource loading (CSS/JS loaded based on content) * - Pluggable template system (custom renderers for different apps) * - Dynamic route generation (no hardcoded routes per app) * - Modular middleware system (security, compression, etc.) * - Plugin architecture (extend without modifying core) */ import express from 'express'; import { UIServerConfig } from './UIServerConfig.js'; import { SessionManager } from '../session/SessionManager.js'; import { WebUISession, UISchema, DataSourceFunction, UpdateHandler } from '../types/index.js'; /** * Generic UI Server Interface */ export interface UIServerPlugin { name: string; initialize(server: GenericUIServer): Promise<void>; cleanup?(): Promise<void>; } /** * GenericUIServer - The new modular, configurable UI server */ export declare class GenericUIServer { private session; private schema; private dataSource; private onUpdate; private sessionManager; private config; private pollInterval; private bindAddress; private app; private server; private dataPollingInterval; private resourceManager; private templateEngine; private plugins; private projectRoot; constructor(session: WebUISession, schema: UISchema, dataSource: DataSourceFunction, onUpdate: UpdateHandler, sessionManager: SessionManager, config?: UIServerConfig, pollInterval?: number, bindAddress?: string); /** * Start the server */ start(): Promise<void>; /** * Stop the server and cleanup */ stop(): Promise<void>; /** * Register a plugin */ registerPlugin(plugin: UIServerPlugin): Promise<void>; /** * Add custom route (for plugins) */ addRoute(path: string, handler: express.RequestHandler): void; /** * Add custom middleware (for plugins) */ addMiddleware(middleware: express.RequestHandler): void; /** * Setup Express middleware with configuration-driven approach */ private setupMiddleware; /** * Setup API routes with dynamic resource handling */ private setupRoutes; /** * Setup dynamic resource routes using ResourceManager */ private setupDynamicResourceRoutes; /** * Setup API routes */ private setupAPIRoutes; /** * Build template data for rendering */ private buildTemplateData; /** * Get active themes for this schema */ private getActiveThemes; /** * Initialize plugins from configuration */ private initializePlugins; /** * Serve static file with proper headers */ private serveStaticFile; /** * Start data polling if enabled */ private startDataPolling; /** * Find project root directory */ private findProjectRoot; /** * Sanitize update data */ private sanitizeUpdateData; /** * Sanitize LLM-generated content */ private sanitizeLLMContent; /** * Timing-safe string comparison */ private timingSafeEquals; /** * Generate cryptographic nonce */ private generateNonce; /** * Escape HTML content */ private escapeHtml; /** * Check if schema matches theme conditions */ private matchesSchemaConditions; /** * Enhanced logging with component context */ private log; } //# sourceMappingURL=GenericUIServer.d.ts.map