Skip to main content
Glama

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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; }
  • 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;
  • 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; } );
  • 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 }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/latte-chan/scryfall-connector'

If you have feedback or need assistance with the MCP directory API, please join our Discord server