Skip to main content
Glama
WaterSippin

OSRS MCP Server

Official
by WaterSippin

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
NameRequiredDescriptionDefault
filenameYesThe filename to get details for in the data directory

Implementation Reference

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

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/WaterSippin/mcp-osrs'

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