get_api_reference
Retrieve API reference documentation for Renesas FSP functions and structures by specifying module and function name.
Instructions
Get API reference documentation for FSP functions and structures
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| module | No | Module name (e.g., 'FspLib', 'Spi', 'I2c') | |
| function | No | Specific function name |
Implementation Reference
- src/handlers/api-reference.ts:1-113 (handler)The apiReferenceHandler async function that implements the 'get_api_reference' tool logic. It loads module data from a JSON file, checks if the requested module is known, and returns static API reference documentation for FSP modules (currently supports 'FspLib' and 'r_sci_b_uart').
/** * API Reference Handler * Provides API documentation for FSP functions and structures */ import * as fs from 'fs'; import * as path from 'path'; // Load module list const modulesPath = path.join(process.cwd(), 'src', 'fsp-modules.json'); let moduleList: any = { modules: [], api_base_url: '', src_base_url: '', instances_base_url: '' }; try { const data = fs.readFileSync(modulesPath, 'utf8'); moduleList = JSON.parse(data); } catch (e) { // ignore } export const apiReferenceHandler = async (args?: any) => { const module = args?.module || 'FspLib'; const function_name = args?.function || ''; const isKnown = (moduleList.modules as string[]).map(m => m.toLowerCase()).includes(module.toLowerCase()); const apiUrl = `${moduleList.api_base_url}/${module.toLowerCase()}.h`; const srcUrl = `${moduleList.src_base_url}/${module.toLowerCase()}`; const instancesUrl = `${moduleList.instances_base_url}/${module.toLowerCase()}.h`; if (!isKnown && module !== 'FspLib') { return { content: [ { type: "text", text: ` ================================================================================ FSP API REFERENCE - ${module.toUpperCase()} ================================================================================ Module "${module}" is not recognized in the current FSP API reference dataset. Known modules: ${moduleList.modules.join(', ')} Please check the official Renesas FSP resources: • API header: ${apiUrl} • Source code: ${srcUrl} • Instance header: ${instancesUrl} • Documentation: https://renesas.github.io/fsp/modules.html; ================================================================================ ` } ] }; } // For known modules, provide static info (could be expanded to fetch from repo) const staticModules: Record<string, any> = { 'FspLib': { description: 'Core FSP Library - Main initialization and control functions', functions: [ { name: 'FspLib_Init', return_type: 'void', parameters: [{ name: 'config_ptr', type: 'const fsp_config_t*', description: 'Pointer to configuration structure' }], description: 'Initialize FSP services and hardware components' }, { name: 'FspLib_Exit', return_type: 'void', parameters: [{ name: 'status', type: 'uint32_t', description: 'Exit status code' }], description: 'Exit FSP and transfer control to bootloader or application' }, { name: 'FspLib_GetVersion', return_type: 'const char*', parameters: [], description: 'Get current FSP version string' } ] }, 'r_sci_b_uart': { description: 'SCI UART Driver - UART communication via SCI peripheral', functions: [ { name: 'R_SCI_B_UART_Open', return_type: 'fsp_err_t', parameters: [{ name: 'p_api_ctrl', type: 'sci_b_uart_ctrl_t *', description: 'Control structure' }, { name: 'p_cfg', type: 'sci_b_uart_cfg_t const *', description: 'Configuration' }], description: 'Open UART channel' }, { name: 'R_SCI_B_UART_Write', return_type: 'fsp_err_t', parameters: [{ name: 'p_api_ctrl', type: 'sci_b_uart_ctrl_t *' }, { name: 'p_src', type: 'uint8_t const *' }, { name: 'bytes', type: 'uint32_t' }], description: 'Write data to UART' } ] } }; const module_info = staticModules[module] || staticModules['FspLib']; return { content: [ { type: "text", text: ` ================================================================================ FSP API REFERENCE - ${module.toUpperCase()} ================================================================================ MODULE: ${module.toUpperCase()} DESCRIPTION: ${module_info.description} -------------------------------------------------------------------------------- FUNCTIONS (examples): -------------------------------------------------------------------------------- ${module_info.functions.map((f: any) => ` 📄 ${f.name}() Return Type: ${f.return_type} Description: ${f.description} Parameters: ` + f.parameters.map((p: any) => ` • ${p.type} ${p.name} - ${p.description}`).join('\n') ).join('')} -------------------------------------------------------------------------------- OFFICIAL RENESAS FSP RESOURCES: -------------------------------------------------------------------------------- • API header: ${apiUrl} • Source code: ${srcUrl} • Instance header: ${instancesUrl} • Documentation: https://renesas.github.io/fsp/group___${module.toUpperCase()}.html ================================================================================ ` } ] }; }; - src/index.ts:14-14 (registration)Import of apiReferenceHandler from the api-reference handler module.
import { apiReferenceHandler } from "./handlers/api-reference.js"; - src/index.ts:89-104 (schema)Input schema definition for the 'get_api_reference' tool, defining 'module' and 'function' as string input properties.
name: "get_api_reference", description: "Get API reference documentation for FSP functions and structures", inputSchema: { type: "object", properties: { module: { type: "string", description: "Module name (e.g., 'FspLib', 'Spi', 'I2c')" }, function: { type: "string", description: "Specific function name" } } } }, - src/index.ts:161-162 (registration)The case statement in the CallToolRequestSchema handler that routes 'get_api_reference' calls to apiReferenceHandler(args).
case "get_api_reference": return await apiReferenceHandler(args);