get_apifox_api_info
Retrieve detailed information about a specific API from an Apifox project by providing the project ID and API ID. Integrates API documentation for AI assistants to extract and understand data.
Instructions
Get the info of Apifox API.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apiId | Yes | The API ID of Apifox | |
| projectId | Yes | The project ID of Apifox |
Implementation Reference
- src/index.ts:42-82 (handler)Handler function for the get_apifox_api_info tool. Retrieves access token from env or args, calls fetchApiInfoApi, and handles errors.async ({ projectId, apiId }) => { try { // Get token from command line arguments or environment variable let token = process.env.APIFOX_ACCESS_TOKEN // Check if token is provided in command line arguments // Format: --token=your_token or --apifox-token=your_token const args = process.argv.slice(2) for (const arg of args) { const tokenArg = arg.match(/^--(?:apifox-)?token=(.+)$/) if (tokenArg) { token = tokenArg[1] break } } if (!token) { throw new Error("No token provided") } const result = await fetchApiInfoApi(projectId, apiId, token) return { content: [ { type: "text", text: result, }, ], } } catch (error: any) { return { content: [ { type: "text", text: `Error fetching API info: ${error.message}`, }, ], isError: true, } } },
- src/index.ts:38-41 (schema)Zod input schema defining projectId and apiId parameters.{ projectId: z.string().describe("The project ID of Apifox"), apiId: z.string().describe("The API ID of Apifox"), },
- src/index.ts:35-83 (registration)Registration of the get_apifox_api_info tool with McpServer.tool() including name, description, schema, and handler.server.tool( "get_apifox_api_info", "Get the info of Apifox API.", { projectId: z.string().describe("The project ID of Apifox"), apiId: z.string().describe("The API ID of Apifox"), }, async ({ projectId, apiId }) => { try { // Get token from command line arguments or environment variable let token = process.env.APIFOX_ACCESS_TOKEN // Check if token is provided in command line arguments // Format: --token=your_token or --apifox-token=your_token const args = process.argv.slice(2) for (const arg of args) { const tokenArg = arg.match(/^--(?:apifox-)?token=(.+)$/) if (tokenArg) { token = tokenArg[1] break } } if (!token) { throw new Error("No token provided") } const result = await fetchApiInfoApi(projectId, apiId, token) return { content: [ { type: "text", text: result, }, ], } } catch (error: any) { return { content: [ { type: "text", text: `Error fetching API info: ${error.message}`, }, ], isError: true, } } }, )
- src/utils/apifox.ts:4-29 (helper)Helper function that performs the actual API request to Apifox to export OpenAPI JSON for the specified project and API.export async function fetchApiInfoApi(projectId: string, apiId: string, accessToken: string) { const response = await request(`https://api.apifox.com/v1/projects/${projectId}/export-openapi`, { method: 'POST', headers: { 'X-Apifox-Api-Version': '2024-03-28', 'Authorization': `Bearer ${accessToken}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ scope: { type: 'SELECTED_ENDPOINTS', selectedEndpointIds: [apiId] }, options: { includeApifoxExtensionProperties: false, addFoldersToTags: false }, oasVersion: '3.1', exportFormat: 'JSON' }) }); const result = await response.body.text(); return result }