@web-interact-mcp/client
Version:
A production-ready TypeScript library that transforms web applications into MCP (Model Context Protocol) servers with robust two-way communication via SignalR
159 lines • 4.93 kB
TypeScript
/**
* @fileoverview Tool Registry for managing Web Interact MCP tool configurations
* @description Manages the collection of available tools with validation and discovery capabilities
* @version 1.0.0
* @author Vijay Nirmal
*/
import { ToolConfiguration, ToolParameterSchema } from './types';
/**
* Tool summary information for MCP server discovery
*/
export interface ToolSummary {
toolId: string;
title: string;
description: string;
mode: string;
hasParameters: boolean;
parameterCount: number;
parameterSchema?: ToolParameterSchema;
destructive?: boolean;
idempotent?: boolean;
openWorld?: boolean;
readOnly?: boolean;
}
/**
* Manages the collection of all available Tools.
* Provides functionality to load configurations from various sources and discover tools based on context.
*/
export declare class ToolRegistry {
private readonly tools;
private readonly logger;
private cachedToolsJson;
/**
* Creates a new ToolRegistry instance
* @param enableLogging - Whether to enable console logging (default: false)
*/
constructor(enableLogging?: boolean);
/**
* Loads tool configurations from a source
* @param source - Array of configurations or URL to a JSON file
* @throws {Error} When source is invalid or tools fail validation
*/
loadTools(source: ToolConfiguration[] | string): Promise<void>;
/**
* Gets a specific tool by its ID
* @param toolId - The ID of the tool to retrieve
* @returns The tool configuration or undefined if not found
*/
getToolById(toolId: string): ToolConfiguration | undefined;
/**
* Returns a map of all tools available for a given page URL
* @param url - The URL of the current page
* @returns Map of available tools for the page
*/
getAvailableTools(url: string): Map<string, ToolConfiguration>;
/**
* Returns a map of all global tools (tools without pageMatcher)
* @returns Map of all global tools
*/
getGlobalTools(): Map<string, ToolConfiguration>;
/**
* Returns all available tools
* @returns Map of all tools
*/
getAllTools(): Map<string, ToolConfiguration>;
/**
* Gets tools that have parameter schemas defined
* @returns Map of tools that have parameter schemas
*/
getToolsWithParameterSchemas(): Map<string, ToolConfiguration>;
/**
* Gets parameter schema for a specific tool
* @param toolId - The ID of the tool
* @returns The parameter schema or undefined if not found
*/
getParameterSchema(toolId: string): ToolParameterSchema | undefined;
/**
* Gets all tools as a JSON string for MCP server communication
* @returns JSON string representation of all tool configurations
*/
getToolsAsJson(): string;
/**
* Gets a summary of all tools with their parameter information for MCP server discovery
* @returns Array of tool summaries including parameter information
*/
getToolsSummaryForMCP(): ToolSummary[];
/**
* Gets the total number of registered tools
* @returns The count of registered tools
*/
getToolCount(): number;
/**
* Checks if a tool exists by ID
* @param toolId - The ID of the tool to check
* @returns True if the tool exists, false otherwise
*/
hasToolId(toolId: string): boolean;
/**
* Removes a tool from the registry
* @param toolId - The ID of the tool to remove
* @returns True if the tool was removed, false if it didn't exist
*/
removeTool(toolId: string): boolean;
/**
* Clears all tools from the registry
*/
clearTools(): void;
/**
* Fetches tools from a URL
* @private
*/
private fetchToolsFromUrl;
/**
* Validates and loads multiple configurations
* @private
*/
private validateAndLoadConfigurations;
/**
* Pre-calculates and caches the JSON representation of all tools
* @private
*/
private cacheToolsJson;
/**
* Validates a tool configuration
* @private
* @throws {Error} When configuration is invalid
*/
private validateToolConfiguration;
/**
* Validates a single tool step
* @private
*/
private validateToolStep;
/**
* Validates a tool action
* @private
*/
private validateToolAction;
/**
* Validates a parameter schema
* @private
*/
private validateParameterSchema;
/**
* Validates a parameter definition
* @private
*/
private validateParameterDefinition;
/**
* Checks if a tool is available for a specific page URL
* @private
*/
private isToolAvailableForPage;
/**
* Creates a silent logger that doesn't output anything
* @private
*/
private createSilentLogger;
}
//# sourceMappingURL=tool-registry.d.ts.map