import type { Tool, ToolSummary } from '../../shared/models/tool.model.js'; import type { Resource } from '../../shared/models/resource.model.js'; import { LIST_SERVERS_TOOL, LIST_TOOLS_TOOL, GET_TOOL_TOOL, CALL_TOOL_TOOL, UPDATE_SERVER_DESCRIPTION_TOOL, LIST_TAGS_TOOL, SEARCH_TOOLS_TOOL } from '../models/system-tools.constants.js'; import type { SystemToolName, ListServersParams, ListToolsInServerParams, GetToolParams, CallToolParams, UpdateServerDescriptionParams, ListTagsParams, SearchToolsParams } from '../models/system-tools.constants.js'; /** * Central service for managing system tools and MCP server interactions in the MCP Hub Lite gateway. * * The HubToolsService provides a unified interface for discovering, managing, and interacting with * all connected MCP (Model Context Protocol) servers. It serves as the primary orchestration layer * between client applications and the underlying MCP infrastructure, offering both system-level * management capabilities and direct tool execution functionality. * * ## Core Responsibilities * * - **System Tool Management**: Exposes a standardized set of system tools for server discovery and management * - **Tool Discovery**: Enables listing tools across all connected MCP servers * - **Tool Execution**: Provides safe, monitored execution of tools with comprehensive event tracking * - **Resource Management**: Dynamically generates and serves virtual resources representing server state * - **Instance Selection**: Handles intelligent server instance selection for multi-instance scenarios * - **Error Handling**: Implements consistent error handling and logging across all operations * * ## System Tools Provided * * The service exposes the following system tools through the `getSystemTools()` method: * - `list-servers`: Retrieve all connected server names * - `list-tools-in-server`: List all tools from a specific server * - `get-tool`: Retrieve complete schema for a specific tool * - `call-tool`: Execute a tool on a specific server * - `update-server-description`: Update the description of a specific MCP server * * ## Architecture Integration * * This service integrates tightly with other core components: * - **HubManagerService**: For server configuration and instance management * - **McpConnectionManager**: For actual tool execution and connection management * - **EventBusService**: For publishing tool call events and system notifications * - **GatewayService**: For system tool routing and aggregation * * All operations include comprehensive logging, error handling, and event publishing * to support observability, debugging, and monitoring of the MCP Hub Lite system. * * @example * ```typescript * const hubTools = new HubToolsService(); * * // List all connected servers * const servers = await hubTools.listServers(); * * // Call a tool on a specific server * const result = await hubTools.callTool('file-system-server', 'list-files', { directory: '/home' }); * ``` */ export declare class HubToolsService { constructor(); /** * Retrieves the complete list of system tools provided by this service. * * This method generates system tool configurations based on the SYSTEM_TOOL_NAMES constant, * ensuring consistency with the defined system tool names. Each tool includes its name, * description, input schema, and annotations for proper client-side rendering and behavior. * * @returns {Array<{ name: string; description: string; inputSchema: JsonSchema; annotations?: ToolAnnotations }>} * Array of system tool configurations */ getSystemTools(): import("./hub-tools/system-tool-definitions.js").SystemToolDefinition[]; /** * Lists all connected MCP servers with their descriptions. * * This method retrieves all configured servers from the hub manager, filters out * invalid entries using the hasValidId type guard, and returns a Record mapping * server names to their descriptions. If a server doesn't have a description, * a default description is provided. * * @returns {Promise>} Record mapping server names to descriptions */ listServers(): Promise>; /** * Lists all tools available from a specific MCP server. * * This method retrieves all tools from the specified server, handling both regular * MCP servers and the special MCP Hub Lite server (which returns system tools). * It uses the selectBestInstance function to resolve server names to instances * and leverages the MCP connection manager for tool retrieval. * * @param {ListToolsInServerParams} args - Server name and request options * @returns {Promise<{ serverName: string; tools: ToolSummary[] }>} Object containing server name and tools array * @throws {Error} If the specified server is not found or not connected */ listToolsInServer(args: ListToolsInServerParams): Promise<{ serverName: string; tools: ToolSummary[]; }>; /** * Retrieves the complete schema for a specific tool from a specific server. * * This method returns the full tool definition including name, description, input schema, * and any annotations. It's useful for clients that need detailed information about * a tool's capabilities and expected parameters before execution. * * @param {GetToolParams} args - Tool retrieval parameters * @returns {Promise} Complete tool schema or undefined if not found * @throws {Error} If the specified server is not found or not connected */ getTool(args: GetToolParams): Promise; /** * Updates the description of a specific MCP server. * * This method validates the server exists, updates its description in the configuration, * and persists the change to disk. It leverages the existing hubManager.updateServer() * method which handles configuration persistence and event publishing. * * @param {UpdateServerDescriptionParams} args - Server name and new description * @returns {Promise<{ success: boolean; serverName: string; description: string }>} Confirmation of successful update * @throws {Error} If the server is not found or update fails */ updateServerDescription(args: UpdateServerDescriptionParams): Promise<{ success: boolean; serverName: string; description: string; }>; /** * Lists all instance tags for a specific MCP server. * * This method retrieves all instances of the specified server and returns their tags, * useful for understanding which instances are available and how to select them * when using tag-match-unique instance selection strategy. * * @param {ListTagsParams} args - Server name * @returns {Promise<{ serverName: string; instances: Array<{ index: number; id: string; tags: Record }> }>} Instance tags information * @throws {Error} If the specified server is not found */ listTags(args: ListTagsParams): Promise<{ serverName: string; instances: Array<{ index: number; id: string; tags: Record; }>; }>; /** * Calls a specific system tool directly with type-safe conditional return types. * * This method provides a unified entry point for all system tool calls, using TypeScript's * conditional types to ensure type safety based on the tool name. It handles logging, * error handling, and delegates to the appropriate internal methods based on the tool name. * * @param {T} toolName - System tool name with generic type constraint * @param {SystemToolArgs} toolArgs - Type-safe arguments based on tool name * @returns {Promise} Tool execution result with accurate type safety matching actual method return types * @throws {Error} If the system tool is not found or execution fails */ callSystemTool(toolName: T, toolArgs: T extends typeof LIST_SERVERS_TOOL ? ListServersParams : T extends typeof LIST_TOOLS_TOOL ? ListToolsInServerParams : T extends typeof GET_TOOL_TOOL ? GetToolParams : T extends typeof CALL_TOOL_TOOL ? CallToolParams : T extends typeof UPDATE_SERVER_DESCRIPTION_TOOL ? UpdateServerDescriptionParams : T extends typeof LIST_TAGS_TOOL ? ListTagsParams : T extends typeof SEARCH_TOOLS_TOOL ? SearchToolsParams : never): Promise : T extends typeof LIST_TOOLS_TOOL ? { serverName: string; tools: ToolSummary[]; } : T extends typeof GET_TOOL_TOOL ? Tool | undefined : T extends typeof CALL_TOOL_TOOL ? unknown : T extends typeof UPDATE_SERVER_DESCRIPTION_TOOL ? { success: boolean; serverName: string; description: string; } : T extends typeof LIST_TAGS_TOOL ? { serverName: string; instances: Array<{ index: number; id: string; tags: Record; }>; } : T extends typeof SEARCH_TOOLS_TOOL ? Record : never>; /** * Calls a specific tool from a specific MCP server with comprehensive event tracking. * * This method handles both regular MCP server tool calls and system tool calls (when * serverName is 'mcp-hub-lite'). It publishes TOOL_CALL_STARTED, TOOL_CALL_COMPLETED, * and TOOL_CALL_ERROR events for monitoring and debugging purposes, and includes * detailed logging for observability. * * @param {CallToolParams} args - Tool call parameters * @returns {Promise} Tool execution result as returned by the server * @throws {Error} If the server is not found, not connected, or tool execution fails */ callTool(args: CallToolParams): Promise; /** * Lists all available tools from all connected servers including system tools. * * This method aggregates tools from all configured and connected MCP servers, including * the system tools provided by the MCP Hub Lite server itself. It returns a structured * object mapping server names to their respective tool arrays. * * @returns {Promise>} Object mapping server names to tool arrays */ listAllTools(): Promise>; /** * Searches for tools matching the query across all connected MCP servers. * * Results are grouped by server name, and only servers with at least one * matching tool are included. Matching is case-insensitive on tool name and description. * * @param {string} query - Search query string for matching tool names and descriptions * @returns {Promise>} * Object mapping server names to their descriptions and matching tools */ searchTools(query: string, limit?: number): Promise>; /** * Lists all dynamically generated Hub resources based on connected MCP servers. * * This method returns an array of virtual resources that represent the current state * of connected servers, providing a unified interface for resource discovery and access. * The resources are generated on-demand based on the current server configuration. * * @returns {Promise} Array of MCP resource objects representing Hub resources */ listResources(): Promise; /** * Reads content from a specific Hub resource URI. * * This method provides access to dynamically generated Hub resources by parsing the URI * and returning the appropriate content based on the resource type. It supports three * types of resources: * - Server metadata: hub://servers/{serverName} * - Tools list: hub://servers/{serverName}/tools * - Resources list: hub://servers/{serverName}/resources * * @param {string} uri - Resource URI to read (e.g., hub://servers/server-name) * @returns {Promise} Resource content based on URI type * @throws {Error} If URI format is invalid, server not found, or resource type unknown */ readResource(uri: string): Promise<{ name: string; status: unknown; toolsCount: number; tools: Record; resourcesCount: number; tags: Record; lastHeartbeat: number; uptime: number; description: string; } | Tool[] | Resource[] | string>; } export declare const hubToolsService: HubToolsService; //# sourceMappingURL=hub-tools.service.d.ts.map