get_api_endpoint_info
Retrieves API endpoint definitions from Apifox projects, providing OpenAPI 3.1 compliant specifications including request methods, parameters, headers, and response schemas for development and code generation.
Instructions
获取apifox的接口定义信息,数据符合OpenAPI 3.1规范。遇到例如:https://app.apifox.com/link/project/{projectId}/apis/api-{endpointId}的链接,请解析出projectId和endpointId,并调用本工具获取接口定义信息。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| endpointId | Yes | 接口Endpoint的ID | |
| projectId | Yes | Apifox的项目ID |
Implementation Reference
- src/index.ts:22-67 (registration)Registration of the 'get_api_endpoint_info' tool using server.tool(), including schema and handler.server.tool( "get_api_endpoint_info", "获取apifox的接口定义信息,数据符合OpenAPI 3.1规范。遇到例如:https://app.apifox.com/link/project/{projectId}/apis/api-{endpointId}的链接,请解析出projectId和endpointId,并调用本工具获取接口定义信息。", { projectId: z.number().describe("Apifox的项目ID"), endpointId: z.number().describe("接口Endpoint的ID"), }, async ({ projectId, endpointId }) => { try { const response = await axios.post( `${BASE_URL}/v1/projects/${projectId}/export-openapi`, JSON.stringify({ scope: { type: "SELECTED_ENDPOINTS", selectedEndpointIds: [endpointId], }, }), { headers: { "Content-Type": "application/json", "X-Apifox-Api-Version": "2024-03-28", Authorization: `Bearer ${APIFOX_AUTH}`, }, } ); return { content: [ { type: "text", text: JSON.stringify(response.data, null, 2) }, ], }; } catch (error) { let errorMessage = ""; if (axios.isAxiosError(error)) { errorMessage = JSON.stringify(error.response?.data, null, 2); } else if (error instanceof Error) { errorMessage = error.message; } else { errorMessage = JSON.stringify(error, null, 2); } return { isError: true, content: [{ type: "text", text: errorMessage }], }; } } );
- src/index.ts:25-28 (schema)Input schema defined with Zod for projectId (number) and endpointId (number).{ projectId: z.number().describe("Apifox的项目ID"), endpointId: z.number().describe("接口Endpoint的ID"), },
- src/index.ts:29-66 (handler)Handler function that exports OpenAPI spec for the given Apifox project and endpoint ID via axios POST request, returns JSON stringified response or error.async ({ projectId, endpointId }) => { try { const response = await axios.post( `${BASE_URL}/v1/projects/${projectId}/export-openapi`, JSON.stringify({ scope: { type: "SELECTED_ENDPOINTS", selectedEndpointIds: [endpointId], }, }), { headers: { "Content-Type": "application/json", "X-Apifox-Api-Version": "2024-03-28", Authorization: `Bearer ${APIFOX_AUTH}`, }, } ); return { content: [ { type: "text", text: JSON.stringify(response.data, null, 2) }, ], }; } catch (error) { let errorMessage = ""; if (axios.isAxiosError(error)) { errorMessage = JSON.stringify(error.response?.data, null, 2); } else if (error instanceof Error) { errorMessage = error.message; } else { errorMessage = JSON.stringify(error, null, 2); } return { isError: true, content: [{ type: "text", text: errorMessage }], }; } }