Skip to main content
Glama

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

NameRequiredDescriptionDefault
filenameYesThe 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

  • 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' }; } }
  • 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), },
  • 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);
  • 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; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JayArrowz/mcp-osrs'

If you have feedback or need assistance with the MCP directory API, please join our Discord server