UNPKG

mcp-swagger-parser

Version:

Enterprise-grade OpenAPI/Swagger specification parser for Model Context Protocol (MCP) projects

131 lines 3.42 kB
import { OpenAPISpec } from '../types/index'; import { MCPTool, TransformerOptions } from './types'; export type { MCPTool, MCPToolResponse, TransformerOptions, ContentBlock, TextContent, ImageContent, AudioContent, ResourceLink, EmbeddedResource } from './types'; /** * OpenAPI to MCP Tools Transformer */ export declare class OpenAPIToMCPTransformer { private spec; private options; private annotationExtractor; private authManager?; private customHeadersManager?; constructor(spec: OpenAPISpec, options?: TransformerOptions); /** * 初始化认证管理器 */ private initializeAuthManager; /** * 初始化自定义请求头管理器 */ private initializeCustomHeadersManager; /** * Transform OpenAPI specification to MCP Tools */ transformToMCPTools(): MCPTool[]; /** * Get default base URL from spec */ private getDefaultBaseUrl; /** * 标准化 Base URL */ private normalizeBaseUrl; /** * Check if operation should be included based on options */ private shouldIncludeOperation; /** * Create MCP Tool from OpenAPI Operation */ private createMCPToolFromOperation; /** * Generate tool name from operation */ private generateToolName; /** * Generate description from operation */ private generateDescription; /** * Generate input schema from operation parameters and request body */ private generateInputSchema; /** * Create handler function for the operation */ private createHandler; /** * Execute HTTP request */ private executeHttpRequest; /** * 构建带参数的完整 URL */ private buildUrlWithParams; /** * 构建基础 URL(处理 baseUrl + pathPrefix + path 的拼接) */ private buildBaseUrl; /** * 构建请求体 */ private buildRequestBody; /** * 格式化 HTTP 响应为 MCP 格式 */ private formatHttpResponse; /** * 处理请求错误 */ private handleRequestError; /** * Build URL with path parameters */ private buildUrl; /** * Check if object is a reference */ private isReferenceObject; /** * 从OpenAPI参数中提取所有可能的示例值 */ private extractParameterExamples; /** * 生成完整的输入示例对象 */ private generateInputExamples; /** * 使用MediaType级别的示例增强schema */ private enhanceSchemaWithMediaTypeExamples; /** * 将示例对象的值合并到schema的properties中 */ private mergeExamplesIntoSchemaProperties; /** * Convert OpenAPI schema to JSON schema */ private convertSchemaToJsonSchema; /** * 构建增强的响应文本,包含字段注释 */ private buildEnhancedResponseText; /** * 格式化字段注释为易读的文本 */ private formatFieldAnnotations; /** * 从响应数据中获取字段值 */ private getFieldValue; /** * 格式化字段值为可读的字符串 */ private formatFieldValue; } /** * Convenience function to transform OpenAPI spec to MCP tools */ export declare function transformToMCPTools(spec: OpenAPISpec, options?: TransformerOptions): MCPTool[]; //# sourceMappingURL=index.d.ts.map