Skip to main content
Glama
hongaah

Swiftcode MCP Server

by hongaah

generate_api_client

Generate TypeScript API clients from Swagger/OpenAPI specifications to automate integration with backend services.

Instructions

Generate TypeScript API client from Swagger/OpenAPI specification

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceYes使用本地文件路径或 swagger URL 生成 API 和类型文件 / URL or JSON file path. Examples: For full path: '//user/file.json', For file only: 'file.json' returns 'file json'. URLs should start with '/' for proper routing.
dirYesworkspace dir

Implementation Reference

  • The handler logic for the 'generate_api_client' tool. It destructures arguments, processes the source path, calls Swagger2InterfaceOutput to generate the API client in the 'apis' directory, and returns success or throws an error.
    case 'generate_api_client': {
      const { source, dir } = args
      // 判断 source 是否是文件路径
      const isFilePath = source.startsWith('/')
      const filePath = isFilePath ? `/${source}` : source
      try {
        await Swagger2InterfaceOutput({
          source: filePath,
          isDev: false,
          dir: path.join(dir, 'apis'),
        })
        return {
          content: [
            {
              type: 'text',
              text: 'API client generated successfully. Please check the apis directory. output file list',
            },
          ],
        }
      } catch (error) {
        console.error('Error while generating API client:', error)
        throw new McpError(ErrorCode.InternalError, 'Failed to generate API client', {
          code: ErrorCode.InternalError,
          message: 'Failed to generate API client',
        })
      }
    }
  • Input schema definition for the 'generate_api_client' tool, specifying 'source' (Swagger file/URL) and 'dir' (workspace directory) as required parameters.
    inputSchema: {
      type: 'object',
      properties: {
        source: {
          type: 'string',
          description:
            "使用本地文件路径或 swagger URL 生成 API 和类型文件 / URL or JSON file path. Examples: For full path: '//user/file.json', For file only: 'file.json' returns 'file json'. URLs should start with '/' for proper routing.",
        },
        dir: {
          type: 'string',
          description: 'workspace dir',
        },
      },
      required: ['source', 'dir'],
    },
  • src/index.ts:18-36 (registration)
    Registration of the 'generate_api_client' tool in the TOOLS array, which is returned by the listTools handler.
    {
      name: 'generate_api_client',
      description: 'Generate TypeScript API client from Swagger/OpenAPI specification',
      inputSchema: {
        type: 'object',
        properties: {
          source: {
            type: 'string',
            description:
              "使用本地文件路径或 swagger URL 生成 API 和类型文件 / URL or JSON file path. Examples: For full path: '//user/file.json', For file only: 'file.json' returns 'file json'. URLs should start with '/' for proper routing.",
          },
          dir: {
            type: 'string',
            description: 'workspace dir',
          },
        },
        required: ['source', 'dir'],
      },
    },
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool generates a TypeScript API client but doesn't explain what 'generate' entails (e.g., creates files, outputs code, requires write permissions), potential side effects (e.g., overwriting existing files), or any constraints (e.g., rate limits, authentication needs). This leaves significant gaps in understanding the tool's behavior.

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 a single, clear sentence: 'Generate TypeScript API client from Swagger/OpenAPI specification.' It is front-loaded with the core purpose, has zero wasted words, and efficiently communicates the essential information without unnecessary elaboration.

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?

Given the complexity of generating code from specifications, the lack of annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects like what the tool outputs (e.g., files, code snippets), error handling, or dependencies. For a tool with 2 required parameters and no structured safety hints, more context is needed to ensure proper usage.

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 the input schema already documents both parameters ('source' and 'dir') with descriptions and examples. The tool description adds no additional parameter information beyond what's in the schema. According to the rules, when schema coverage is high (>80%), the baseline score is 3 even without param details in the description.

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 TypeScript API client from Swagger/OpenAPI specification.' It specifies the verb ('generate'), resource ('TypeScript API client'), and source format ('Swagger/OpenAPI specification'). However, it doesn't explicitly differentiate from sibling tools like 'generate_sfc_client' or 'generate_sfc_template_client', which appear to be related but distinct generation tools.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools, prerequisites, or specific scenarios where this generation method is preferred. Without such context, users must infer usage based on the tool name alone, which is insufficient for effective tool selection.

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/hongaah/swiftcode-mcp-server'

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