Skip to main content
Glama
gregario

lego-oracle

find_part_in_sets

Locate LEGO sets containing a specific brick part number, with optional color filtering. Helps builders identify sources for particular pieces, displaying results by quantity.

Instructions

Find which LEGO sets contain a specific part, optionally in a specific colour. Use this when a builder wants to know where to source a particular brick. Results sorted by quantity (most pieces first).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
part_numYesPart number to search for
colorNoOptional colour filter (name or ID)
limitNoMax results (default 25, max 50)

Implementation Reference

  • The handler function that executes the SQL query to find sets containing a specific part.
    export function handler(db: Database.Database, params: FindPartInSetsParams): FindPartInSetsResult {
      const limit = params.limit ?? 25;
      const conditions: string[] = ['ip.part_num = ?'];
      const bindings: unknown[] = [params.part_num];
    
      if (params.color) {
        const colorId = parseInt(params.color, 10);
        if (!isNaN(colorId)) {
          conditions.push('c.id = ?');
          bindings.push(colorId);
        } else {
          conditions.push('LOWER(c.name) = LOWER(?)');
          bindings.push(params.color);
        }
      }
    
      const sql = `
        SELECT s.set_num, s.name as set_name, s.year, c.name as color_name,
               SUM(ip.quantity) as quantity
        FROM inventory_parts ip
        JOIN inventories inv ON ip.inventory_id = inv.id
        JOIN sets s ON inv.set_num = s.set_num
        JOIN colors c ON ip.color_id = c.id
        WHERE ${conditions.join(' AND ')}
        GROUP BY s.set_num, c.name
        ORDER BY quantity DESC
        LIMIT ?
      `;
      bindings.push(limit);
    
      const rows = db.prepare(sql).all(...bindings) as PartInSet[];
    
      return {
        part_num: params.part_num,
        sets: rows,
        total: rows.length,
      };
    }
  • The input validation schema for the find_part_in_sets tool using Zod.
    export const FindPartInSetsInput = z.object({
      part_num: z.string().describe('Part number to search for'),
      color: z.string().optional().describe('Optional colour filter (name or ID)'),
      limit: z.number().min(1).max(50).optional().describe('Max results (default 25, max 50)'),
    });
    
    export type FindPartInSetsParams = z.infer<typeof FindPartInSetsInput>;
  • src/server.ts:131-143 (registration)
    Registration of the find_part_in_sets tool in the MCP server instance.
    server.tool(
      'find_part_in_sets',
      'Find which LEGO sets contain a specific part, optionally in a specific colour. Use this when a builder wants to know where to source a particular brick. Results sorted by quantity (most pieces first).',
      FindPartInSetsInput.shape,
      async (params) => {
        try {
          const result = findPartInSetsHandler(db, params);
          return { content: [{ type: 'text' as const, text: formatFindPartInSets(result) }] };
        } catch (err) {
          return { content: [{ type: 'text' as const, text: `Error finding part in sets: ${err instanceof Error ? err.message : String(err)}` }], isError: true };
        }
      },
    );

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/lego-oracle'

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