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';
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions 'caching and large document support' which provides some context about performance characteristics, but doesn't describe what the tool actually produces (e.g., file structure, code format), whether it validates the Swagger document, what happens on failure, or any side effects like file system modifications. For a complex 16-parameter tool with no annotations, this is insufficient behavioral transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise - a single sentence that efficiently communicates the core purpose and key differentiators. Every word earns its place: 'Generate API client code' (action), 'from Swagger/OpenAPI document' (input), 'optimized version' (differentiator), 'with caching and large document support' (key features). No wasted words or redundant information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex tool with 16 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what the output looks like (files generated, structure), doesn't mention error handling, doesn't describe the caching behavior in detail, and provides minimal guidance on when to use this versus alternatives. The description leaves too many questions unanswered for such a sophisticated code generation tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, so all parameters are documented in the schema itself. The description doesn't add any parameter-specific information beyond what's in the schema. It mentions 'caching' which relates to the 'useCache' and 'cacheTTLMinutes' parameters, but doesn't provide additional semantic context. With complete schema coverage, the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Generate API client code from Swagger/OpenAPI document' with the specific verb 'generate' and resource 'API client code'. It distinguishes from the sibling 'generate-api-client' by mentioning 'optimized version with caching and large document support', but doesn't explicitly differentiate from other code generation siblings like 'generate-typescript-types'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context through 'optimized version with caching and large document support', suggesting this tool should be used when those features are needed. However, it doesn't provide explicit guidance on when to choose this over the non-optimized 'generate-api-client' sibling or when to use other code generation tools like 'generate-typescript-types'. No exclusions or prerequisites are mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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