mcp-openapi-schema-explorer
Version:
MCP OpenAPI schema explorer
70 lines (69 loc) • 3.78 kB
TypeScript
import { OpenAPIV3 } from 'openapi-types';
import { RenderContext, RenderResultItem } from '../rendering/types.js';
export type FormattedResultItem = {
uri: string;
mimeType?: string;
text: string;
isError?: boolean;
};
/**
* Formats RenderResultItem array into an array compatible with the 'contents'
* property of ReadResourceResultSchema (specifically TextResourceContents).
*/
export declare function formatResults(context: RenderContext, items: RenderResultItem[]): FormattedResultItem[];
/**
* Type guard to check if an object is an OpenAPIV3.Document.
*/
export declare function isOpenAPIV3(spec: unknown): spec is OpenAPIV3.Document;
/**
* Safely retrieves a PathItemObject from the specification using a Map.
* Throws an McpError if the path is not found.
*
* @param spec The OpenAPIV3 Document.
* @param path The decoded path string (e.g., '/users/{id}').
* @returns The validated PathItemObject.
* @throws {McpError} If the path is not found in spec.paths.
*/
export declare function getValidatedPathItem(spec: OpenAPIV3.Document, path: string): OpenAPIV3.PathItemObject;
/**
* Validates requested HTTP methods against a PathItemObject using a Map.
* Returns the list of valid requested methods.
* Throws an McpError if none of the requested methods are valid for the path item.
*
* @param pathItem The PathItemObject to check against.
* @param requestedMethods An array of lowercase HTTP methods requested by the user.
* @param pathForError The path string, used for creating informative error messages.
* @returns An array of the requested methods that are valid for this path item.
* @throws {McpError} If none of the requested methods are valid.
*/
export declare function getValidatedOperations(pathItem: OpenAPIV3.PathItemObject, requestedMethods: string[], pathForError: string): string[];
/**
* Safely retrieves the component map for a specific type (e.g., schemas, responses)
* from the specification using a Map.
* Throws an McpError if spec.components or the specific type map is not found.
*
* @param spec The OpenAPIV3 Document.
* @param type The ComponentType string (e.g., 'schemas', 'responses').
* @returns The validated component map object (e.g., spec.components.schemas).
* @throws {McpError} If spec.components or the type map is not found.
*/
export declare function getValidatedComponentMap(spec: OpenAPIV3.Document, type: string): NonNullable<OpenAPIV3.ComponentsObject[keyof OpenAPIV3.ComponentsObject]>;
/**
* Validates requested component names against a specific component map (e.g., schemas).
* Returns an array of objects containing the valid name and its corresponding detail object.
* Throws an McpError if none of the requested names are valid for the component map.
*
* @param componentMap The specific component map object (e.g., spec.components.schemas).
* @param requestedNames An array of component names requested by the user.
* @param componentTypeForError The component type string, used for creating informative error messages.
* @param detailsMap A Map created from the specific component map object (e.g., new Map(Object.entries(spec.components.schemas))).
* @param requestedNames An array of component names requested by the user.
* @param componentTypeForError The component type string, used for creating informative error messages.
* @returns An array of { name: string, detail: V } for valid requested names, where V is the value type of the Map.
* @throws {McpError} If none of the requested names are valid.
*/
export declare function getValidatedComponentDetails<V extends OpenAPIV3.ReferenceObject | object>(detailsMap: Map<string, V>, // Accept Map<string, V>
requestedNames: string[], componentTypeForError: string): {
name: string;
detail: V;
}[];