yapi_search_interface
Search for API interfaces in YApi projects by name or path to quickly find endpoint details and documentation.
Instructions
在YApi项目中搜索接口,支持按接口名称、路径搜索
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | YApi项目ID | |
| keyword | Yes | 搜索关键词 | |
| token | No | 访问令牌(可选) |
Implementation Reference
- src/index.ts:585-613 (handler)The handler function for 'yapi_search_interface' tool. It calls yapiClient.searchInterface with provided arguments and returns the search results as JSON or an error message.async (args: { project_id: string; keyword: string; token?: string }) => { try { const results = await yapiClient.searchInterface( args.project_id, args.keyword, args.token ); return { content: [ { type: 'text', text: JSON.stringify(results, null, 2), }, ], }; } catch (error) { return { content: [ { type: 'text', text: `错误: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } } );
- src/index.ts:577-584 (schema)Input schema definition for the 'yapi_search_interface' tool, including parameters project_id, keyword, and optional token.{ description: '在YApi项目中搜索接口,支持按接口名称、路径搜索', inputSchema: { project_id: z.string().describe('YApi项目ID'), keyword: z.string().describe('搜索关键词'), token: z.string().optional().describe('访问令牌(可选)'), }, },
- src/index.ts:575-613 (registration)Registration of the 'yapi_search_interface' tool using server.registerTool, including schema and handler.server.registerTool( 'yapi_search_interface', { description: '在YApi项目中搜索接口,支持按接口名称、路径搜索', inputSchema: { project_id: z.string().describe('YApi项目ID'), keyword: z.string().describe('搜索关键词'), token: z.string().optional().describe('访问令牌(可选)'), }, }, async (args: { project_id: string; keyword: string; token?: string }) => { try { const results = await yapiClient.searchInterface( args.project_id, args.keyword, args.token ); return { content: [ { type: 'text', text: JSON.stringify(results, null, 2), }, ], }; } catch (error) { return { content: [ { type: 'text', text: `错误: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } } );
- src/index.ts:134-157 (helper)YApiClient.searchInterface helper method that makes the HTTP request to YApi's /api/interface/search endpoint to perform the interface search.async searchInterface(projectId: string, keyword: string, token?: string): Promise<any[]> { try { const params: any = { project_id: projectId, q: keyword, }; // 优先使用传入的 token,其次使用实例的 token const finalToken = token || this.token; if (finalToken) { params.token = finalToken; } const response = await this.client.get('/api/interface/search', { params }); if (response.data.errcode !== 0) { throw new Error(response.data.errmsg || '搜索接口失败'); } return response.data.data || []; } catch (error) { this.handleError(error, '搜索接口失败'); } }