Skip to main content
Glama

get_keyword

Retrieve the official rules text for a Magic: The Gathering keyword ability like Flying or Deathtouch. Ideal for clarifying keyword mechanics.

Instructions

Get the official rules definition for a Magic keyword ability (e.g., "Flying", "Deathtouch", "Equip"). Use this when a user asks how a keyword works or what its rules text says. Different from get_glossary — this is specifically for keyword abilities with rules text.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesKeyword name to look up (case-insensitive). Examples: "Flying", "Equip", "Scry".

Implementation Reference

  • Core handler function that looks up a keyword by name. First tries exact (case-insensitive) match, then fuzzy LIKE match, and finally returns suggestions based on the first word of the query.
    export function handler(db: Database.Database, params: GetKeywordParams): GetKeywordResult {
      // 1. Exact match (case-insensitive)
      const exact = db.prepare(
        'SELECT * FROM keywords WHERE LOWER(name) = LOWER(?)'
      ).get(params.name) as KeywordRow | undefined;
    
      if (exact) {
        return {
          found: true,
          keyword: toEntry(exact),
        };
      }
    
      // 2. Fuzzy fallback via LIKE
      const fuzzy = db.prepare(
        'SELECT * FROM keywords WHERE LOWER(name) LIKE LOWER(?)'
      ).get(`%${params.name}%`) as KeywordRow | undefined;
    
      if (fuzzy) {
        return {
          found: true,
          keyword: toEntry(fuzzy),
        };
      }
    
      // 3. Suggestions based on first word
      const suggestions = db.prepare(
        'SELECT name FROM keywords WHERE LOWER(name) LIKE LOWER(?) LIMIT 5'
      ).all(`%${params.name.split(' ')[0]}%`) as Array<{ name: string }>;
    
      return {
        found: false,
        message: `No keyword found matching "${params.name}"`,
        suggestions: suggestions.length > 0 ? suggestions.map(s => s.name) : undefined,
      };
    }
  • Input schema using Zod, output types (KeywordEntry and GetKeywordResult discriminated union), and the type alias for params.
    import { z } from 'zod';
    import type Database from 'better-sqlite3';
    import type { KeywordRow } from '../data/db.js';
    
    // --- Input schema ---
    
    export const GetKeywordInput = z.object({
      name: z.string().describe('Keyword name to look up (case-insensitive). Examples: "Flying", "Equip", "Scry".'),
    });
    
    export type GetKeywordParams = z.infer<typeof GetKeywordInput>;
  • src/server.ts:179-191 (registration)
    Registration of the 'get_keyword' tool on the MCP server with its schema, description, and async handler that calls the handler function and formats the result.
    server.tool(
      'get_keyword',
      'Get the official rules definition for a Magic keyword ability (e.g., "Flying", "Deathtouch", "Equip"). Use this when a user asks how a keyword works or what its rules text says. Different from get_glossary — this is specifically for keyword abilities with rules text.',
      GetKeywordInput.shape,
      async (params) => {
        try {
          const result = getKeywordHandler(db, params);
          return { content: [{ type: 'text' as const, text: formatGetKeyword(result) }] };
        } catch (err) {
          return { content: [{ type: 'text' as const, text: `Error getting keyword: ${err instanceof Error ? err.message : String(err)}` }], isError: true };
        }
      },
    );
  • Formatting helper that converts the GetKeywordResult into a human-readable string (markdown). Handles both found and not-found cases, including suggestions.
    export function formatGetKeyword(result: GetKeywordResult): string {
      if (!result.found) {
        let text = result.message;
        if (result.suggestions && result.suggestions.length > 0) {
          text += `\n\nDid you mean: ${result.suggestions.join(', ')}?`;
        }
        return text;
      }
    
      const kw = result.keyword;
      const lines: string[] = [
        `# ${kw.name}`,
        `Type: ${kw.type} | Section: ${kw.section}`,
        '',
        kw.rules_text,
      ];
    
      return lines.join('\n');
    }
  • Helper function to convert a KeywordRow database row into a KeywordEntry object.
    function toEntry(row: KeywordRow): KeywordEntry {
      return {
        name: row.name,
        section: row.section,
        type: row.type,
        rules_text: row.rules_text,
      };
    }
Behavior3/5

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

No annotations are provided, so the description must cover behavioral traits. It describes a read-only lookup operation but does not disclose potential side effects, authentication needs, rate limits, or data source details. The simplicity of the operation partially mitigates this, but more transparency would be beneficial.

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 two sentences long, with no extraneous information. The first sentence defines the purpose with examples, and the second provides usage guidance and sibling differentiation. Every word earns its place.

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

Completeness5/5

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

For a simple lookup tool with one parameter and no output schema, the description covers purpose, usage context, and differentiation. No additional information (e.g., output format) is necessary for the agent to use the tool effectively.

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

Parameters4/5

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

The input schema has 100% description coverage, so baseline is 3. The description adds value with examples ('Flying', 'Equip', 'Scry') and implicitly confirms case-insensitivity, which is already in the schema. This extra context justifies a 4.

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 retrieves official rules definitions for Magic keyword abilities, with examples like 'Flying', 'Deathtouch', 'Equip'. It distinguishes itself from the sibling tool 'get_glossary' by specifying it is for keyword abilities with rules text.

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 this tool: 'Use this when a user asks how a keyword works or what its rules text says.' It also contrasts with the alternative 'get_glossary', providing clear guidance on differentiation.

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