list_roms
Retrieve a list of all available GameBoy ROM files to access and manage game data for use with the MCP GameBoy Server toolset.
Instructions
List all available GameBoy ROM files
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools.ts:110-152 (handler)Handler function for the 'list_roms' tool. Lists GameBoy ROM files (.gb and .gbc) from the 'roms' directory (creating it if necessary), constructs an array of objects with 'name' and 'path', returns as JSON-formatted TextContent, or error details if failed.async (): Promise<CallToolResult> => { try { const romsDir = path.join(process.cwd(), 'roms'); // Create roms directory if it doesn't exist if (!fs.existsSync(romsDir)) { fs.mkdirSync(romsDir); log.info('Created roms directory'); } // Get list of ROM files const romFiles = fs.readdirSync(romsDir) .filter(file => file.endsWith('.gb') || file.endsWith('.gbc')) .map(file => ({ name: file, path: path.join(romsDir, file) })); const responseText: TextContent = { type: 'text', text: JSON.stringify(romFiles) }; log.verbose('Listed available ROMs', JSON.stringify({ count: romFiles.length, roms: romFiles })); return { content: [responseText] }; } catch (error) { log.error('Error listing ROMs:', error instanceof Error ? error.message : String(error)); const errorText: TextContent = { type: 'text', text: JSON.stringify({ error: 'Failed to list ROMs', message: error instanceof Error ? error.message : String(error) }) }; return { content: [errorText] }; } }
- src/tools.ts:106-153 (registration)Registers the 'list_roms' tool with the MCP server using server.tool(), providing description 'List all available GameBoy ROM files' and empty input schema {}.server.tool( 'list_roms', 'List all available GameBoy ROM files', {}, async (): Promise<CallToolResult> => { try { const romsDir = path.join(process.cwd(), 'roms'); // Create roms directory if it doesn't exist if (!fs.existsSync(romsDir)) { fs.mkdirSync(romsDir); log.info('Created roms directory'); } // Get list of ROM files const romFiles = fs.readdirSync(romsDir) .filter(file => file.endsWith('.gb') || file.endsWith('.gbc')) .map(file => ({ name: file, path: path.join(romsDir, file) })); const responseText: TextContent = { type: 'text', text: JSON.stringify(romFiles) }; log.verbose('Listed available ROMs', JSON.stringify({ count: romFiles.length, roms: romFiles })); return { content: [responseText] }; } catch (error) { log.error('Error listing ROMs:', error instanceof Error ? error.message : String(error)); const errorText: TextContent = { type: 'text', text: JSON.stringify({ error: 'Failed to list ROMs', message: error instanceof Error ? error.message : String(error) }) }; return { content: [errorText] }; } } );