Skip to main content
Glama

export_openapi

Export API documentation from Apifox projects to OpenAPI format. Use summary mode to review structure before importing new APIs, or full mode for complete specifications.

Instructions

查看 Apifox 接口文档:从 Apifox 项目导出接口信息。重要:在导入新接口前,务必先使用 summary 模式查看现有目录结构和接口列表,以便将新接口放入合适的目录中,保持项目结构一致性。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modeNo导出模式:summary=仅导出目录结构和接口列表(推荐,节省上下文),full=导出完整的 OpenAPI 规范。默认为 summary
oasVersionNoOpenAPI 规范版本,默认为 3.0(仅 full 模式有效)
exportFormatNo导出格式,默认为 JSON(仅 full 模式有效)
pathFilterNo路径过滤器,只导出匹配的接口路径(支持前缀匹配),如 "/api/user" 只导出用户相关接口

Implementation Reference

  • MCP server handler for the export_openapi tool. Handles input parameters, calls ApifoxClient.exportOpenApi, applies path filtering, and formats output in summary or full mode.
    case 'export_openapi': {
      const { mode, oasVersion, exportFormat, pathFilter } = args as {
        mode?: 'summary' | 'full';
        oasVersion?: '2.0' | '3.0' | '3.1';
        exportFormat?: 'JSON' | 'YAML';
        pathFilter?: string;
      };
    
      const exportMode = mode || 'summary';
    
      const result = await apifoxClient.exportOpenApi({
        oasVersion: oasVersion || '3.0',
        exportFormat: exportFormat || 'JSON'
      });
    
      // 路径过滤
      let filteredPaths = result.paths;
      if (pathFilter) {
        filteredPaths = {};
        Object.keys(result.paths).forEach(path => {
          if (path.startsWith(pathFilter)) {
            filteredPaths[path] = result.paths[path];
          }
        });
      }
    
      // Summary 模式:只返回目录结构和接口列表
      if (exportMode === 'summary') {
        let resultText = '✅ 接口文档概览(Summary 模式)\n\n';
    
        // 统计信息
        const pathsCount = Object.keys(filteredPaths).length;
        const totalCount = Object.keys(result.paths).length;
    
        resultText += `📊 统计信息:\n`;
        resultText += `  - 项目标题: ${result.info?.title || '未命名'}\n`;
        if (pathFilter) {
          resultText += `  - 过滤条件: ${pathFilter}\n`;
          resultText += `  - 匹配接口: ${pathsCount} / ${totalCount}\n`;
        } else {
          resultText += `  - 总接口数: ${pathsCount}\n`;
        }
        resultText += '\n';
    
        // 按路径前缀分组(模拟目录结构)
        const groups: { [key: string]: any[] } = {};
        Object.keys(filteredPaths).forEach(path => {
          const pathObj = filteredPaths[path];
          const methods = Object.keys(pathObj).filter(m => m !== 'parameters');
    
          methods.forEach(method => {
            const operation = pathObj[method];
            const tags = operation.tags || ['未分类'];
            const tag = tags[0] || '未分类';
    
            if (!groups[tag]) {
              groups[tag] = [];
            }
    
            groups[tag].push({
              path,
              method: method.toUpperCase(),
              summary: operation.summary || '无描述'
            });
          });
        });
    
        // 显示目录结构
        resultText += '📁 目录结构和接口列表:\n\n';
        const sortedGroups = Object.keys(groups).sort();
    
        sortedGroups.forEach(groupName => {
          resultText += `📂 ${groupName}\n`;
          groups[groupName].forEach(api => {
            resultText += `  └─ [${api.method}] ${api.path}\n`;
            resultText += `     ${api.summary}\n`;
          });
          resultText += '\n';
        });
    
        resultText += '\n💡 提示:\n';
        resultText += '  - 导入新接口时,请参考上述目录结构\n';
        resultText += '  - 将相关接口放入对应的目录(使用 tags 字段)\n';
        resultText += '  - 保持接口路径命名风格一致\n';
        if (!pathFilter) {
          resultText += '  - 如需查看特定接口详情,使用 pathFilter 参数过滤\n';
          resultText += '  - 如需完整规范,使用 mode: "full"\n';
        }
    
        return {
          content: [
            {
              type: 'text',
              text: resultText
            }
          ]
        };
      }
    
      // Full 模式:返回完整 OpenAPI 规范
      let resultText = '✅ OpenAPI 规范导出成功(Full 模式)\n\n';
    
      const pathsCount = Object.keys(filteredPaths).length;
      const schemasCount = result.components?.schemas ? Object.keys(result.components.schemas).length : 0;
    
      resultText += `📊 导出统计:\n`;
      resultText += `  - OpenAPI 版本: ${result.openapi || result.swagger}\n`;
      resultText += `  - 项目标题: ${result.info?.title || '未命名'}\n`;
      resultText += `  - 接口数量: ${pathsCount}\n`;
      resultText += `  - 数据模型数量: ${schemasCount}\n`;
    
      if (pathsCount > 0) {
        resultText += '\n📋 接口列表:\n';
        const paths = Object.keys(filteredPaths);
        paths.slice(0, 10).forEach(path => {
          const methods = Object.keys(filteredPaths[path]).filter(m => m !== 'parameters');
          resultText += `  - ${path} [${methods.join(', ').toUpperCase()}]\n`;
        });
        if (paths.length > 10) {
          resultText += `  ... 还有 ${paths.length - 10} 个接口\n`;
        }
      }
    
      // 如果有过滤,返回过滤后的规范
      let exportedSpec = result;
      if (pathFilter) {
        exportedSpec = {
          ...result,
          paths: filteredPaths
        };
      }
    
      return {
        content: [
          {
            type: 'text',
            text: resultText
          },
          {
            type: 'text',
            text: `\n📄 完整 OpenAPI 规范:\n\`\`\`json\n${JSON.stringify(exportedSpec, null, 2)}\n\`\`\``
          }
        ]
      };
    }
  • Input schema and metadata definition for the export_openapi tool in the tools registry.
    {
      name: 'export_openapi',
      description: '查看 Apifox 接口文档:从 Apifox 项目导出接口信息。重要:在导入新接口前,务必先使用 summary 模式查看现有目录结构和接口列表,以便将新接口放入合适的目录中,保持项目结构一致性。',
      inputSchema: {
        type: 'object',
        properties: {
          mode: {
            type: 'string',
            enum: ['summary', 'full'],
            description: '导出模式:summary=仅导出目录结构和接口列表(推荐,节省上下文),full=导出完整的 OpenAPI 规范。默认为 summary'
          },
          oasVersion: {
            type: 'string',
            enum: ['2.0', '3.0', '3.1'],
            description: 'OpenAPI 规范版本,默认为 3.0(仅 full 模式有效)'
          },
          exportFormat: {
            type: 'string',
            enum: ['JSON', 'YAML'],
            description: '导出格式,默认为 JSON(仅 full 模式有效)'
          },
          pathFilter: {
            type: 'string',
            description: '路径过滤器,只导出匹配的接口路径(支持前缀匹配),如 "/api/user" 只导出用户相关接口'
          }
        }
      }
    }
  • ApifoxClient helper method implementing the core export logic by calling the Apifox /export-openapi API endpoint.
    async exportOpenApi(options?: {
      oasVersion?: '2.0' | '3.0' | '3.1';
      exportFormat?: 'JSON' | 'YAML';
      scope?: {
        type?: 'ALL' | 'SELECTED_FOLDERS' | 'SELECTED_ENDPOINTS';
        excludedByTags?: string[];
      };
      options?: {
        includeApifoxExtensionProperties?: boolean;
        addFoldersToTags?: boolean;
      };
    }): Promise<any> {
      const response = await this.client.post(
        `/v1/projects/${this.projectId}/export-openapi`,
        {
          oasVersion: options?.oasVersion || '3.0',
          exportFormat: options?.exportFormat || 'JSON',
          ...(options?.scope && { scope: options.scope }),
          ...(options?.options && { options: options.options })
        }
      );
      return response.data;
    }
  • src/index.ts:211-213 (registration)
    Registration of the tools list (including export_openapi) via MCP ListToolsRequestSchema handler.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return { tools };
    });
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the important constraint about using summary mode before imports and hints at context-saving benefits, but doesn't describe authentication requirements, rate limits, error conditions, or what the exported data looks like. For a tool with no annotations, this leaves significant behavioral aspects undocumented.

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

Conciseness4/5

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

The description is appropriately concise with two sentences. The first states the purpose, the second provides important usage guidance. Both sentences earn their place by adding value. However, the structure could be slightly improved by front-loading the purpose more explicitly.

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

Completeness3/5

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

Given no annotations, no output schema, and 4 parameters, the description provides adequate purpose and usage guidance but lacks details about authentication, error handling, rate limits, and output format. For a tool that exports potentially complex data, more context about what gets returned would be helpful, though the schema coverage is excellent.

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?

With 100% schema description coverage, the schema already documents all 4 parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema. It mentions 'summary 模式' (summary mode) which aligns with the 'mode' parameter, but provides no additional semantic context about parameters beyond what the schema already states.

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: '从 Apifox 项目导出接口信息' (export interface information from an Apifox project). It specifies the resource (Apifox project interfaces) and verb (export), but doesn't explicitly differentiate from its sibling 'import_openapi' beyond the obvious export/import distinction.

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

Usage Guidelines4/5

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

The description provides clear usage guidance: '在导入新接口前,务必先使用 summary 模式查看现有目录结构和接口列表,以便将新接口放入合适的目录中' (before importing new interfaces, use summary mode to view existing directory structure and interface list). This gives a specific when-to-use scenario and recommends summary mode for context-saving. However, it doesn't explicitly state when NOT to use this tool or alternatives beyond the sibling import tool.

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/Warren-W/apifox-mcp'

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