csb_build_card_index
Rebuilds the card index mapping oracle IDs to CSB IDs and updates the cache to ensure accurate card data retrieval for Magic: The Gathering searches.
Instructions
Rebuild oracleId→CSB id index and write cache.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp-server.ts:508-512 (handler)The tool handler: invokes buildCsbIndex to generate index, writes cache, returns results.async () => { const data = await buildCsbIndex(); const path = await writeCsbIndex(data); return { structuredContent: { path, total: data.total, size: Object.keys(data.oracleToId).length, builtAtMs: data.builtAtMs } } as any; }
- src/mcp-server.ts:495-500 (schema)Output schema (Zod) for the tool response.const csbBuildIndexOutput = { path: z.string(), total: z.number().int().nonnegative(), size: z.number().int().nonnegative(), builtAtMs: z.number() } as const;
- src/mcp-server.ts:501-513 (registration)Tool registration in MCP server, including name, description, schema ref, and handler.server.registerTool( "csb_build_card_index", { title: "CSB: Build card index", description: "Rebuild oracleId→CSB id index and write cache.", outputSchema: csbBuildIndexOutput }, async () => { const data = await buildCsbIndex(); const path = await writeCsbIndex(data); return { structuredContent: { path, total: data.total, size: Object.keys(data.oracleToId).length, builtAtMs: data.builtAtMs } } as any; } );
- src/csb-index.ts:36-56 (helper)Core implementation: paginates CSB.cards API to build oracleId to CSB ID mapping index.export async function buildCsbIndex(): Promise<CsbCardIndex> { const oracleToId: Record<string, number> = Object.create(null); const limit = 100; let offset = 0; let total = 0; while (true) { const page: any = await CSB.cards({ limit, offset }); const results: any[] = Array.isArray(page?.results) ? page.results : []; total = Number(page?.count ?? total); for (const c of results) { const oid = c?.oracleId; const id = c?.id; if (typeof oid === "string" && typeof id === "number") { if (!(oid in oracleToId)) oracleToId[oid] = id; } } if (!page?.next || results.length === 0) break; offset += limit; } return { builtAtMs: Date.now(), total, oracleToId }; }