Skip to main content
Glama

csb_read_card_index

Retrieve the mapping between Oracle IDs and CSB IDs from local cache to enable efficient card data lookups in Magic: The Gathering applications.

Instructions

Read oracleId→CSB id index from local cache.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Inline handler function for csb_read_card_index tool: computes cache path, reads index using readCsbIndex helper, computes size, returns structured content with path/total/size/cachedAtMs or text error if not found.
    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; }
  • Output schema definition for csb_read_card_index tool using zod schemas.
    const csbReadIndexOutput = { path: z.string(), total: z.number().int().nonnegative(), size: z.number().int().nonnegative(), cachedAtMs: z.number() } as const;
  • Registers the csb_read_card_index tool on the MCP server with title, description, output schema, and 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; } );
  • Helper function readCsbIndex reads the JSON cache file, parses it as CsbCardIndex, returns data with mtimeMs or null on error.
    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; } }

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