From 4386beea6601225660cff280664f1416f208db2f Mon Sep 17 00:00:00 2001 From: zhangguoyun Date: Tue, 2 Dec 2025 16:53:17 +0800 Subject: [PATCH] =?UTF-8?q?feat(apifox):=20=E4=B8=BA=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=96=B9=E6=B3=95=E6=B7=BB=E5=8A=A0projectId?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 允许在查询接口详情时指定项目ID,提高多项目环境下的灵活性 --- apifox.js | 10 ++++++++-- index.js | 10 ++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/apifox.js b/apifox.js index bced919..693a152 100644 --- a/apifox.js +++ b/apifox.js @@ -276,7 +276,10 @@ export class ApifoxService { }; } - async getApiDetailByPath(path) { + async getApiDetailByPath(path, projectId) { + if (projectId) { + this.projectId = projectId; + } const apiDetails = await this.getApiDetails(); const apiDetail = apiDetails.find((item) => item.path === path); if (!apiDetail) { @@ -285,7 +288,10 @@ export class ApifoxService { return this.getApiDetailResp(apiDetail); } - async getApiDetailsById(apiId) { + async getApiDetailsById(apiId, projectId) { + if (projectId) { + this.projectId = projectId; + } const apiDetails = await this.getApiDetails(); const apiDetail = apiDetails.find((item) => item.id === apiId); if (!apiDetail) { diff --git a/index.js b/index.js index b4badf5..5d6b0bb 100644 --- a/index.js +++ b/index.js @@ -32,13 +32,14 @@ server.registerTool( description: "根据接口path获取Apifox接口定义数据", inputSchema: z.object({ path: z.string().describe("接口路径"), + projectId: z.number().optional().describe("Apifox项目ID"), }), }, - async ({ path }) => { + async ({ path, projectId }) => { try { - const apiData = await apifoxService.getApiDetailByPath(path); + const apiData = await apifoxService.getApiDetailByPath(path, projectId); return { content: [ @@ -68,13 +69,14 @@ server.registerTool( description: "根据接口目录获取Apifox目录下所有接口定义数据", inputSchema: z.object({ folderName: z.string().describe("接口路径"), + projectId: z.number().optional().describe("Apifox项目ID"), }), }, - async ({ folderName }) => { + async ({ folderName, projectId }) => { try { - const apiData = await apifoxService.getApiListByFolderName(folderName); + const apiData = await apifoxService.getApiListByFolderName(folderName, projectId); return { content: [