search_spritetypes
Search sprite image definitions in the spritetypes.txt file for OSRS interface design. Input a query, page number, and page size to retrieve specific sprite data efficiently.
Instructions
Search the spritetypes.txt file for sprite image definitions used in the interface.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page | No | Page number for pagination | |
| pageSize | No | Number of results per page | |
| query | Yes | The term to search for in the file |
Input Schema (JSON Schema)
{
"additionalProperties": false,
"properties": {
"page": {
"default": 1,
"description": "Page number for pagination",
"minimum": 1,
"type": "integer"
},
"pageSize": {
"default": 10,
"description": "Number of results per page",
"maximum": 100,
"minimum": 1,
"type": "integer"
},
"query": {
"description": "The term to search for in the file",
"type": "string"
}
},
"required": [
"query"
],
"type": "object"
}
Implementation Reference
- index.ts:444-455 (handler)Handler code executed when 'search_spritetypes' is called. Parses input arguments, determines the spritetypes.txt file path, checks if file exists, searches the file using the shared searchFile helper, and returns paginated results.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:52-56 (schema)Zod schema definition used for input validation of search_spritetypes tool (shared with other search_* tools). Defines query, pagination parameters.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") });
- index.ts:291-295 (schema)Logic in getSchemaForTool function that selects FileSearchSchema for any tool name starting with 'search_', including search_spritetypes.if (toolName.startsWith("search_")) { return FileSearchSchema; } throw new Error(`Unknown tool: ${toolName}`); }
- index.ts:358-360 (registration)Tool registration/declaration in getToolDefinitions() array, providing name and description returned by listTools.name: "search_spritetypes", description: "Search the spritetypes.txt file for sprite image definitions used in the interface.", },
- index.ts:102-168 (helper)Core helper function that performs the actual file search: reads lines, matches query (case-insensitive, spaces to underscores), paginates results, formats as ID-value pairs, returns structured results with pagination info. Called by all search_* handlers including search_spritetypes.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); }); }); }