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: [