Skip to main content
Glama
tuskermanshu

Swagger MCP Server

by tuskermanshu

generate-api-client-optimized

Generate API client code from Swagger/OpenAPI documents with caching and large document support for Axios, Fetch, or React Query frameworks.

Instructions

Generate API client code from Swagger/OpenAPI document (optimized version with caching and large document support).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
swaggerUrlYesSwagger/OpenAPI document URL
outputDirNoOutput directory
overwriteNoWhether to overwrite existing files
filePrefixNoFile prefix
fileSuffixNoFile suffix
clientTypeNoAPI client technology stack
generateTypeImportsNoWhether to generate type imports
typesImportPathNoTypes import path
groupByNoGrouping method
includeTagsNoInclude tags filter
excludeTagsNoExclude tags filter
headersNoRequest headers
useCacheNoWhether to use cache
cacheTTLMinutesNoCache TTL in minutes
skipValidationNoWhether to skip validation
lazyLoadingNoWhether to use lazy loading

Implementation Reference

  • Main handler function 'execute' that performs the core logic of generating optimized API client code from Swagger/OpenAPI specs using ApiClientGenerator.
    */ async execute(params: z.infer<typeof this.optimizedSchema>) { try { console.log(`[ApiClientGeneratorTool] 开始生成API客户端: ${params.swaggerUrl}`); // 创建生成器实例 const generator = new ApiClientGenerator(); // 记录进度的函数 let progressUpdates: { progress: number, message: string }[] = []; const progressCallback = (progress: number, message: string) => { progressUpdates.push({ progress, message }); }; // 执行生成 const result = await generator.generate({ ...params, progressCallback } as ApiClientGeneratorOptions); // 处理结果 if (result.success) { console.log(`[ApiClientGeneratorTool] 客户端生成成功,生成了 ${result.files.length} 个文件`); return { content: [ { type: 'text' as const, text: JSON.stringify({ success: true, files: result.files, warnings: result.warnings, progress: progressUpdates }, null, 2) } ] }; } else { console.error(`[ApiClientGeneratorTool] 客户端生成失败: ${result.error}`); return { content: [ { type: 'text' as const, text: JSON.stringify({ success: false, error: result.error, progress: progressUpdates }, null, 2) } ] }; } } catch (error) { console.error(`[ApiClientGeneratorTool] 执行异常:`, error); // 返回错误结果 return { content: [ { type: 'text' as const, text: JSON.stringify({ success: false, error: error instanceof Error ? error.message : String(error) }, null, 2) } ] }; } }
  • Zod schema for the optimized tool parameters, extending the base schema with caching and optimization options.
    // Define optimized parameter schema optimizedSchema = this.schema.extend({ /** * Whether to use cache */ useCache: z.boolean().optional().describe('Whether to use cache'), /** * Cache TTL in minutes */ cacheTTLMinutes: z.number().optional().describe('Cache TTL in minutes'), /** * Whether to skip validation */ skipValidation: z.boolean().optional().describe('Whether to skip validation'), /** * Whether to use lazy loading */ lazyLoading: z.boolean().optional().describe('Whether to use lazy loading') });
  • Registration of the 'generate-api-client-optimized' tool on the MCP server, providing optimized defaults and delegating to the execute handler.
    // 注册优化版 server.tool( this.optimizedName, this.optimizedDescription, this.optimizedSchema.shape, async (params) => { // 设置优化版默认选项 const optimizedParams = { ...params, useCache: params.useCache !== false, lazyLoading: params.lazyLoading !== false, skipValidation: params.skipValidation || false }; return await this.execute(optimizedParams); } );
  • src/index.ts:62-62 (registration)
    Main server setup where the ApiClientGeneratorTool (containing the optimized tool) is instantiated and registered.
    new ApiClientGeneratorTool().register(server);
  • Import of the ApiClientGenerator helper class used in the handler for actual code generation.
    import { ApiClientGenerator, ApiClientGeneratorOptions } from '../generators/api-client-generator';

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tuskermanshu/swagger-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server