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'],
      },
    },

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