Skip to main content
Glama
LostInBrittany

RAGmonsters Custom PostgreSQL MCP Server

getMonsterByHabitat

Retrieve monsters based on specific habitats. First, use getHabitats to identify available habitats, then query this tool with the exact habitat name to fetch relevant monster data efficiently.

Instructions

Get monsters by habitat (exact match only). IMPORTANT: for best results, first call getHabitats to get a list of available habitats, then find the most appropriate one to use with this tool.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
habitatYesExact habitat name (must match exactly). For best results, first call getHabitats to get a list of available habitats, then find the most appropriate one to use with this tool.
limitNoMaximum number of results to return (default: 10)

Implementation Reference

  • The core handler function implementing the getMonsterByHabitat tool. It queries the database for monsters matching the exact habitat name, handles errors, logs activity, and returns formatted JSON response.
    export async function getMonsterByHabitat(params) {
      try {
        if (!dbPool) {
          throw new Error('Database pool not initialized. Call initialize() first.');
        }
        
        logger.info(`getMonsterByHabitat called with params: ${JSON.stringify(params)}`);
        
        const { habitat, limit = 10 } = params;
        
        if (!habitat) {
          throw new Error('Habitat parameter is required');
        }
        
        // Query monsters with the exact habitat name
        const query = `
          SELECT 
            m.monster_id,
            m.name,
            m.category,
            m.habitat,
            m.rarity,
            m.primary_power,
            m.secondary_power,
            m.special_ability
          FROM 
            monsters m
          WHERE 
            m.habitat = $1
          ORDER BY 
            m.name ASC
          LIMIT $2
        `;
        
        const monsters = await executeQuery(dbPool, query, [habitat, limit]);
        
        logger.info(`getMonsterByHabitat returning ${monsters.length} monsters for habitat "${habitat}"`);
        
        // Format the response
        return {
          content: [{
            type: 'text',
            text: JSON.stringify({
              monsters: monsters.map(monster => ({
                id: monster.monster_id,
                name: monster.name,
                category: monster.category,
                habitat: monster.habitat,
                rarity: monster.rarity,
                powers: {
                  primary: monster.primary_power,
                  secondary: monster.secondary_power,
                  special: monster.special_ability
                }
              })),
              habitat: habitat,
              count: monsters.length
            })
          }]
        };
      } catch (error) {
        logger.error(`Error in getMonsterByHabitat: ${error.message}`);
        logger.error(error.stack);
        throw new Error(`Failed to retrieve monsters by habitat: ${error.message}`);
      }
    }
  • Registration of the 'getMonsterByHabitat' tool with the MCP server, including input schema (Zod validation), description, and binding to the handler function.
    server.addTool({
      name: 'getMonsterByHabitat',
      description: 'Get monsters by habitat (exact match only). IMPORTANT: for best results, first call getHabitats to get a list of available habitats, then find the most appropriate one to use with this tool.',
      parameters: z.object({
        habitat: z.string().describe('Exact habitat name (must match exactly). For best results, first call getHabitats to get a list of available habitats, then find the most appropriate one to use with this tool.'),
        limit: z.number().optional().describe('Maximum number of results to return (default: 10)')
      }),
      execute: getMonsterByHabitat
    });
  • Zod schema defining the input parameters for the getMonsterByHabitat tool: required 'habitat' string and optional 'limit' number.
      parameters: z.object({
        habitat: z.string().describe('Exact habitat name (must match exactly). For best results, first call getHabitats to get a list of available habitats, then find the most appropriate one to use with this tool.'),
        limit: z.number().optional().describe('Maximum number of results to return (default: 10)')
      }),
      execute: getMonsterByHabitat
    });
Behavior3/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the 'exact match only' constraint, which is useful behavioral context beyond basic functionality. However, it lacks details on error handling, rate limits, authentication needs, or what the return format looks like (e.g., list of monsters with specific fields).

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 and well-structured: two sentences that efficiently convey purpose and usage guidelines without wasted words. The first sentence states the core functionality, and the second provides critical procedural advice, both earning their place.

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 tool's moderate complexity (2 parameters, no output schema, no annotations), the description is fairly complete. It covers purpose, usage guidelines, and a key behavioral constraint ('exact match only'). However, without annotations or an output schema, it could benefit from more details on return values or error cases, but it's adequate for basic use.

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 the schema already documents both parameters ('habitat' and 'limit') with descriptions. The description repeats the guidance about calling 'getHabitats' for the 'habitat' parameter but doesn't add new semantic meaning beyond what the schema provides. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get monsters by habitat (exact match only).' It specifies the verb ('Get'), resource ('monsters'), and constraint ('by habitat, exact match only'). However, it doesn't explicitly differentiate from siblings like 'getMonsters' (which might fetch all monsters) or 'getMonsterByName' (which filters by name rather than habitat).

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 provides explicit usage guidance: 'for best results, first call getHabitats to get a list of available habitats, then find the most appropriate one to use with this tool.' This tells the agent when to use this tool (after retrieving habitat list) and references a sibling tool ('getHabitats') as a prerequisite, offering clear alternatives and 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

Related 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/LostInBrittany/RAGmonsters-mcp-pg'

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