Skip to main content
Glama
LostInBrittany

RAGmonsters Custom PostgreSQL MCP Server

getMonsters

Retrieve a list of monsters with optional filters, sorting, and pagination for efficient data access on the RAGmonsters PostgreSQL MCP server.

Instructions

Get a list of monsters with optional filtering, sorting, and pagination

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filtersNoOptional filters for the query
limitNoMaximum number of results to return (default: 10)
offsetNoNumber of results to skip for pagination (default: 0)
sortNoOptional sorting parameters

Implementation Reference

  • The core handler function for the getMonsters tool. It constructs a dynamic SQL query based on input parameters (filters, sort, limit, offset), executes it using the database pool, and returns a formatted list of monsters.
    export async function getMonsters(params = {}) {
      try {
        if (!dbPool) {
          throw new Error('Database pool not initialized. Call initialize() first.');
        }
        
        logger.info(`getMonsters called with params: ${JSON.stringify(params)}`);
        const { filters = {}, sort = {}, limit = 10, offset = 0 } = params;
        
        // Start building the query
        let 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 1=1
        `;
        
        // Build parameter array for prepared statement
        const queryParams = [];
        
        // Add filters
        if (filters.category) {
          queryParams.push(filters.category);
          query += ` AND m.category = $${queryParams.length}`;
        }
        
        if (filters.habitat) {
          queryParams.push(filters.habitat);
          query += ` AND m.habitat = $${queryParams.length}`;
        }
        
        if (filters.rarity) {
          queryParams.push(filters.rarity);
          query += ` AND m.rarity = $${queryParams.length}`;
        }
        
        // Add sorting
        if (sort.field) {
          // Validate sort field to prevent SQL injection
          const validSortFields = ['name', 'category', 'habitat', 'rarity'];
          const sortField = validSortFields.includes(sort.field) ? sort.field : 'name';
          
          // Validate sort direction
          const sortDirection = sort.direction?.toLowerCase() === 'desc' ? 'DESC' : 'ASC';
          
          query += ` ORDER BY m.${sortField} ${sortDirection}`;
        } else {
          // Default sort by name
          query += ` ORDER BY m.name ASC`;
        }
        
        // Add pagination
        query += ` LIMIT $${queryParams.length + 1} OFFSET $${queryParams.length + 2}`;
        queryParams.push(limit, offset);
        
        const monsters = await executeQuery(dbPool, query, queryParams);
        
        logger.info(`getMonsters returning ${monsters.length} monsters`);
        logger.debug(`First monster in results: ${JSON.stringify(monsters[0] || {})}`);
        
        // Format the response
        return { content:monsters.map(monster => ({
          type: 'text',
          text: JSON.stringify({
            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
            }
          }),
        }))};
      } catch (error) {
        logger.error(`Error in getMonsters: ${error.message}`);
        logger.error(error.stack);
        throw error;
      }
    }
  • Registers the getMonsters tool with the MCP server instance, linking the handler function and defining the input schema.
    server.addTool({
      name: 'getMonsters',
      description: 'Get a list of monsters with optional filtering, sorting, and pagination',
      parameters: z.object({
        filters: z.object({
          category: z.string().optional().describe('Filter by monster category'),
          habitat: z.string().optional().describe('Filter by monster habitat'),
          rarity: z.string().optional().describe('Filter by monster rarity')
        }).optional().describe('Optional filters for the query'),
        
        sort: z.object({
          field: z.string().optional().describe('Field to sort by (name, category, habitat, rarity)'),
          direction: z.enum(['asc', 'desc']).optional().describe('Sort direction (asc or desc)')
        }).optional().describe('Optional sorting parameters'),
        
        limit: z.number().optional().describe('Maximum number of results to return (default: 10)'),
        offset: z.number().optional().describe('Number of results to skip for pagination (default: 0)')
      }),
      execute: getMonsters
    });
  • Zod schema defining the input parameters for the getMonsters tool: filters (category, habitat, rarity), sort (field, direction), limit, offset.
    parameters: z.object({
      filters: z.object({
        category: z.string().optional().describe('Filter by monster category'),
        habitat: z.string().optional().describe('Filter by monster habitat'),
        rarity: z.string().optional().describe('Filter by monster rarity')
      }).optional().describe('Optional filters for the query'),
      
      sort: z.object({
        field: z.string().optional().describe('Field to sort by (name, category, habitat, rarity)'),
        direction: z.enum(['asc', 'desc']).optional().describe('Sort direction (asc or desc)')
      }).optional().describe('Optional sorting parameters'),
      
      limit: z.number().optional().describe('Maximum number of results to return (default: 10)'),
      offset: z.number().optional().describe('Number of results to skip for pagination (default: 0)')
    }),
  • Initialization function for the monsters tools module, setting up the shared database connection pool required by the handlers.
    export function initializeTools(pool) {
      dbPool = pool;
      logger.info('Monsters module initialized with database pool');
    }
Behavior2/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 filtering, sorting, and pagination but doesn't describe important traits like whether this is a read-only operation, what happens with invalid filters, rate limits, authentication requirements, or the format of returned results. For a list retrieval tool with zero annotation coverage, this leaves significant gaps.

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 a single, efficient sentence that front-loads the core purpose ('Get a list of monsters') and then succinctly lists the key capabilities. Every word earns its place with no redundancy or unnecessary elaboration.

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

Completeness2/5

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

Given no annotations and no output schema, the description is incomplete for a tool with four parameters and nested objects. It doesn't explain what the returned list looks like, how errors are handled, or important behavioral aspects like default values or constraints. For a list retrieval tool with filtering capabilities, more context is needed to be fully helpful.

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 all four parameters thoroughly. The description adds minimal value by mentioning 'optional filtering, sorting, and pagination' which aligns with the schema but doesn't provide additional semantic context beyond what's already in the parameter descriptions. This meets the baseline for high schema coverage.

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 verb ('Get') and resource ('list of monsters'), making the purpose immediately understandable. It distinguishes itself from siblings like getMonsterById or getMonsterByName by indicating it returns a list rather than a single entity. However, it doesn't explicitly differentiate from getMonsterByHabitat which also involves filtering.

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?

The description implies usage through 'optional filtering, sorting, and pagination', suggesting this tool is for general queries rather than specific lookups. However, it doesn't explicitly state when to use this versus alternatives like getMonsterByHabitat or getMonsterById, nor does it provide any exclusions or prerequisites for usage.

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