csb_read_card_index
Access cached Oracle ID to CSB ID mappings for Magic: The Gathering cards to enable efficient card data retrieval and cross-referencing.
Instructions
Read oracleId→CSB id index from local cache.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp-server.ts:529-535 (handler)Inline async handler function that computes the cache path, reads the CSB card index using readCsbIndex helper, computes the size, and returns structured content or error message.async () => { const cachePath = process.env.CSB_CARD_INDEX_PATH || require('node:path').join(process.cwd(), 'cache', 'csb-card-index.json'); const disk = await readCsbIndex(cachePath); if (!disk) return { content: [{ type: "text", text: "No CSB card index cache found" }] } as any; const size = Object.keys(disk.data.oracleToId || {}).length; return { structuredContent: { path: cachePath, total: disk.data.total, size, cachedAtMs: disk.at } } as any; }
- src/mcp-server.ts:516-521 (schema)Output schema (zod) for the csb_read_card_index tool response.const csbReadIndexOutput = { path: z.string(), total: z.number().int().nonnegative(), size: z.number().int().nonnegative(), cachedAtMs: z.number() } as const;
- src/mcp-server.ts:522-536 (registration)Registration of the csb_read_card_index tool using server.registerTool, specifying title, description, outputSchema, and inline handler.server.registerTool( "csb_read_card_index", { title: "CSB: Read card index", description: "Read oracleId→CSB id index from local cache.", outputSchema: csbReadIndexOutput }, async () => { const cachePath = process.env.CSB_CARD_INDEX_PATH || require('node:path').join(process.cwd(), 'cache', 'csb-card-index.json'); const disk = await readCsbIndex(cachePath); if (!disk) return { content: [{ type: "text", text: "No CSB card index cache found" }] } as any; const size = Object.keys(disk.data.oracleToId || {}).length; return { structuredContent: { path: cachePath, total: disk.data.total, size, cachedAtMs: disk.at } } as any; } );
- src/csb-index.ts:20-28 (helper)Helper function readCsbIndex that reads and parses the CSB card index JSON file from disk, returning data and modification time or null if failed.export async function readCsbIndex(cachePath = DEFAULT_CACHE_PATH): Promise<{ data: CsbCardIndex; at: number } | null> { try { const [buf, st] = await Promise.all([readFile(cachePath, "utf8"), stat(cachePath)]); const data = JSON.parse(buf) as CsbCardIndex; return { data, at: st.mtimeMs }; } catch { return null; } }
- src/csb-index.ts:5-9 (schema)Type definition for CsbCardIndex used in the tool's output and helpers.export type CsbCardIndex = { builtAtMs: number; total: number; oracleToId: Record<string, number>; };