rap2_get_interface_by_id
Retrieve detailed API interface specifications by providing the interface ID to access documentation parameters, endpoints, and requirements.
Instructions
根据接口 ID 获取接口详情
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| interfaceId | Yes | 接口 ID(传入字符串,内部会规范化) |
Implementation Reference
- src/mcp-server.js:212-227 (handler)Handler for rap2_get_interface_by_id tool: validates interfaceId, invokes Rap2Client.getInterfaceById, logs, handles errors, returns JSON response.if (name === 'rap2_get_interface_by_id') { const { interfaceId } = (req.params.arguments || {}); const normalizedId = validateAndNormalizeId('interfaceId', interfaceId); const client = createClient(); const result = await client.getInterfaceById(normalizedId); if (result?.error) { const errorMsg = String(result.error); logger.error({ tool: name, interfaceId: normalizedId, error: errorMsg }, 'tool failed'); throw new Error(`获取接口失败: ${errorMsg}`); } logger.info({ tool: name, interfaceId: normalizedId, resultType: typeof result, hasData: !!result }, 'tool success'); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; }
- src/rap2Client.js:165-171 (helper)Core implementation: HTTP fetch to /interface/get?id=, parses response, returns interface data or error.async getInterfaceById(interfaceId) { const res = await this._fetch(`/interface/get?id=${encodeURIComponent(interfaceId)}`); const ok = res?.data; if (!ok) return { error: '空响应' }; if (ok.errMsg) return { error: ok.errMsg }; return ok.data || ok; }
- src/mcp-server.js:118-128 (registration)Tool registration in tools list: defines name, description, and input schema.{ name: 'rap2_get_interface_by_id', description: '根据接口 ID 获取接口详情', inputSchema: { type: 'object', properties: { interfaceId: { type: 'string', description: '接口 ID(传入字符串,内部会规范化)' }, }, required: ['interfaceId'], }, },
- src/mcp-server.js:121-127 (schema)Input schema definition for the tool.inputSchema: { type: 'object', properties: { interfaceId: { type: 'string', description: '接口 ID(传入字符串,内部会规范化)' }, }, required: ['interfaceId'], },
- src/mcp-server.js:49-78 (helper)Utility function used in handler to validate and normalize interfaceId.function validateAndNormalizeId(paramName, value, allowEmpty = false) { if (value === null || value === undefined) { if (!allowEmpty) { throw new Error(`参数错误: ${paramName} 不能为空`); } return undefined; } let normalized; if (typeof value === 'number') { normalized = String(value); } else if (typeof value === 'string') { if (!value.trim()) { if (!allowEmpty) { throw new Error(`参数错误: ${paramName} 不能是空字符串`); } return undefined; } normalized = value.trim(); } else { throw new Error(`参数错误: ${paramName} 必须是数字或字符串,收到的是 ${typeof value}`); } // 验证ID格式 if (normalized && !/^\d+$/.test(normalized)) { throw new Error(`参数错误: ${paramName} 必须是有效的数字字符串,收到的是 "${normalized}"`); } return normalized; }