Skip to main content
Glama

check_legality

Check Magic: The Gathering card legality across formats like Commander, Modern, Standard, Legacy, and Vintage to determine if cards are legal, banned, or restricted.

Instructions

Check which formats a card (or multiple cards) is legal in. Use this when a user wants to know if a card is legal, banned, or restricted in formats like Commander, Modern, Standard, Legacy, or Vintage. Accepts a single card name or an array of up to 50 card names.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cardsYesCard name or array of card names (max 50)
formatNoSpecific format to check (e.g., "commander", "modern"). Omit for all formats.

Implementation Reference

  • The main handler function for the check_legality tool, which queries the database for card legalities.
    export function handler(db: Database.Database, params: CheckLegalityParams): CheckLegalityResult {
      const cardNames = Array.isArray(params.cards) ? params.cards : [params.cards];
      const resolvedFormat = params.format ? resolveFormat(params.format) : null;
    
      const results: CardLegality[] = [];
    
      for (const name of cardNames) {
        // Case-insensitive exact match, then LIKE fallback
        let card = db.prepare(
          'SELECT * FROM cards WHERE LOWER(name) = LOWER(?)'
        ).get(name) as CardRow | undefined;
    
        if (!card) {
          card = db.prepare(
            'SELECT * FROM cards WHERE LOWER(name) LIKE LOWER(?)'
          ).get(`%${name}%`) as CardRow | undefined;
        }
    
        if (!card) {
          results.push({
            card_name: name,
            found: false,
            legalities: {},
            message: `Card not found: "${name}"`,
          });
          continue;
        }
    
        let rows: LegalityRow[];
        if (resolvedFormat) {
          rows = db.prepare(
            'SELECT * FROM legalities WHERE card_id = ? AND format = ?'
          ).all(card.id, resolvedFormat) as LegalityRow[];
        } else {
          rows = db.prepare(
            'SELECT * FROM legalities WHERE card_id = ?'
          ).all(card.id) as LegalityRow[];
        }
    
        const legalities: Record<string, string> = {};
        for (const row of rows) {
          legalities[row.format] = row.status;
        }
    
        results.push({
          card_name: card.name,
          found: true,
          legalities,
        });
      }
    
      return {
        format: resolvedFormat,
        results,
      };
    }
  • Zod schema defining the input parameters for the check_legality tool.
    export const CheckLegalityInput = z.object({
      cards: z.union([z.string(), z.array(z.string()).max(50)]).describe('Card name or array of card names (max 50)'),
      format: z.string().optional().describe('Specific format to check (e.g., "commander", "modern"). Omit for all formats.'),
    });
    
    export type CheckLegalityParams = z.infer<typeof CheckLegalityInput>;
  • Type interfaces defining the structure of the output for the check_legality tool.
    export interface CardLegality {
      card_name: string;
      found: boolean;
      legalities: Record<string, string>;
      message?: string;
    }
    
    export interface CheckLegalityResult {
      format: string | null;
      results: CardLegality[];
    }

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/gregario/mtg-oracle'

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