Skip to main content
Glama

search_rules

Find D&D 5e SRD rules by full-text search or look up specific conditions. Get official game rules quickly.

Instructions

Search D&D 5e SRD rules and conditions. Look up specific conditions or search rules text.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryNoFull-text search query for rules
condition_nameNoName of a specific condition to look up

Implementation Reference

  • Handlers for the search_rules tool: handleCondition (looks up a specific condition by name), handleRulesSearch (full-text search of rules), and handleListConditions (lists all conditions). Each returns MCP content.
    function handleCondition(db: Database.Database, conditionName: string) {
      const condition = getConditionByName(db, conditionName);
      if (!condition) {
        const allConditions = listConditions(db);
        const available = allConditions.map((c) => c.name).join(', ');
        return {
          content: [
            {
              type: 'text' as const,
              text: `Condition "${conditionName}" not found. Available conditions: ${available}`,
            },
          ],
          isError: true,
        };
      }
    
      const text = [
        `${condition.name}`,
        '='.repeat(40),
        condition.description,
      ].join('\n');
    
      return { content: [{ type: 'text' as const, text }] };
    }
    
    function handleRulesSearch(db: Database.Database, query: string) {
      const rules = searchRules(db, query);
      if (rules.length === 0) {
        return {
          content: [
            {
              type: 'text' as const,
              text: `No rules found matching "${query}".`,
            },
          ],
        };
      }
    
      const lines = rules.map((rule) => {
        const preview =
          rule.description.length > 200
            ? rule.description.slice(0, 200) + '...'
            : rule.description;
        return `${rule.name} [${rule.section}]\n  ${preview}`;
      });
    
      const text = `Rules matching "${query}" (${rules.length} results)\n${'='.repeat(40)}\n\n${lines.join('\n\n')}`;
      return { content: [{ type: 'text' as const, text }] };
    }
    
    function handleListConditions(db: Database.Database) {
      const conditions = listConditions(db);
      if (conditions.length === 0) {
        return {
          content: [
            { type: 'text' as const, text: 'No conditions found in the database.' },
          ],
        };
      }
    
      const lines = conditions.map((c) => {
        const preview =
          c.description.length > 150
            ? c.description.slice(0, 150) + '...'
            : c.description;
        return `${c.name}\n  ${preview}`;
      });
    
      const text = `D&D 5e SRD Conditions (${conditions.length})\n${'='.repeat(40)}\n\n${lines.join('\n\n')}`;
      return { content: [{ type: 'text' as const, text }] };
    }
  • handleRulesSearch: Performs full-text search on rules using the searchRules DB function and formats results with name, section, and a 200-char preview.
    function handleRulesSearch(db: Database.Database, query: string) {
      const rules = searchRules(db, query);
      if (rules.length === 0) {
        return {
          content: [
            {
              type: 'text' as const,
              text: `No rules found matching "${query}".`,
            },
          ],
        };
      }
    
      const lines = rules.map((rule) => {
        const preview =
          rule.description.length > 200
            ? rule.description.slice(0, 200) + '...'
            : rule.description;
        return `${rule.name} [${rule.section}]\n  ${preview}`;
      });
    
      const text = `Rules matching "${query}" (${rules.length} results)\n${'='.repeat(40)}\n\n${lines.join('\n\n')}`;
      return { content: [{ type: 'text' as const, text }] };
    }
  • Input schema for search_rules: accepts optional 'query' (full-text search string) and optional 'condition_name' (specific condition name).
    {
      description:
        'Search D&D 5e SRD rules and conditions. Look up specific conditions or search rules text.',
      inputSchema: {
        query: z
          .string()
          .optional()
          .describe('Full-text search query for rules'),
        condition_name: z
          .string()
          .optional()
          .describe('Name of a specific condition to look up'),
      },
  • registerSearchRules function: registers the 'search_rules' tool on the MCP server with its input schema and handler logic (3 modes).
    export function registerSearchRules(
      server: McpServer,
      db: Database.Database,
    ): void {
      server.registerTool(
        'search_rules',
        {
          description:
            'Search D&D 5e SRD rules and conditions. Look up specific conditions or search rules text.',
          inputSchema: {
            query: z
              .string()
              .optional()
              .describe('Full-text search query for rules'),
            condition_name: z
              .string()
              .optional()
              .describe('Name of a specific condition to look up'),
          },
        },
        async ({ query, condition_name }) => {
          // Mode 1: Specific condition
          if (condition_name) {
            return handleCondition(db, condition_name);
          }
    
          // Mode 2: Full-text search rules
          if (query) {
            return handleRulesSearch(db, query);
          }
    
          // Mode 3: List all conditions
          return handleListConditions(db);
        },
      );
  • src/server.ts:51-51 (registration)
    Registration call in src/server.ts: invokes registerSearchRules(server, db) to register the tool.
    registerSearchRules(server, db);
  • searchRules database function: runs FTS query on rules via SQLite MATCH (or returns all rules if query is empty after sanitization).
    export function searchRules(
      db: Database.Database,
      query: string,
    ): RuleRow[] {
      const ftsQuery = sanitizeFtsQuery(query);
      if (ftsQuery.length === 0) {
        return db
          .prepare('SELECT * FROM rules ORDER BY section ASC, name ASC')
          .all() as RuleRow[];
      }
      return db
        .prepare(
          'SELECT r.* FROM rules r WHERE r.id IN (SELECT rowid FROM rules_fts WHERE rules_fts MATCH ?) ORDER BY r.section ASC, r.name ASC',
        )
        .all(ftsQuery) as RuleRow[];
    }
Behavior3/5

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

No annotations exist, so the description carries full burden. It discloses a read-only search behavior, but lacks details on return format, pagination, or any constraints. Adequate for a simple search but not rich.

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 at two sentences, front-loading the main verb and resource, with no redundant or unnecessary words.

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?

For a simple 2-parameter search tool with no output schema, the description sufficiently covers purpose and parameter usage. It lacks details on return values but that is acceptable given the simplicity and no output schema.

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?

With 100% schema description coverage, the parameters are fully described in the schema. The tool description adds marginal value by restating the parameter purposes (specific conditions vs general search) but does not go beyond schema.

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 it searches D&D 5e SRD rules and conditions, distinguishing it from sibling tools like search_spells or search_monsters by specifying the exact resource (rules and conditions) and action (search/look up).

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

Usage Guidelines3/5

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

The description implies usage for rules and conditions but does not explicitly state when to use this tool over others, nor does it provide exclusions or alternatives. Usage guidance is inferred from sibling tool names.

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

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