Skip to main content
Glama

check_legality

Verify card legality in MTG formats. Input one card name or up to 50 to see if they are legal, banned, or restricted in Commander, Modern, Standard, Legacy, Vintage.

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 core handler function that checks card legality. It accepts a card name (or array of names) and an optional format, queries the database for matching cards and their legalities, and returns a structured result.
    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 input schema for check_legality: accepts a string or array of up to 50 card names, and an optional format parameter.
    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.'),
    });
  • Output type definitions: CardLegality (per-card results) and CheckLegalityResult (overall format + results array).
    export interface CardLegality {
      card_name: string;
      found: boolean;
      legalities: Record<string, string>;
      message?: string;
    }
    
    export interface CheckLegalityResult {
      format: string | null;
      results: CardLegality[];
    }
  • src/server.ts:121-133 (registration)
    Tool registration in the MCP server using server.tool() with name 'check_legality', description, input schema, and handler invocation.
    server.tool(
      'check_legality',
      '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.',
      CheckLegalityInput.shape,
      async (params) => {
        try {
          const result = checkLegalityHandler(db, params);
          return { content: [{ type: 'text' as const, text: formatCheckLegality(result) }] };
        } catch (err) {
          return { content: [{ type: 'text' as const, text: `Error checking legality: ${err instanceof Error ? err.message : String(err)}` }], isError: true };
        }
      },
    );
  • Formatting helper that converts the CheckLegalityResult into a human-readable text string for display.
    export function formatCheckLegality(result: CheckLegalityResult): string {
      const lines: string[] = [];
    
      if (result.format) {
        lines.push(`# Format Legality Check: ${capitalize(result.format)}\n`);
      } else {
        lines.push('# Format Legality Check\n');
      }
    
      for (const card of result.results) {
        if (!card.found) {
          lines.push(`**${card.card_name}**: ${card.message}`);
          continue;
        }
    
        lines.push(`**${card.card_name}**:`);
        const entries = Object.entries(card.legalities);
        if (entries.length === 0) {
          lines.push('  No legality data available.');
        } else {
          const parts = entries.map(([fmt, status]) => `${capitalize(fmt)}: ${capitalize(status)}`);
          lines.push(`  ${parts.join(' | ')}`);
        }
      }
    
      return lines.join('\n');
    }
Behavior4/5

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

With no annotations, the description provides key behaviors: accepts single or array up to 50 cards, checks legality. It implies a read-only operation, no contradictory behaviors. Could mention output structure but adequate.

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?

Two sentences: first states purpose, second provides usage context and acceptable formats. No filler, front-loading of key info, every sentence earns its place.

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

Completeness4/5

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

Given no output schema, the description implies the output is a legality status per format, which is sufficient for this simple tool. Could detail output format, but the agent can infer from the query nature.

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 coverage is 100%, so parameters are well-documented. The description adds context like 'max 50' and 'Omit for all formats' but does not go beyond what the schema already conveys. Baseline 3 is appropriate.

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 verb 'check' and the resource 'which formats a card is legal in', distinguishing it from sibling tools like 'get_card' (card details) and 'search_cards' (searching). It specifies the action and scope.

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

Usage Guidelines4/5

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

The description tells when to use the tool ('when a user wants to know if a card is legal') and lists example formats. It does not explicitly state when not to use it, but the focus on legality is clear, and siblings cover other use cases.

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