import { OpenAPIV3 } from "openapi-types"; import type { Agent as HttpsAgent } from "node:https"; import type { AuthProvider } from "./auth-provider.js"; import { Tool } from "@modelcontextprotocol/sdk/types.js"; /** * Extended Tool interface with metadata for filtering * This extends the standard MCP Tool interface with additional properties * that are computed during tool creation to optimize filtering operations */ export interface ExtendedTool extends Tool { /** OpenAPI tags associated with this tool's operation */ tags?: string[]; /** HTTP method for this tool (GET, POST, etc.) */ httpMethod?: string; /** Primary resource name extracted from the path */ resourceName?: string; /** Original OpenAPI path before toolId conversion */ originalPath?: string; } /** * Spec input method type */ export type SpecInputMethod = "url" | "file" | "stdin" | "inline"; /** * Options for the OpenAPI spec loader */ export interface OpenAPISpecLoaderOptions { disableAbbreviation?: boolean; verbose?: boolean; /** * HTTPS agent applied when loading the spec from an https:// URL, so specs served * behind mTLS or a private CA can be fetched with the same TLS settings as API calls */ httpsAgent?: HttpsAgent; /** * Restricts `httpsAgent` to spec URLs on this URL's origin (scheme + host + port), * typically the API base URL. Spec URLs (and redirect targets) on any other origin * are fetched without the agent, so client certificates, custom CAs and * `rejectUnauthorized: false` never leak to unrelated hosts. * When omitted, the agent is used for every https:// spec URL. */ httpsAgentScope?: string; /** * Auth provider whose headers are sent with spec requests the `specAuth` mode allows */ authProvider?: AuthProvider; /** * Which spec URLs receive auth headers (default `"same-origin"`): * - `"same-origin"`: only URLs on the origin of `authScope` (typically the API base URL) * - `"always"`: the spec URL's own origin, even if it differs from the API * - `"never"`: no auth headers on spec requests * Redirects off the allowed origin never carry auth headers. */ specAuth?: SpecAuthMode; /** * URL whose origin auth headers are restricted to in `"same-origin"` mode, typically * the API base URL. Without it, `"same-origin"` sends no auth headers. */ authScope?: string; } /** * Which spec URLs receive HTTP auth headers */ export type SpecAuthMode = "same-origin" | "always" | "never"; /** * Class to load and parse OpenAPI specifications */ export declare class OpenAPISpecLoader { /** * Disable name optimization */ private disableAbbreviation; private logger; /** * Optional HTTPS agent (mTLS client cert/key, custom CA, TLS verification settings) * used when fetching the spec from an https:// URL */ private httpsAgent?; /** * Origin the HTTPS agent is restricted to. `undefined` means unrestricted, * `null` means the configured scope was not a valid URL (agent is never used). */ private httpsAgentOrigin?; private authProvider?; private specAuth; /** Origin auth headers are restricted to in "same-origin" mode (null: none) */ private authOrigin; constructor(config?: OpenAPISpecLoaderOptions); /** * Load an OpenAPI specification from various sources */ loadOpenAPISpec(specPathOrUrl: string, inputMethod?: SpecInputMethod, inlineContent?: string): Promise; /** * Load spec content from URL. * * Requests that need neither the HTTPS agent nor auth headers use Node's built-in * fetch, as before. Otherwise axios is used (fetch cannot use a node:https Agent, * and AuthProvider.handleAuthError expects an AxiosError). Redirects are then * followed manually so every hop is re-checked: the agent and auth headers are * only sent to the origins they are scoped to. */ private loadFromUrl; private axiosGet; /** * Origin auth headers may be sent to for this spec URL, or null for none */ private resolveAllowedAuthOrigin; /** * Auth headers for a request to this URL. `headers` is undefined when none may or * need be sent. If the provider throws (e.g. no token set yet), the request goes * out unauthenticated and `unavailable` explains why, so a spec that needs no auth * still loads and one that does fails with the provider's reason. */ private getSpecAuthHeaders; private toAxiosError; /** * Run a request and, when TLS options were skipped for it, add that to any error: * otherwise a TLS failure only shows up as a generic "fetch failed" */ private withNotice; private appendNotice; private describeSkippedTlsOptions; /** * Load spec content with Node's built-in fetch (no custom TLS settings, no auth) */ private fetchText; /** * Whether the HTTPS agent may be used for this URL: it must be https:// and, * when a scope is configured, on the scoped origin */ private shouldUseHttpsAgent; /** * Origin of an http(s) URL, or null for invalid URLs and other schemes (whose * opaque origin "null" would otherwise compare equal to each other) */ private getOrigin; /** * Load spec content from local file */ private loadFromFile; /** * Load spec content from standard input */ private loadFromStdin; /** * Parse spec content as JSON or YAML */ private parseSpecContent; /** * Inline `$ref` schemas from components and drop recursive cycles */ private inlineSchema; /** * Determine the appropriate JSON Schema type for a parameter * @param paramSchema The OpenAPI schema object after inlining * @param paramName The name of the parameter (for logging purposes) * @returns The determined type string, or undefined if the type should be omitted */ private determineParameterType; /** * Extract the primary resource name from an OpenAPI path * Examples: * - "/users" -> "users" * - "/users/{id}" -> "users" * - "/api/v1/users/{id}/posts" -> "posts" * - "/health" -> "health" */ private extractResourceName; /** * Parse an OpenAPI specification into a map of tools */ parseOpenAPISpec(spec: OpenAPIV3.Document): Map; /** * Make sure a generated tool name is unique within the server (Issue #103). * * Different operations can reduce to the same name (e.g. summaries that only differ * in non-ASCII characters that get sanitized away). The first operation in spec order * keeps the base name; later ones get a suffix derived from the tool ID (method + path). * * Note: only the suffix value is deterministic per method + path. Which operation keeps * the bare name depends on spec order, so reordering or inserting colliding operations * can change names. Tool IDs or explicit operationIds are the stable way to reference tools. */ private ensureUniqueToolName; private generateShortHash; private splitCombined; private splitCombinedWithoutNumbers; private _initialSanitizeAndValidate; private _performSemanticAbbreviation; private _applyVowelRemovalIfOverLength; private _truncateAndApplyHashIfNeeded; private _finalizeNameFormatting; abbreviateOperationId(originalId: string, maxLength?: number): string; }