/** * External API Dependency Detector * * Identifies tools that depend on external APIs based on: * 1. Tool name and description patterns (fast, always available) * 2. Source code scanning for API calls (more accurate, when source available) * * This information enables downstream assessors to adjust their behavior: * - TemporalAssessor: Relaxed variance thresholds for external API tools * - FunctionalityAssessor: Accept API errors as valid responses * - ErrorHandlingAssessor: Account for external service failures * * Issue #168: Enhanced with source code scanning support * * @module helpers/ExternalAPIDependencyDetector */ import { Tool } from "@modelcontextprotocol/sdk/types.js"; /** * Implications of external API dependencies for downstream assessors * @public */ export interface ExternalAPIImplications { /** Expected temporal variance behavior */ temporalVariance: string; /** Dependency on external service availability */ availabilityDependency: string; /** Potential rate limiting from external services */ rateLimitingRisk?: string; } /** * External API dependency detection results * @public */ export interface ExternalAPIDependencyInfo { /** Set of tool names that depend on external APIs */ toolsWithExternalAPIDependency: Set; /** Number of tools detected with external API dependencies */ detectedCount: number; /** Detection confidence based on pattern strength */ confidence: "high" | "medium" | "low"; /** List of detected tool names (for serialization) */ detectedTools: string[]; /** Extracted domains from source code scanning (e.g., ["api.worldbank.org"]) */ domains?: string[]; /** Whether source code was available and scanned */ sourceCodeScanned?: boolean; /** Implications for downstream assessors when external APIs are detected */ implications?: ExternalAPIImplications; } /** * Detects external API dependencies in MCP tools based on name and description patterns. * Designed to run during context preparation before assessors execute. * * @public */ export declare class ExternalAPIDependencyDetector { /** * Tool name patterns that suggest external API dependency. * Uses word-boundary matching to prevent false positives. * * Extracted from VarianceClassifier (Issue #166) for reuse across modules. */ private readonly EXTERNAL_API_PATTERNS; /** * Description patterns that suggest external API dependency. * Regex patterns for more flexible matching. */ private readonly EXTERNAL_API_DESCRIPTION_PATTERNS; /** * Source code patterns that indicate external API calls. * Each pattern captures the URL in group 1. * * Issue #168: Patterns from proposal for source code scanning */ private readonly SOURCE_CODE_API_PATTERNS; /** * URL patterns to skip (localhost, local networks, documentation) */ private readonly LOCALHOST_PATTERNS; /** * File patterns to skip during source code scanning */ private readonly SKIP_FILE_PATTERNS; /** * Detect external API dependencies from tools and optionally source code. * * Detection strategy: * 1. Always analyze tool names and descriptions (fast, no source needed) * 2. If sourceCodeFiles provided, scan for actual API calls (more accurate) * 3. Combine results and compute confidence * * @param tools - List of MCP tools to analyze * @param sourceCodeFiles - Optional map of file paths to content for source scanning * @returns Detection results with tool names, domains, and implications */ detect(tools: Tool[], sourceCodeFiles?: Map): ExternalAPIDependencyInfo; /** Maximum content length per file (500KB) - prevents ReDoS attacks */ private readonly MAX_CONTENT_LENGTH; /** Maximum matches per file - prevents runaway matching */ private readonly MAX_MATCHES_PER_FILE; /** * Scan source code files for external API URLs. * Returns unique external domains found in the code. * * @param sourceCodeFiles - Map of file paths to content * @returns Array of unique external domain names */ scanSourceCode(sourceCodeFiles: Map): string[]; /** * Extract the hostname from a URL string. * * @param url - URL string (may be partial) * @returns Hostname or null if extraction fails */ private extractDomain; /** * Check if a URL points to localhost or local network. * * @param url - URL string to check * @returns true if URL is local */ private isLocalhost; /** * Check if a file should be skipped during source scanning. * * @param filePath - Path to check * @returns true if file should be skipped */ private shouldSkipFile; /** * Compute detection confidence based on both methods. * Source code confirmation boosts confidence. * * @param toolCount - Number of tools detected via name/description * @param domains - Domains found in source code * @returns Confidence level */ private computeConfidence; /** * Generate implications for downstream assessors. * * @param domains - External domains found * @returns Implications object */ private generateImplications; /** * Check if a single tool depends on external APIs. * Uses BOTH name patterns AND description analysis for detection. * * @param tool - MCP tool to check * @returns true if tool appears to depend on external APIs */ isExternalAPITool(tool: Tool): boolean; /** * Get the list of name patterns used for detection. * Useful for debugging and documentation. */ getNamePatterns(): readonly string[]; /** * Get the list of description patterns used for detection. * Useful for debugging and documentation. */ getDescriptionPatterns(): readonly RegExp[]; } //# sourceMappingURL=ExternalAPIDependencyDetector.d.ts.map