search
Search ASCII art and kaomoji by keyword, filter by type, or list categories. Get a random entry with the random option.
Instructions
Search ASCII art and kaomoji. Omit query to list all. Use random for a random entry. Use mode "categories" to list categories.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | No | Search keyword (matches id, name, category, tags). Omit to list all. | |
| type | No | Filter by type: "art", "kaomoji", or "all" | all |
| random | No | Return one random entry | |
| mode | No | Mode: "search" (default) or "categories" to list categories | search |
Implementation Reference
- src/mcp.ts:39-102 (handler)The handler function for the 'search' tool. Handles categories mode, random mode, list-all mode (no query), and search mode. Calls search(query) for ASCII art and searchKaomoji(query) for kaomoji.
async ({ query, type, random, mode }) => { // Categories mode if (mode === 'categories') { const parts: string[] = []; if (type !== 'kaomoji') { parts.push('Art: ' + listCategories().join(', ')); } if (type !== 'art') { parts.push('Kaomoji: ' + listKaomojiCategories().join(', ')); } return { content: [{ type: 'text', text: parts.join('\n') }] }; } // Random mode if (random) { if (type !== 'kaomoji') { const result = await toResult(getRandom()); return { content: [{ type: 'text', text: `--- ${result.name} [${result.size}w ${result.width}x${result.height}] ---\n${result.art}` }] }; } const k = getRandomKaomoji(); return { content: [{ type: 'text', text: `${k.text} — ${k.name} [${k.category}]` }] }; } // List all (no query) if (!query) { const parts: string[] = []; if (type !== 'kaomoji') { const items = listAll().map((e) => { const desc = e.description ? ` — ${e.description}` : ''; return `${e.id} — ${e.name} [${e.category}] (${e.size}w: ${e.width}x${e.height})${desc}`; }); if (items.length > 0) parts.push(items.join('\n')); } if (type !== 'art') { const items = listAllKaomoji().map((k) => `${k.text} — ${k.name} [${k.category}]`); if (items.length > 0) parts.push(items.join('\n')); } return { content: [{ type: 'text', text: parts.join('\n\n') }] }; } // Search mode const parts: string[] = []; if (type !== 'kaomoji') { const results = search(query); const arts = await Promise.all(results.map((e) => toResult(e))); const text = arts.map((a) => { const desc = a.description ? `\n${a.description}` : ''; return `--- ${a.name} (${a.id}) [${a.size}w ${a.width}x${a.height}] ---${desc}\n${a.art}`; }).join('\n\n'); if (text) parts.push(text); } if (type !== 'art') { const kaomoji = searchKaomoji(query); const text = kaomoji.map((k) => `${k.text} — ${k.name} [${k.category}]`).join('\n'); if (text) parts.push(text); } if (parts.length === 0) { return { content: [{ type: 'text', text: `No results found for "${query}"` }] }; } return { content: [{ type: 'text', text: parts.join('\n\n') }] }; } - src/mcp.ts:30-38 (registration)Registration of the 'search' tool via server.tool() with name 'search', description, Zod schema for parameters (query, type, random, mode), and the async handler.
server.tool( 'search', 'Search ASCII art and kaomoji. Omit query to list all. Use random for a random entry. Use mode "categories" to list categories.', { query: z.string().optional().describe('Search keyword (matches id, name, category, tags). Omit to list all.'), type: z.enum(['art', 'kaomoji', 'all']).default('all').describe('Filter by type: "art", "kaomoji", or "all"'), random: z.boolean().default(false).describe('Return one random entry'), mode: z.enum(['search', 'categories']).default('search').describe('Mode: "search" (default) or "categories" to list categories'), }, - src/mcp.ts:33-38 (schema)Zod schema definitions for the 'search' tool parameters: query (optional string), type (enum 'art'|'kaomoji'|'all'), random (boolean), and mode (enum 'search'|'categories').
{ query: z.string().optional().describe('Search keyword (matches id, name, category, tags). Omit to list all.'), type: z.enum(['art', 'kaomoji', 'all']).default('all').describe('Filter by type: "art", "kaomoji", or "all"'), random: z.boolean().default(false).describe('Return one random entry'), mode: z.enum(['search', 'categories']).default('search').describe('Mode: "search" (default) or "categories" to list categories'), }, - src/store.ts:38-40 (helper)The search() function in store.ts that queries ASCII art entries using matchQuery(). Delegates to the generic matchQuery utility with an extra match on description.
export function search(query: string): ArtEntry[] { return matchQuery(entries, query, (e, q) => e.description?.toLowerCase().includes(q) ?? false); } - src/kaomoji.ts:19-21 (helper)The searchKaomoji() function that queries kaomoji entries using matchQuery().
export function searchKaomoji(query: string): KaomojiEntry[] { return matchQuery(entries, query); }