get_api_endpoint_info
Retrieve API endpoint definitions from Apifox projects using project and endpoint IDs. Returns OpenAPI 3.1-compliant specifications for methods, parameters, headers, and response schemas.
Instructions
获取apifox的接口定义信息,数据符合OpenAPI 3.1规范。遇到例如:https://app.apifox.com/link/project/{projectId}/apis/api-{endpointId}的链接,请解析出projectId和endpointId,并调用本工具获取接口定义信息。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectId | Yes | Apifox的项目ID | |
| endpointId | Yes | 接口Endpoint的ID |
Implementation Reference
- src/index.ts:22-67 (registration)Registration of the tool 'get_api_endpoint_info' via server.tool() with name, description, 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:29-67 (handler)Handler function that makes an HTTP POST request to Apifox's export-openapi endpoint to retrieve endpoint info in OpenAPI 3.1 format, then returns the response as text content.
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 using Zod: requires projectId (number) and endpointId (number).
{ projectId: z.number().describe("Apifox的项目ID"), endpointId: z.number().describe("接口Endpoint的ID"), },