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 });

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