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

csb_parse_deck_text

Parse plain-text decklists into Magic: The Gathering cards using Commander Spellbook to identify cards from text entries.

Instructions

Parse a plain-text decklist into cards using Commander Spellbook.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesPlain-text deck list, e.g. '1x Sol Ring' per line

Implementation Reference

  • The main handler function for the csb_parse_deck_text tool, which calls CSB.parseCardListFromText to parse the deck text and returns structured content.
    async ({ text }: { text: string }) => {
        const res = (await CSB.parseCardListFromText(text)) as any;
        return { structuredContent: res } as any;
    }
  • Input schema (deck text string) and output schema (arrays of cards with quantities for main and optional commanders).
    const csbParseDeckInput = {
        text: z.string().min(1).describe("Plain-text deck list, e.g. '1x Sol Ring' per line")
    } as const;
    const csbParseDeckOutput = {
        main: z.array(z.object({ card: z.string(), quantity: z.number().int().positive() })),
        commanders: z.array(z.object({ card: z.string(), quantity: z.number().int().positive() })).optional()
    } as const;
  • Registers the csb_parse_deck_text tool in the MCP server with schema, description, and handler function.
    server.registerTool(
        "csb_parse_deck_text",
        {
            title: "CSB: Parse deck text",
            description: "Parse a plain-text decklist into cards using Commander Spellbook.",
            inputSchema: csbParseDeckInput,
            outputSchema: csbParseDeckOutput
        },
        async ({ text }: { text: string }) => {
            const res = (await CSB.parseCardListFromText(text)) as any;
            return { structuredContent: res } as any;
        }
    );
  • CSB client method that performs POST request to CSB API endpoint /card-list-from-text with the deck text.
    parseCardListFromText: (text: string) => postText("/card-list-from-text", text),
  • Helper function postText used by CSB methods to send POST requests to CSB API with rate limiting and retries.
    async function postText(path: string, body: string) {
        const base = process.env.CSB_BASE_URL || DEFAULT_BASE_URL;
        const url = new URL(path, base);
    
        const maxRetries = Number(process.env.CSB_MAX_RETRIES || 3);
        const retryBaseMs = Number(process.env.CSB_RETRY_BASE_MS || 250);
    
        for (let attempt = 0; attempt <= maxRetries; attempt++) {
            await acquireSlot();
            const res = await fetch(url, {
                method: "POST",
                headers: {
                    "Content-Type": "text/plain",
                    "User-Agent": "scryfall-mcp/0.1 (commanderspellbook client)"
                },
                body
            });
    
            if (res.status === 429) {
                const retryAfter = Number(res.headers.get("Retry-After") || 0);
                const backoff = retryAfter > 0 ? retryAfter * 1000 : retryBaseMs * Math.pow(2, attempt);
                if (attempt < maxRetries) {
                    await sleep(backoff);
                    continue;
                }
            }
    
            if (!res.ok) {
                const text = await res.text().catch(() => "");
                throw new Error(`CSB request failed: ${res.status} ${res.statusText} - ${text}`);
            }
    
            return res.json() as Promise<unknown>;
        }
    
        throw new Error("CSB request failed after retries");
    }

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