Skip to main content
Glama

decode_deck

Decode a Hearthstone deck code to see its full card list, mana curve, and card type breakdown. Get a clear view of the deck's composition.

Instructions

Decode a Hearthstone deck code into its full card list with mana curve and card type breakdown. Use this when a user shares a deck code and wants to see what's in it.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
deck_codeYesHearthstone deck code (base64 deckstring)

Implementation Reference

  • The main handler function 'decodeDeck' that decodes a Hearthstone deck code. It uses the 'deckstrings' library to decode the base64 deck code, looks up hero class (via DB or hardcoded map), resolves each card's dbfId to a CardSummary from the DB (with a placeholder for unknown cards), computes mana curve and type distribution, and returns a DecodeDeckResult.
    export function decodeDeck(
      db: Database.Database,
      input: DecodeDeckInputType,
    ): DecodeDeckResult {
      let decoded: { cards: Array<[number, number]>; heroes: number[]; format: number };
    
      try {
        decoded = decode(input.deck_code);
      } catch (err) {
        return {
          success: false,
          message: `Invalid deck code: ${err instanceof Error ? err.message : String(err)}`,
        };
      }
    
      // Format
      const format = decoded.format === 1 ? 'Wild' : 'Standard';
    
      // Hero class — try to look up hero in DB first, then fall back to map
      let heroClass = 'UNKNOWN';
      if (decoded.heroes.length > 0) {
        const heroDbfId = decoded.heroes[0];
        // Try DB lookup
        const heroRow = db
          .prepare('SELECT player_class FROM cards WHERE id = ?')
          .get(String(heroDbfId)) as { player_class: string | null } | undefined;
    
        if (heroRow?.player_class) {
          heroClass = heroRow.player_class;
        } else if (HERO_CLASS_MAP[heroDbfId]) {
          heroClass = HERO_CLASS_MAP[heroDbfId];
        }
      }
    
      // Cards
      const cards: Array<{ card: CardSummary; count: number }> = [];
      const manaCurve: Record<string, number> = {};
      const typeDistribution: Record<string, number> = {};
      let totalCards = 0;
    
      for (const [dbfId, count] of decoded.cards) {
        const row = db
          .prepare('SELECT * FROM cards WHERE id = ?')
          .get(String(dbfId)) as CardRow | undefined;
    
        let cardSummary: CardSummary;
        if (row) {
          cardSummary = toCardSummary(row);
        } else {
          // Unknown card — create a richer placeholder so the user understands
          // what happened and how to resolve it. The most common cause is a
          // recently-released card whose dbfId isn't in the local snapshot yet.
          cardSummary = {
            name: `Unknown card (dbfId: ${dbfId}) — possibly added in a recent expansion; refresh data to resolve`,
            mana_cost: null,
            type: null,
            player_class: null,
            rarity: null,
            text: null,
            attack: null,
            health: null,
            keywords: [],
          };
        }
    
        cards.push({ card: cardSummary, count });
        totalCards += count;
    
        // Mana curve
        const bucket = manaCurveBucket(cardSummary.mana_cost);
        manaCurve[bucket] = (manaCurve[bucket] ?? 0) + count;
    
        // Type distribution
        const cardType = cardSummary.type ?? 'UNKNOWN';
        typeDistribution[cardType] = (typeDistribution[cardType] ?? 0) + count;
      }
    
      return {
        success: true,
        format,
        hero_class: heroClass,
        cards,
        total_cards: totalCards,
        mana_curve: manaCurve,
        type_distribution: typeDistribution,
      };
    }
  • Input schema (DecodeDeckInput) requiring a 'deck_code' string, and output type definitions (DecodeDeckSuccess / DecodeDeckError) for the tool's result.
    export const DecodeDeckInput = z.object({
      deck_code: z.string().describe('Hearthstone deck code (base64 deckstring)'),
    });
    
    export type DecodeDeckInputType = z.infer<typeof DecodeDeckInput>;
    
    // --- Result Types ---
    
    export interface DecodeDeckSuccess {
      success: true;
      format: string;
      hero_class: string;
      cards: Array<{ card: CardSummary; count: number }>;
      total_cards: number;
      mana_curve: Record<string, number>;
      type_distribution: Record<string, number>;
    }
    
    export interface DecodeDeckError {
      success: false;
      message: string;
    }
    
    export type DecodeDeckResult = DecodeDeckSuccess | DecodeDeckError;
  • src/server.ts:137-162 (registration)
    Registration of the 'decode_deck' tool on the MCP server via server.tool(), importing the handler and schema from src/tools/decode-deck.ts.
    // 4. decode_deck
    server.tool(
      'decode_deck',
      'Decode a Hearthstone deck code into its full card list with mana curve and card type breakdown. Use this when a user shares a deck code and wants to see what\'s in it.',
      DecodeDeckInput.shape,
      async (params) => {
        try {
          const result = decodeDeck(db, params);
          return {
            content: [
              { type: 'text' as const, text: formatDecodeDeck(result) },
            ],
          };
        } catch (err) {
          return {
            content: [
              {
                type: 'text' as const,
                text: `Error: ${err instanceof Error ? err.message : String(err)}`,
              },
            ],
            isError: true,
          };
        }
      },
    );
  • The formatDecodeDeck function that formats the DecodeDeckResult into a human-readable markdown string (hero class, format, cards list, mana curve, type distribution).
    export function formatDecodeDeck(result: DecodeDeckResult): string {
      if (!result.success) {
        return result.message;
      }
    
      const lines: string[] = [];
      lines.push(`# Deck: ${result.hero_class} (${result.format})`);
      lines.push(`Total cards: ${result.total_cards}`);
      lines.push('');
    
      // Cards list
      lines.push('## Cards');
      for (const { card, count } of result.cards) {
        lines.push(
          `- ${count}x **${card.name}** (${card.mana_cost ?? '?'} mana) — ${card.type ?? 'Unknown'}`,
        );
      }
    
      // Mana Curve
      lines.push('');
      lines.push('## Mana Curve');
      const buckets = ['0', '1', '2', '3', '4', '5', '6', '7+'];
      for (const bucket of buckets) {
        const count = result.mana_curve[bucket] ?? 0;
        if (count > 0) {
          lines.push(`${bucket}: ${'#'.repeat(count)} (${count})`);
        }
      }
    
      // Type Distribution
      lines.push('');
      lines.push('## Type Distribution');
      for (const [type, count] of Object.entries(result.type_distribution)) {
        lines.push(`- ${type}: ${count}`);
      }
    
      return lines.join('\n');
    }
  • Helper functions used by the handler: parseJson (parses keyword JSON), toCardSummary (maps a DB row to CardSummary), manaCurveBucket (buckets mana cost), and HERO_CLASS_MAP (hardcoded hero dbfId to class mappings).
    function parseJson(raw: string | null): string[] {
      if (!raw) return [];
      try {
        return JSON.parse(raw) as string[];
      } catch {
        return [];
      }
    }
    
    function toCardSummary(row: CardRow): CardSummary {
      return {
        name: row.name,
        mana_cost: row.mana_cost,
        type: row.type,
        player_class: row.player_class,
        rarity: row.rarity,
        text: row.text ? row.text.split('\n')[0] : null,
        attack: row.attack,
        health: row.health,
        keywords: parseJson(row.keywords),
      };
    }
    
    function manaCurveBucket(cost: number | null): string {
      if (cost == null) return '0';
      if (cost >= 7) return '7+';
      return String(cost);
    }
Behavior3/5

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

No annotations provided, so description carries full burden. It describes the tool as decoding without side effects, but does not explicitly state read-only nature, error handling, or performance implications. Adequate but lacks explicit safety guarantees.

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, no wasted words. Purpose and usage are front-loaded. Highly concise and efficient.

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 simple tool with 1 parameter and no output schema, description explains input and output (card list, mana curve, card type breakdown). Could mention return format or error handling for invalid codes, but overall adequate for the complexity.

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?

Input schema has 100% description coverage for the single parameter 'deck_code' as 'Hearthstone deck code (base64 deckstring)'. Description adds minimal extra context ('when a user shares a deck code'), but doesn't elaborate on format or examples. 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?

Description uses specific verb 'Decode' and resource 'Hearthstone deck code', and specifies output: 'full card list with mana curve and card type breakdown'. It also states the use case: when a user shares a deck code. This clearly distinguishes it from siblings like 'analyze_deck'.

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?

Description provides a clear when-to-use scenario: 'Use this when a user shares a deck code and wants to see what's in it.' It does not explicitly mention when not to use or alternatives, but the purpose is distinct enough.

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/hearthstone-oracle'

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