yapi_get_project
Retrieve YApi project details including name, description, and member information using the project ID to access API documentation platform data.
Instructions
获取YApi项目的基本信息,包括项目名称、描述、成员等
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | YApi项目ID | |
| token | No | 访问令牌(可选) |
Implementation Reference
- src/index.ts:504-530 (handler)Handler function for the yapi_get_project tool. Fetches project information using YApiClient.getProjectInfo and returns it as formatted JSON text content or error message.async (args: { project_id: string; token?: string }) => { try { const projectInfo = await yapiClient.getProjectInfo( args.project_id, args.token ); return { content: [ { type: 'text', text: JSON.stringify(projectInfo, null, 2), }, ], }; } catch (error) { return { content: [ { type: 'text', text: `错误: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }
- src/index.ts:497-502 (schema)Input schema definition for yapi_get_project tool using Zod validation for required project_id and optional token.{ description: '获取YApi项目的基本信息,包括项目名称、描述、成员等', inputSchema: { project_id: z.string().describe('YApi项目ID'), token: z.string().optional().describe('访问令牌(可选)'), },
- src/index.ts:495-531 (registration)Registration of the yapi_get_project tool on the MCP server, including name, description, input schema, and handler function.server.registerTool( 'yapi_get_project', { description: '获取YApi项目的基本信息,包括项目名称、描述、成员等', inputSchema: { project_id: z.string().describe('YApi项目ID'), token: z.string().optional().describe('访问令牌(可选)'), }, }, async (args: { project_id: string; token?: string }) => { try { const projectInfo = await yapiClient.getProjectInfo( args.project_id, args.token ); return { content: [ { type: 'text', text: JSON.stringify(projectInfo, null, 2), }, ], }; } catch (error) { return { content: [ { type: 'text', text: `错误: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } } );
- src/index.ts:75-95 (helper)YApiClient helper method that makes the HTTP GET request to YApi's /api/project/get endpoint to retrieve project information.async getProjectInfo(projectId: string, token?: string): Promise<any> { try { const params: any = { id: projectId }; // 优先使用传入的 token,其次使用实例的 token const finalToken = token || this.token; if (finalToken) { params.token = finalToken; } const response = await this.client.get('/api/project/get', { params }); if (response.data.errcode !== 0) { throw new Error(response.data.errmsg || '获取项目信息失败'); } return response.data.data; } catch (error) { this.handleError(error, '获取项目信息失败'); } }