get_file_details
Retrieve detailed information about a specific file in the OSRS data directory using the filename. Designed for accessing game data definitions via the OSRS MCP Server.
Instructions
Get details about a file in the data directory.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filename | Yes | The filename to get details for in the data directory |
Implementation Reference
- index.ts:190-211 (handler)The main handler function that executes the get_file_details tool logic, retrieving file existence, size, line count, and timestamps from the data directory.async function getFileDetails(filename: string): Promise<any> { try { const filePath = path.join(getDataDir(), filename); if (!fs.existsSync(filePath)) { return { exists: false }; } const stats = await fs.promises.stat(filePath); const lineCount = await getFileLineCount(filePath); return { exists: true, size: stats.size, lineCount, created: stats.birthtime, lastModified: stats.mtime }; } catch (error) { console.error(`Error getting file details for ${filename}:`, error); return { exists: false, error: 'Error getting file details' }; } }
- index.ts:65-67 (schema)Zod schema defining the input validation for the get_file_details tool (filename parameter).const FileDetailsSchema = z.object({ filename: z.string().describe("The filename to get details for in the data directory") });
- index.ts:370-372 (registration)Tool registration in the getToolDefinitions() function, listing get_file_details as an available tool.name: "get_file_details", description: "Get details about a file in the data directory.", },
- index.ts:473-483 (registration)Registration and dispatching logic in the main CallToolRequestSchema handler switch, validating arguments and invoking the getFileDetails handler.case "get_file_details": const detailsArgs = getSchemaForTool(name).parse(args) as { filename: string }; const { filename: detailsFilename } = detailsArgs; // Security check to prevent directory traversal if (detailsFilename.includes('..') || detailsFilename.includes('/') || detailsFilename.includes('\\')) { throw new Error('Invalid filename'); } const details = await getFileDetails(detailsFilename); return responseToString(details);
- index.ts:218-232 (helper)Helper function used by getFileDetails to count the number of lines in a file efficiently using streams.async function getFileLineCount(filePath: string): Promise<number> { return new Promise((resolve, reject) => { let lineCount = 0; const stream = fs.createReadStream(filePath); stream.on('data', (chunk) => { for (let i = 0; i < chunk.length; i++) { if (chunk[i] === 10) { // ASCII code for newline lineCount++; } } }); stream.on('end', () => resolve(lineCount)); stream.on('error', reject); }); }