Skip to main content
Glama
WaterSippin

OSRS MCP Server

Official
by WaterSippin

search_npctypes

Search and retrieve NPC definitions from the npctypes.txt file on the OSRS MCP Server. Use a query to find specific characters and manage results with pagination for efficient data access.

Instructions

Search the npctypes.txt file for NPC (non-player character) definitions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pageNoPage number for pagination
pageSizeNoNumber of results per page
queryYesThe term to search for in the file

Implementation Reference

  • Shared handler logic for all search_* tools including search_npctypes. Parses args, determines npctypes.txt filename, checks existence, and calls searchFile function.
    case "search_varptypes":
    case "search_varbittypes":
    case "search_iftypes":
    case "search_invtypes":
    case "search_loctypes":
    case "search_npctypes":
    case "search_objtypes":
    case "search_rowtypes":
    case "search_seqtypes":
    case "search_soundtypes":
    case "search_spottypes":
    case "search_spritetypes":
    case "search_tabletypes":
        const fileSearchArgs = getSchemaForTool(name).parse(args) as { query: string; page?: number; pageSize?: number };
        const { query, page: filePage = 1, pageSize: filePageSize = 10 } = fileSearchArgs;
        const filename = `${name.replace('search_', '')}.txt`;
        const filePath = path.join(getDataDir(), filename);
        
        if (!fileExists(filename)) {
            return responseToString({ error: `${filename} not found in data directory` });
        }
        
        const fileResults = await searchFile(filePath, query, filePage, filePageSize);
        return responseToString(fileResults);
  • index.ts:334-336 (registration)
    Tool registration/definition in getToolDefinitions() function, returned by ListTools handler.
        name: "search_npctypes",
        description: "Search the npctypes.txt file for NPC (non-player character) definitions.",
    },
  • Input schema (FileSearchSchema) used for validating arguments in search_* tools including search_npctypes.
    const FileSearchSchema = z.object({
        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")
    });
  • Core searchFile helper function that reads the npctypes.txt file, searches for query (case-insensitive, spaces to underscores), paginates results, and formats as ID-value pairs.
    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);
            });
        });
    }

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