Skip to main content
Glama

build_encounter

Calculate XP budgets and suggest monster combinations for balanced D&D 5e encounters. Input party size and level to get encounter difficulty options.

Instructions

Build balanced D&D 5e encounters. Given party size and level, calculates XP budgets for each difficulty and suggests monster combinations.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
party_sizeYesNumber of party members (1-10)
party_levelYesAverage party level (1-20)
difficultyNoTarget difficulty. If omitted, shows budgets and suggestions for all difficulties.
monster_cr_minNoMinimum monster CR to consider (numeric, e.g. 0.25 for 1/4)
monster_cr_maxNoMaximum monster CR to consider (numeric)

Implementation Reference

  • The `registerBuildEncounter` function registers the 'build_encounter' tool on the MCP server. The handler (async callback starting at line 190) calculates XP budgets, queries monsters by CR range, and generates encounter suggestions using helper functions for difficulty calculation, encounter multipliers, and monster group composition.
    export function registerBuildEncounter(
      server: McpServer,
      db: Database.Database,
    ): void {
      server.registerTool(
        'build_encounter',
        {
          description:
            'Build balanced D&D 5e encounters. Given party size and level, calculates XP budgets for each difficulty and suggests monster combinations.',
          inputSchema: {
            party_size: z.number().min(1).max(10).describe('Number of party members (1-10)'),
            party_level: z.number().min(1).max(20).describe('Average party level (1-20)'),
            difficulty: z
              .enum(['easy', 'medium', 'hard', 'deadly'])
              .optional()
              .describe('Target difficulty. If omitted, shows budgets and suggestions for all difficulties.'),
            monster_cr_min: z
              .number()
              .optional()
              .describe('Minimum monster CR to consider (numeric, e.g. 0.25 for 1/4)'),
            monster_cr_max: z
              .number()
              .optional()
              .describe('Maximum monster CR to consider (numeric)'),
          },
        },
        async ({ party_size, party_level, difficulty, monster_cr_min, monster_cr_max }) => {
          const budgets = calculatePartyBudget(party_size, party_level);
    
          const crMin = monster_cr_min ?? 0;
          const crMax = monster_cr_max ?? party_level + 3;
          const monsters = getMonstersByCrRange(db, crMin, crMax);
    
          const lines: string[] = [];
          lines.push(`# Encounter Builder`);
          lines.push('');
          lines.push(`**Party:** ${party_size} characters at level ${party_level}`);
          lines.push(`**Monster CR range:** ${crMin}–${crMax}`);
          lines.push('');
    
          // XP budget table
          lines.push('## XP Budgets');
          lines.push('');
          lines.push('| Difficulty | XP Budget |');
          lines.push('|------------|-----------|');
          for (const d of DIFFICULTIES) {
            const marker = difficulty === d ? ' ←' : '';
            lines.push(`| ${d.charAt(0).toUpperCase() + d.slice(1)} | ${budgets[d].toLocaleString()} XP${marker} |`);
          }
          lines.push('');
    
          if (monsters.length === 0) {
            lines.push('*No SRD monsters found in the specified CR range.*');
            return {
              content: [{ type: 'text' as const, text: lines.join('\n') }],
            };
          }
    
          // Suggest groups for target difficulties
          const targetDifficulties: Difficulty[] = difficulty ? [difficulty] : DIFFICULTIES;
    
          for (const d of targetDifficulties) {
            const budget = budgets[d];
            lines.push(`## ${d.charAt(0).toUpperCase() + d.slice(1)} Encounters (${budget.toLocaleString()} XP)`);
            lines.push('');
    
            const groups = findMonsterGroups(monsters, budget, 5);
            if (groups.length === 0) {
              lines.push('*No suitable monster combinations found for this budget and CR range. Try widening the CR range.*');
            } else {
              groups.forEach((group, i) => {
                lines.push(`**Option ${i + 1}:**`);
                lines.push(formatGroup(group));
                lines.push('');
              });
            }
            lines.push('');
          }
    
          lines.push('---');
          lines.push('*Adjusted XP uses DMG encounter multipliers based on monster count. The actual difficulty may vary based on terrain, tactics, and party composition.*');
    
          return {
            content: [{ type: 'text' as const, text: lines.join('\n') }],
          };
        },
      );
    }
  • src/server.ts:54-57 (registration)
    Registration call: `registerBuildEncounter(server, db)` is invoked in the `createServer` function to wire the tool into the MCP server instance.
    registerBuildEncounter(server, db);
    registerPlanSpells(server, db);
    registerCompareMonsters(server, db);
    registerAnalyzeLoadout(server, db);
  • Input schema using Zod: defines `party_size` (1-10), `party_level` (1-20), optional `difficulty` enum, and optional `monster_cr_min`/`monster_cr_max` numeric range filters.
    description:
      'Build balanced D&D 5e encounters. Given party size and level, calculates XP budgets for each difficulty and suggests monster combinations.',
    inputSchema: {
      party_size: z.number().min(1).max(10).describe('Number of party members (1-10)'),
      party_level: z.number().min(1).max(20).describe('Average party level (1-20)'),
      difficulty: z
        .enum(['easy', 'medium', 'hard', 'deadly'])
        .optional()
        .describe('Target difficulty. If omitted, shows budgets and suggestions for all difficulties.'),
      monster_cr_min: z
        .number()
        .optional()
        .describe('Minimum monster CR to consider (numeric, e.g. 0.25 for 1/4)'),
      monster_cr_max: z
        .number()
        .optional()
        .describe('Maximum monster CR to consider (numeric)'),
    },
  • Helper function `getEncounterMultiplier`: returns DMG encounter XP multiplier based on monster count (1→1x, 2→1.5x, 3-6→2x, 7-10→2.5x, 11-14→3x, 15+→4x).
    function getEncounterMultiplier(monsterCount: number): number {
      if (monsterCount <= 1) return 1;
      if (monsterCount === 2) return 1.5;
      if (monsterCount <= 6) return 2;
      if (monsterCount <= 10) return 2.5;
      if (monsterCount <= 14) return 3;
      return 4;
    }
  • Helper function `calculatePartyBudget`: calculates the total XP budget for each difficulty threshold (easy/medium/hard/deadly) based on party size and average level, using the XP_THRESHOLDS table.
    function calculatePartyBudget(
      partySize: number,
      partyLevel: number,
    ): Record<Difficulty, number> {
      const thresholds = XP_THRESHOLDS[partyLevel];
      return {
        easy: thresholds.easy * partySize,
        medium: thresholds.medium * partySize,
        hard: thresholds.hard * partySize,
        deadly: thresholds.deadly * partySize,
      };
    }
Behavior3/5

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

No annotations are provided, so the description carries full burden. It indicates the tool calculates and suggests, implying read-only behavior, but does not explicitly confirm no side effects, rate limits, or error handling.

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?

Three sentences with no filler. Front-loaded with the core action 'Build balanced D&D 5e encounters' followed by a concise summary of functionality.

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

Completeness3/5

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

With no output schema, the description provides only high-level output (XP budgets, monster suggestions). Lacks detail on return format, structure, or exact data provided, which is important for a tool that suggests concrete combinations.

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 description coverage is 100%, so baseline is 3. The description reinforces the role of party_size, party_level, and difficulty, but adds minimal new meaning beyond the schema descriptions.

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 builds balanced D&D 5e encounters, calculates XP budgets, and suggests monster combinations. It distinguishes from sibling tools like search_monsters or compare_monitors by focusing on encounter creation.

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 implies when to use (when building an encounter with party size and level) and what the tool does, but does not explicitly mention when not to use or suggest alternatives. Sibling tool names provide implicit context.

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