Skip to main content
Glama

browse_races

Retrieve a list of all D&D 5e SRD races or detailed information on a specific race including traits, ability bonuses, and subraces.

Instructions

Browse D&D 5e SRD races. List all races or view a specific race's traits, ability bonuses, and subraces.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
race_nameNoName of a specific race to look up

Implementation Reference

  • handleListRaces: Lists all races from the database, formatting each with speed, size, and ability bonuses.
    function handleListRaces(db: Database.Database) {
      const races = listRaces(db);
      if (races.length === 0) {
        return {
          content: [{ type: 'text' as const, text: 'No races found in the database.' }],
        };
      }
    
      const lines = races.map((race) => {
        const bonuses = safeJsonParse<AbilityBonus[]>(race.ability_bonuses, []);
        return `${race.name}\n  Speed: ${race.speed} ft.\n  Size: ${race.size}\n  Ability Bonuses: ${formatAbilityBonuses(bonuses)}`;
      });
    
      const text = `D&D 5e SRD Races (${races.length})\n${'='.repeat(40)}\n\n${lines.join('\n\n')}`;
      return { content: [{ type: 'text' as const, text }] };
    }
    
    function handleSingleRace(db: Database.Database, raceName: string) {
      const race = getRaceByName(db, raceName);
      if (!race) {
        const allRaces = listRaces(db);
        const available = allRaces.map((r) => r.name).join(', ');
        return {
          content: [
            {
              type: 'text' as const,
              text: `Race "${raceName}" not found. Available races: ${available}`,
            },
          ],
          isError: true,
        };
      }
    
      const bonuses = safeJsonParse<AbilityBonus[]>(race.ability_bonuses, []);
      const traits = safeJsonParse<RaceTrait[]>(race.traits, []);
      const languages = safeJsonParse<string[]>(race.languages, []);
      const subraces = safeJsonParse<Subrace[]>(race.subraces, []);
    
      const sections: string[] = [
        `${race.name}`,
        '='.repeat(40),
        `Speed: ${race.speed} ft.`,
        `Size: ${race.size}`,
        `Ability Bonuses: ${formatAbilityBonuses(bonuses)}`,
        `Languages: ${languages.join(', ') || 'None'}`,
      ];
    
      // Traits
      if (traits.length > 0) {
        sections.push(`\nTraits (${traits.length}):`);
        sections.push(formatTraits(traits));
      }
    
      // Subraces
      if (subraces.length > 0) {
        sections.push(`\nSubraces (${subraces.length}):`);
        for (const subrace of subraces) {
          sections.push(`\n  ${subrace.name}`);
          if (subrace.description) {
            sections.push(`    ${subrace.description}`);
          }
          if (subrace.ability_bonuses && subrace.ability_bonuses.length > 0) {
            sections.push(
              `    Additional Ability Bonuses: ${formatAbilityBonuses(subrace.ability_bonuses)}`,
            );
          }
          if (subrace.traits && subrace.traits.length > 0) {
            sections.push(`    Subrace Traits:`);
            for (const trait of subrace.traits) {
              sections.push(`      ${trait.name}: ${trait.description}`);
            }
          }
        }
      }
    
      return { content: [{ type: 'text' as const, text: sections.join('\n') }] };
    }
  • handleSingleRace: Looks up a specific race by name and returns detailed info including traits, languages, and subraces.
    function handleSingleRace(db: Database.Database, raceName: string) {
      const race = getRaceByName(db, raceName);
      if (!race) {
        const allRaces = listRaces(db);
        const available = allRaces.map((r) => r.name).join(', ');
        return {
          content: [
            {
              type: 'text' as const,
              text: `Race "${raceName}" not found. Available races: ${available}`,
            },
          ],
          isError: true,
        };
      }
    
      const bonuses = safeJsonParse<AbilityBonus[]>(race.ability_bonuses, []);
      const traits = safeJsonParse<RaceTrait[]>(race.traits, []);
      const languages = safeJsonParse<string[]>(race.languages, []);
      const subraces = safeJsonParse<Subrace[]>(race.subraces, []);
    
      const sections: string[] = [
        `${race.name}`,
        '='.repeat(40),
        `Speed: ${race.speed} ft.`,
        `Size: ${race.size}`,
        `Ability Bonuses: ${formatAbilityBonuses(bonuses)}`,
        `Languages: ${languages.join(', ') || 'None'}`,
      ];
    
      // Traits
      if (traits.length > 0) {
        sections.push(`\nTraits (${traits.length}):`);
        sections.push(formatTraits(traits));
      }
    
      // Subraces
      if (subraces.length > 0) {
        sections.push(`\nSubraces (${subraces.length}):`);
        for (const subrace of subraces) {
          sections.push(`\n  ${subrace.name}`);
          if (subrace.description) {
            sections.push(`    ${subrace.description}`);
          }
          if (subrace.ability_bonuses && subrace.ability_bonuses.length > 0) {
            sections.push(
              `    Additional Ability Bonuses: ${formatAbilityBonuses(subrace.ability_bonuses)}`,
            );
          }
          if (subrace.traits && subrace.traits.length > 0) {
            sections.push(`    Subrace Traits:`);
            for (const trait of subrace.traits) {
              sections.push(`      ${trait.name}: ${trait.description}`);
            }
          }
        }
      }
    
      return { content: [{ type: 'text' as const, text: sections.join('\n') }] };
    }
  • registerBrowseRaces: Registers the 'browse_races' tool on the MCP server with an optional race_name input schema.
    export function registerBrowseRaces(
      server: McpServer,
      db: Database.Database,
    ): void {
      server.registerTool(
        'browse_races',
        {
          description:
            "Browse D&D 5e SRD races. List all races or view a specific race's traits, ability bonuses, and subraces.",
          inputSchema: {
            race_name: z
              .string()
              .optional()
              .describe('Name of a specific race to look up'),
          },
        },
        async ({ race_name }) => {
          if (race_name) {
            return handleSingleRace(db, race_name);
          }
          return handleListRaces(db);
        },
      );
    }
  • Tool registration with inputSchema: optional 'race_name' string parameter and description.
    server.registerTool(
      'browse_races',
      {
        description:
          "Browse D&D 5e SRD races. List all races or view a specific race's traits, ability bonuses, and subraces.",
        inputSchema: {
          race_name: z
            .string()
            .optional()
            .describe('Name of a specific race to look up'),
        },
      },
  • Helper functions: safeJsonParse, formatAbilityBonuses, formatTraits for formatting race data.
    function safeJsonParse<T>(value: string | null, fallback: T): T {
      if (!value) return fallback;
      try {
        return JSON.parse(value) as T;
      } catch {
        return fallback;
      }
    }
    
    function formatAbilityBonuses(bonuses: AbilityBonus[]): string {
      if (bonuses.length === 0) return 'None';
      return bonuses.map((b) => `${b.ability ?? b.ability_score ?? 'Unknown'} +${b.bonus}`).join(', ');
    }
    
    function formatTraits(traits: RaceTrait[]): string {
      if (traits.length === 0) return '  None';
      return traits
        .map((t) => `  ${t.name}: ${t.description}`)
        .join('\n');
    }
Behavior4/5

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

With no annotations, the description carries the full burden. It discloses that the tool can list all races or provide details on a specific race, including traits, ability bonuses, and subraces. It does not explicitly state it's read-only, but this is inferred. A score of 4 reflects good but not exhaustive disclosure.

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 concise sentences with no extraneous information. It is front-loaded with the tool's purpose and efficiently covers both modes of operation.

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 the simplicity of the tool (one optional parameter, no output schema, no annotations), the description covers the core functionality adequately. It could mention that the tool is read-only, but overall it provides sufficient context for an AI agent to use correctly.

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?

Schema coverage is 100% with one parameter. The description adds meaning beyond the schema by explaining that omitting the parameter lists all races while providing it yields specific details. This clarifies the dual behavior based on parameter usage.

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 browses D&D 5e SRD races, with the ability to list all or view a specific race's details. It uses a specific verb ('browse') and resource ('races'), and distinguishes itself from sibling tools like 'browse_classes' by explicitly mentioning races.

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?

No explicit guidance on when to use this tool versus alternatives like 'browse_classes' or when not to use it. The implied usage is clear from the description, but there are no exclusionary statements or comparisons to siblings.

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