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[];
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It describes the tool's function and input constraints (e.g., up to 50 card names), but lacks details on behavioral traits such as error handling, rate limits, authentication needs, or what the output looks like. It's adequate but has gaps in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and front-loaded: it starts with the core purpose, then provides usage context and input details in two sentences. Every sentence adds value without redundancy, making it efficient and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for a tool with 2 parameters. It covers purpose and usage well but lacks details on output format, error cases, or behavioral constraints. It's minimally viable but could be more comprehensive.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents parameters well. The description adds minimal value beyond the schema by mentioning the array limit (50 card names) and example formats, but doesn't provide additional syntax or format details. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Check which formats a card (or multiple cards) is legal in.' It specifies the action ('check'), resource ('card(s)'), and outcome ('legal, banned, or restricted in formats'). It distinguishes from siblings by focusing on legality rather than analysis, pricing, or searching.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly states when to use it: '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.' It provides clear context and purpose, though it doesn't explicitly name alternatives or exclusions, the guidance is direct and actionable.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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