Skip to main content
Glama
latte-chan
by latte-chan

csb_build_card_index

Rebuilds the card index mapping for the Scryfall MCP server to maintain accurate card data retrieval and search functionality.

Instructions

Rebuild oracleId→CSB id index and write cache.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function registered for 'csb_build_card_index', which builds the index using buildCsbIndex and writes it using writeCsbIndex.
    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 definition for the tool.
    const csbBuildIndexOutput = {
        path: z.string(),
        total: z.number().int().nonnegative(),
        size: z.number().int().nonnegative(),
        builtAtMs: z.number()
    } as const;
  • Registration of the 'csb_build_card_index' tool with MCP server.
    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 helper function that paginates through all CSB cards and builds the oracleId to CSB ID mapping.
    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 };
    }
  • Helper function to write the built index to cache file.
    export async function writeCsbIndex(data: CsbCardIndex, cachePath = DEFAULT_CACHE_PATH): Promise<string> {
        await ensureDirFor(cachePath);
        await writeFile(cachePath, JSON.stringify(data, null, 2), "utf8");
        return cachePath;
    }

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