Skip to main content
Glama
LostInBrittany

RAGmonsters Custom PostgreSQL MCP Server

getHabitats

Retrieve a comprehensive list of all available habitats stored in the RAGmonsters dataset, ensuring efficient access to monster habitat data via an optimized API.

Instructions

Get a list of all available habitats in the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the getHabitats tool. It queries the database for distinct non-null habitats from the monsters table, extracts the habitat names, logs the action, and returns them as a JSON string in the expected MCP content format.
    export async function getHabitats() { try { if (!dbPool) { throw new Error('Database pool not initialized. Call initialize() first.'); } logger.info('getHabitats called'); // Query to get distinct habitats const query = ` SELECT DISTINCT habitat FROM monsters WHERE habitat IS NOT NULL ORDER BY habitat ASC `; const results = await executeQuery(dbPool, query); // Extract habitat names const habitats = results.map(row => row.habitat); logger.info(`getHabitats returning ${habitats.length} habitats`); // Format the response return { content: [{ type: 'text', text: JSON.stringify(habitats) }] }; } catch (error) { logger.error(`Error in getHabitats: ${error.message}`); logger.error(error.stack); throw new Error(`Failed to retrieve habitats: ${error.message}`); } }
  • The registration of the getHabitats tool with the MCP server. It defines the tool name, description, empty parameters schema (since no inputs), and links the execute function to the imported getHabitats handler.
    server.addTool({ name: 'getHabitats', description: 'Get a list of all available habitats in the database', parameters: z.object({}), execute: getHabitats });
  • The Zod schema for the getHabitats tool parameters, which is an empty object indicating no input parameters are required.
    parameters: z.object({}),

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