UNPKG

@toolprint/hypertool-mcp

Version:

HyperTool MCP proxy server for routing requests between clients and multiple underlying MCP servers

137 lines • 4.04 kB
/** * TypeScript interfaces for request routing */ import { DiscoveredTool } from "../discovery/types.js"; import { CallToolRequest, CallToolResult } from "@modelcontextprotocol/sdk/types.js"; /** * Routing information for a tool call */ export interface ToolRoute { /** Original tool name from request */ originalName: string; /** Resolved tool name (may be namespaced) */ resolvedName: string; /** Server that should handle this tool */ serverName: string; /** Tool metadata from discovery */ tool: DiscoveredTool; /** Whether this is a namespaced tool call */ isNamespaced: boolean; } /** * Request context for routing */ export interface RouteContext { /** Unique request ID for tracking */ requestId: string; /** Timestamp when request was received */ timestamp: Date; /** Tool call request details */ request: CallToolRequest["params"]; /** Resolved routing information */ route?: ToolRoute; /** Client information (if available) */ clientInfo?: { transport: "stdio" | "http"; remoteAddress?: string; }; } /** * Request routing result */ export interface RoutingResult { /** Whether routing was successful */ success: boolean; /** Routing information if successful */ route?: ToolRoute; /** Error information if failed */ error?: { code: string; message: string; details?: any; }; } /** * Request router configuration */ export interface RouterConfig { /** Whether to enable request logging */ enableLogging?: boolean; /** Whether to enable performance metrics */ enableMetrics?: boolean; /** Default namespace separator */ namespaceSeparator?: string; /** Request timeout in milliseconds */ requestTimeout?: number; /** Whether to validate request parameters */ validateParameters?: boolean; /** Whether to allow non-namespaced tool calls */ allowNonNamespaced?: boolean; } /** * Request router statistics */ export interface RouterStats { /** Total number of requests processed */ totalRequests: number; /** Number of successful requests */ successfulRequests: number; /** Number of failed requests */ failedRequests: number; /** Average request duration in milliseconds */ averageRequestTime: number; /** Requests by server */ requestsByServer: Record<string, number>; /** Common routing errors */ errorsByType: Record<string, number>; } /** * Request router interface */ export interface IRequestRouter { /** * Initialize the router with configuration */ initialize(config?: RouterConfig): Promise<void>; /** * Route a tool call request to the appropriate server */ routeToolCall(request: CallToolRequest["params"], context?: Partial<RouteContext>): Promise<CallToolResult>; /** * Resolve tool name to routing information */ resolveToolRoute(toolName: string): Promise<RoutingResult>; /** * Validate request parameters against tool schema */ validateRequest(request: CallToolRequest["params"], tool: DiscoveredTool): Promise<boolean>; /** * Get router statistics */ getStats(): RouterStats; /** * Clear router statistics */ clearStats(): void; /** * Enable or disable request logging */ setLogging(enabled: boolean): void; } /** * Default router configuration */ export declare const DEFAULT_ROUTER_CONFIG: Required<RouterConfig>; /** * Router error codes */ export declare const ROUTER_ERROR_CODES: { readonly TOOL_NOT_FOUND: "TOOL_NOT_FOUND"; readonly SERVER_NOT_CONNECTED: "SERVER_NOT_CONNECTED"; readonly INVALID_PARAMETERS: "INVALID_PARAMETERS"; readonly REQUEST_TIMEOUT: "REQUEST_TIMEOUT"; readonly ROUTING_ERROR: "ROUTING_ERROR"; readonly VALIDATION_ERROR: "VALIDATION_ERROR"; }; export type RouterErrorCode = (typeof ROUTER_ERROR_CODES)[keyof typeof ROUTER_ERROR_CODES]; //# sourceMappingURL=types.d.ts.map