Skip to main content
Glama
WaterSippin

OSRS MCP Server

Official
by WaterSippin

search_data_file

Locate specific entries in OSRS game data files by searching within a specified file and query term, with pagination support for efficient results navigation.

Instructions

Search any file in the data directory for matching entries.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYesThe filename to search in the data directory (e.g., 'varptypes.txt')
pageNoPage number for pagination
pageSizeNoNumber of results per page
queryYesThe term to search for in the file

Implementation Reference

  • Main handler for the 'search_data_file' tool. Validates input arguments, performs security checks on the filename to prevent path traversal, checks if the file exists, constructs the file path, and invokes the searchFile helper to perform the actual search, then returns the paginated results.
    case "search_data_file":
        const genericSearchArgs = getSchemaForTool(name).parse(args) as { filename: string; query: string; page?: number; pageSize?: number };
        const { filename: genericFilename, query: searchQuery, page: genericFilePage = 1, pageSize: genericFilePageSize = 10 } = genericSearchArgs;
        
        // Security check to prevent directory traversal
        if (genericFilename.includes('..') || genericFilename.includes('/') || genericFilename.includes('\\')) {
            throw new Error('Invalid filename');
        }
        
        if (!fileExists(genericFilename)) {
            return responseToString({ error: `${genericFilename} not found in data directory` });
        }
        
        const genericFilePath = path.join(getDataDir(), genericFilename);
        const genericFileResults = await searchFile(genericFilePath, searchQuery, genericFilePage, genericFilePageSize);
        return responseToString(genericFileResults);
  • Zod schema defining the input parameters for the 'search_data_file' tool: filename (required), query (required), page (optional, default 1), pageSize (optional, default 10).
    const GenericFileSearchSchema = z.object({
        filename: z.string().describe("The filename to search in the data directory (e.g., 'varptypes.txt')"),
        query: z.string().describe("The term to search for in the file"),
        page: z.number().int().min(1).optional().default(1).describe("Page number for pagination"),
        pageSize: z.number().int().min(1).max(100).optional().default(10).describe("Number of results per page")
    });
  • index.ts:366-368 (registration)
    Tool registration entry in the getToolDefinitions() function, providing the tool name and description for discovery via ListTools.
        name: "search_data_file",
        description: "Search any file in the data directory for matching entries.",
    },
  • Core helper function implementing the file search logic: reads file line-by-line using readline, performs case-insensitive search (converting spaces to underscores in query), collects matching lines with line numbers, applies pagination, formats results as ID-value pairs when possible, and returns structured results with pagination metadata.
    async function searchFile(filePath: string, searchTerm: string, page: number = 1, pageSize: number = 10): Promise<any> {
        //replace spaces with underscores
        searchTerm = searchTerm.replace(" ", "_");
        return new Promise((resolve, reject) => {
            if (!fs.existsSync(filePath)) {
                reject(new Error(`File not found: ${filePath}`));
                return;
            }
    
            const results: {line: string, lineNumber: number}[] = [];
            const fileStream = fs.createReadStream(filePath);
            const rl = readline.createInterface({
                input: fileStream,
                crlfDelay: Infinity
            });
    
            let lineNumber = 0;
            
            rl.on('line', (line) => {
                lineNumber++;
                if (line.toLowerCase().includes(searchTerm.toLowerCase())) {
                    results.push({ line, lineNumber });
                }
            });
    
            rl.on('close', () => {
                const totalResults = results.length;
                const totalPages = Math.ceil(totalResults / pageSize);
                const startIndex = (page - 1) * pageSize;
                const endIndex = startIndex + pageSize;
                const paginatedResults = results.slice(startIndex, endIndex);
    
                // Process the results to extract key-value pairs if possible
                const formattedResults = paginatedResults.map(result => {
                    // Try to format as key-value pair (common for ID data files)
                    const parts = result.line.split(/\s+/);
                    if (parts.length >= 2) {
                        const id = parts[0];
                        const value = parts.slice(1).join(' ');
                        return {
                            ...result,
                            id,
                            value,
                            formatted: `${id}\t${value}`
                        };
                    }
                    return result;
                });
    
                resolve({
                    results: formattedResults,
                    pagination: {
                        page,
                        pageSize,
                        totalResults,
                        totalPages,
                        hasNextPage: page < totalPages,
                        hasPreviousPage: page > 1
                    }
                });
            });
    
            rl.on('error', (err) => {
                reject(err);
            });
        });
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions searching 'any file' but doesn't specify what 'matching entries' means (e.g., line-by-line text search, structured data lookup), whether there are rate limits, authentication requirements, or what the output format looks like. This is inadequate for a search tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, with every word contributing to understanding the core functionality.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a search operation with 4 parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what constitutes a 'matching entry', the search scope (e.g., case-sensitive, partial matches), or the result format, leaving significant gaps for the agent to operate effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all four parameters (filename, query, page, pageSize). The description adds no additional parameter semantics beyond implying a search operation, which is already clear from the tool name. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Search') and target ('any file in the data directory for matching entries'), providing a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'search_varptypes' or 'list_data_files', which appear to be more specialized searches, so it falls short of a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like the various 'search_*types' siblings or 'list_data_files'. It lacks explicit when/when-not instructions or named alternatives, leaving the agent to infer usage from context alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.