get_glossary
Look up Magic: The Gathering glossary terms. Use to define game-specific words like 'permanent' or 'spell' with partial matching support.
Instructions
Look up a term in the Magic: The Gathering glossary. Use this when a user asks "what does X mean" for game-specific terminology like "permanent", "spell", "stack", "priority", etc. Supports partial matching.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| term | Yes | Glossary term to look up (case-insensitive). Supports exact and partial matching. |
Implementation Reference
- src/tools/get-glossary.ts:30-59 (handler)Main handler function that queries the SQLite database for glossary terms, first by exact match (case-insensitive), then by partial match, returning entries or a 'not found' message.
export function handler(db: Database.Database, params: GetGlossaryParams): GetGlossaryResult { // 1. Exact match (case-insensitive) const exact = db.prepare( 'SELECT * FROM glossary WHERE LOWER(term) = LOWER(?)' ).get(params.term) as GlossaryRow | undefined; if (exact) { return { found: true, entries: [{ term: exact.term, definition: exact.definition }], }; } // 2. Partial match (case-insensitive) const partials = db.prepare( 'SELECT * FROM glossary WHERE LOWER(term) LIKE LOWER(?) ORDER BY term LIMIT 20' ).all(`%${params.term}%`) as GlossaryRow[]; if (partials.length > 0) { return { found: true, entries: partials.map(row => ({ term: row.term, definition: row.definition })), }; } return { found: false, message: `No glossary entry found for "${params.term}"`, }; } - src/tools/get-glossary.ts:7-9 (schema)Zod input schema for 'get_glossary': accepts a 'term' string for case-insensitive exact/partial matching.
export const GetGlossaryInput = z.object({ term: z.string().describe('Glossary term to look up (case-insensitive). Supports exact and partial matching.'), }); - src/tools/get-glossary.ts:15-26 (schema)Output types: GlossaryEntry interface and GetGlossaryResult discriminated union (found/not found).
export interface GlossaryEntry { term: string; definition: string; } export type GetGlossaryResult = { found: true; entries: GlossaryEntry[]; } | { found: false; message: string; }; - src/server.ts:165-177 (registration)Registration of the 'get_glossary' tool on the MCP server with its description, input schema, and handler invocation.
server.tool( 'get_glossary', 'Look up a term in the Magic: The Gathering glossary. Use this when a user asks "what does X mean" for game-specific terminology like "permanent", "spell", "stack", "priority", etc. Supports partial matching.', GetGlossaryInput.shape, async (params) => { try { const result = getGlossaryHandler(db, params); return { content: [{ type: 'text' as const, text: formatGetGlossary(result) }] }; } catch (err) { return { content: [{ type: 'text' as const, text: `Error getting glossary entry: ${err instanceof Error ? err.message : String(err)}` }], isError: true }; } }, ); - src/format.ts:252-263 (helper)Formatting helper that converts the GetGlossaryResult into a human-readable string.
export function formatGetGlossary(result: GetGlossaryResult): string { if (!result.found) { return result.message; } const lines: string[] = []; for (const entry of result.entries) { lines.push(`**${entry.term}**: ${entry.definition}`); } return lines.join('\n\n'); }