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

search_by_cmc

Search Magic: The Gathering cards by converted mana cost range, with optional filters for color and card type to find specific cards for deck building.

Instructions

Find cards within a mana value range, optionally filtered by color and type.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
minNo
maxNo
colorsNo
typeNo
pageNo

Implementation Reference

  • Executes the tool: builds Scryfall query for mana value (mv>=min mv<=max), optional color>=colors, type:quoted(type), searches, summarizes results into {total, results: CardSummary[]}.
    async ({ min, max, colors = [], type, page }: { min?: number; max?: number; colors?: Array<"W" | "U" | "B" | "R" | "G">; type?: string; page?: number }) => {
        const range = [typeof min === "number" ? `mv>=${min}` : undefined, typeof max === "number" ? `mv<=${max}` : undefined];
        const colorPart = colors.length ? `color>=${colors.join("")}` : undefined;
        const typePart = type ? `type:${quote(type)}` : undefined;
        const q = joinParts([...range, colorPart, typePart]);
        const data: any = (await Scryfall.searchCards({ q, page })) as any;
        const items: any[] = Array.isArray(data?.data) ? data.data : [];
        const out = { total: Number(data?.total_cards ?? items.length), results: items.map(summarize) };
        return { structuredContent: out } as any;
    }
  • Input schema (min/max cmc, colors array, type str, page) and output schema reference (reuses search_by_colors output: {total: number, results: CardSummary[]}).
    const searchByCmcInput = {
        min: z.number().int().min(0).optional(),
        max: z.number().int().min(0).optional(),
        colors: z.array(z.enum(["W", "U", "B", "R", "G"])).min(0).max(5).optional(),
        type: z.string().optional(),
        page: z.number().int().min(1).optional()
    } as const;
    const searchByCmcOutput = searchByColorsOutput;
  • Registers the 'search_by_cmc' tool with MCP server, providing title, description, input/output schemas, and inline handler.
    server.registerTool(
        "search_by_cmc",
        {
            title: "Search by mana value",
            description: "Find cards within a mana value range, optionally filtered by color and type.",
            inputSchema: searchByCmcInput,
            outputSchema: searchByCmcOutput
        },
        async ({ min, max, colors = [], type, page }: { min?: number; max?: number; colors?: Array<"W" | "U" | "B" | "R" | "G">; type?: string; page?: number }) => {
            const range = [typeof min === "number" ? `mv>=${min}` : undefined, typeof max === "number" ? `mv<=${max}` : undefined];
            const colorPart = colors.length ? `color>=${colors.join("")}` : undefined;
            const typePart = type ? `type:${quote(type)}` : undefined;
            const q = joinParts([...range, colorPart, typePart]);
            const data: any = (await Scryfall.searchCards({ q, page })) as any;
            const items: any[] = Array.isArray(data?.data) ? data.data : [];
            const out = { total: Number(data?.total_cards ?? items.length), results: items.map(summarize) };
            return { structuredContent: out } as any;
        }
    );
  • Shared output schema {total: number, results: array of summarized cards}, referenced by searchByCmcOutput.
    const searchByColorsOutput = {
        total: z.number().int().nonnegative(),
        results: z.array(z.object(cardSummaryShape))
    } as const;
  • Helper to summarize Scryfall card data into CardSummary shape used in output results.
    const summarize = (card: any): CardSummary => ({
        name: card?.name,
        mana_cost: card?.mana_cost,
        type_line: card?.type_line,
        oracle_text: card?.oracle_text,
        set: card?.set,
        collector_number: String(card?.collector_number ?? ""),
        scryfall_uri: card?.scryfall_uri,
        image: card?.image_uris?.normal ?? card?.image_uris?.large ?? card?.image_uris?.small,
        prices: card?.prices
    });

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