get_file_details
Retrieve detailed information about a specific file within the OSRS MCP Server's data directory by providing the filename, enabling efficient access to game-related data.
Instructions
Get details about a file in the data directory.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filename | Yes | The filename to get details for in the data directory |
Input Schema (JSON Schema)
{
"additionalProperties": false,
"properties": {
"filename": {
"description": "The filename to get details for in the data directory",
"type": "string"
}
},
"required": [
"filename"
],
"type": "object"
}
Implementation Reference
- index.ts:182-203 (handler)The core handler function that implements the logic for the 'get_file_details' tool, retrieving file existence, size, line count, and modification timestamps.function getFileDetails(filename: string): any { try { const filePath = path.join(DATA_DIR, filename); if (!fs.existsSync(filePath)) { return { exists: false }; } const stats = fs.statSync(filePath); const lineCount = 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:62-64 (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:328-332 (registration)Registration of the 'get_file_details' tool in the MCP server's listTools response.{ name: "get_file_details", description: "Get details about a file in the data directory.", inputSchema: convertZodToJsonSchema(FileDetailsSchema), },
- index.ts:424-433 (handler)Dispatch handler in the CallToolRequestSchema that validates input, performs security checks, calls getFileDetails, and formats the response.case "get_file_details": const { filename: detailsFilename } = FileDetailsSchema.parse(args); // Security check to prevent directory traversal if (detailsFilename.includes('..') || detailsFilename.includes('/') || detailsFilename.includes('\\')) { throw new Error('Invalid filename'); } const details = getFileDetails(detailsFilename); return responseToString(details);
- index.ts:210-218 (helper)Helper utility function used by getFileDetails to compute the line count of the file.function getFileLineCount(filePath: string): number { try { const content = fs.readFileSync(filePath, 'utf8'); return content.split('\n').length; } catch (error) { console.error(`Error counting lines in ${filePath}:`, error); return 0; } }