rap2_search_interfaces_by_keyword
Search API interfaces in RAP2 repositories using keywords to find relevant documentation and endpoints quickly.
Instructions
按关键字搜索接口(可选限定仓库)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| keyword | Yes | 搜索关键字 | |
| repositoryId | No | 仓库 ID(可选,传入字符串) |
Implementation Reference
- src/rap2Client.js:183-190 (handler)Core tool handler: Constructs query parameters for keyword (required) and optional repositoryId, performs HTTP GET to RAP2 /interface/search endpoint via _fetch, extracts and returns data array or propagates error.async searchInterfacesByKeyword(keyword, repositoryId) { const params = new URLSearchParams({ keyword: String(keyword || '') }); if (repositoryId) params.set('repositoryId', String(repositoryId)); const res = await this._fetch(`/interface/search?${params.toString()}`); const body = res?.data || {}; if (body.errMsg) return { error: body.errMsg }; return body.data || []; }
- src/mcp-server.js:244-260 (handler)MCP CallToolRequest handler dispatch for this tool: Extracts and normalizes arguments using custom validators, creates Rap2Client instance, invokes core search method, logs, handles errors by throwing, returns JSON-formatted result as text content.if (name === 'rap2_search_interfaces_by_keyword') { const { keyword, repositoryId } = (req.params.arguments || {}); const normalizedKeyword = validateAndNormalizeKeyword(keyword); const normalizedRepoId = validateAndNormalizeId('repositoryId', repositoryId, true); // 允许为空 const client = createClient(); const result = await client.searchInterfacesByKeyword(normalizedKeyword, normalizedRepoId); if (result?.error) { const errorMsg = String(result.error); logger.error({ tool: name, keyword: normalizedKeyword, repositoryId: normalizedRepoId, error: errorMsg }, 'tool failed'); throw new Error(`搜索接口失败: ${errorMsg}`); } logger.info({ tool: name, keyword: normalizedKeyword, repositoryId: normalizedRepoId, resultCount: Array.isArray(result) ? result.length : 0 }, 'tool success'); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
- src/mcp-server.js:143-150 (schema)Input schema defining the tool parameters: required 'keyword' string for search term, optional 'repositoryId' string to limit to a repository.inputSchema: { type: 'object', properties: { keyword: { type: 'string', description: '搜索关键字' }, repositoryId: { type: 'string', description: '仓库 ID(可选,传入字符串)' }, }, required: ['keyword'], },
- src/mcp-server.js:140-151 (registration)Tool definition object registered in the static tools list array, used for server capabilities.tools.list and listTools response.{ name: 'rap2_search_interfaces_by_keyword', description: '按关键字搜索接口(可选限定仓库)', inputSchema: { type: 'object', properties: { keyword: { type: 'string', description: '搜索关键字' }, repositoryId: { type: 'string', description: '仓库 ID(可选,传入字符串)' }, }, required: ['keyword'], }, },
- src/mcp-server.js:80-90 (helper)Helper function specifically for normalizing and validating the 'keyword' input parameter in the tool handler.function validateAndNormalizeKeyword(keyword) { if (!keyword) { throw new Error('参数错误: keyword 不能为空'); } if (typeof keyword === 'string' && !keyword.trim()) { throw new Error('参数错误: keyword 不能是空字符串'); } return typeof keyword === 'string' ? keyword.trim() : String(keyword); }