search_spottypes
Identify spot animation definitions by searching the spottypes.txt file with specific queries, enabling precise access to graphical effect data in Old School RuneScape.
Instructions
Search the spottypes.txt file for spot animation (graphical effect) definitions.
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:384-406 (handler)Shared handler logic for all search_* tools including search_spottypes: validates input using FileSearchSchema, derives filename from tool name (spottypes.txt), checks file existence, performs search via searchFile helper, and returns paginated results.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 { query, page: filePage = 1, pageSize: filePageSize = 10 } = FileSearchSchema.parse(args); const filename = `${name.replace('search_', '')}.txt`; const filePath = path.join(DATA_DIR, 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:49-53 (schema)Zod schema for input validation of search_spottypes and other file search tools: defines query string, optional page and pageSize for pagination.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:308-312 (registration)Tool registration in ListTools response: defines name, description, and references FileSearchSchema for search_spottypes.{ name: "search_spottypes", description: "Search the spottypes.txt file for spot animation (graphical effect) definitions.", inputSchema: convertZodToJsonSchema(FileSearchSchema), },
- index.ts:99-165 (helper)Core helper function implementing file search logic: streams file lines, matches query case-insensitively (after replacing spaces with underscores in query), formats ID-value pairs, applies pagination, returns structured results.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); }); }); }