Skip to main content
Glama
gregario

lego-oracle

compare_sets

Compare LEGO sets side by side to view piece counts, themes, minifigures, and shared parts for informed purchasing decisions.

Instructions

Compare 2 to 4 LEGO sets side by side. Shows piece count, year, theme, minifig count, and shared parts between sets. Use this when someone is deciding between sets or wants to know what parts overlap.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
set_numsYesArray of 2-4 LEGO set numbers to compare side by side

Implementation Reference

  • The handler function that executes the logic to compare LEGO sets, including database queries to fetch set details and find shared parts.
    export function handler(db: Database.Database, params: CompareSetsParams): CompareSetsResult {
      const setNums = params.set_nums;
      const sets: SetComparison[] = [];
    
      for (const setNum of setNums) {
        const row = db.prepare(`
          SELECT s.set_num, s.name, s.year, s.num_parts, t.name AS theme_name
          FROM sets s
          LEFT JOIN themes t ON s.theme_id = t.id
          WHERE s.set_num = ?
        `).get(setNum) as { set_num: string; name: string; year: number | null; num_parts: number | null; theme_name: string | null } | undefined;
    
        if (!row) {
          sets.push({
            set_num: setNum,
            found: false,
            name: null,
            year: null,
            theme: null,
            num_parts: null,
            minifig_count: 0,
          });
          continue;
        }
    
        // Count minifigs
        const minifigCount = (db.prepare(`
          SELECT COALESCE(SUM(im.quantity), 0) AS cnt
          FROM inventory_minifigs im
          JOIN inventories inv ON im.inventory_id = inv.id
          WHERE inv.set_num = ?
        `).get(setNum) as { cnt: number }).cnt;
    
        sets.push({
          set_num: setNum,
          found: true,
          name: row.name,
          year: row.year,
          theme: row.theme_name,
          num_parts: row.num_parts,
          minifig_count: minifigCount,
        });
      }
    
      // Find shared parts: parts that appear in ALL compared sets (only among found sets)
      const foundSetNums = sets.filter(s => s.found).map(s => s.set_num);
      let sharedParts: Array<{ part_num: string; name: string }> = [];
    
      if (foundSetNums.length >= 2) {
        // For each set, get the distinct part_nums from its inventories
        // Then find the intersection across all sets
        const placeholders = foundSetNums.map(() => '?').join(', ');
        const numSets = foundSetNums.length;
    
        sharedParts = db.prepare(`
          SELECT ip.part_num, p.name
          FROM inventory_parts ip
          JOIN inventories inv ON ip.inventory_id = inv.id
          JOIN parts p ON ip.part_num = p.part_num
          WHERE inv.set_num IN (${placeholders})
          GROUP BY ip.part_num
          HAVING COUNT(DISTINCT inv.set_num) = ?
          ORDER BY p.name
          LIMIT 50
        `).all(...foundSetNums, numSets) as Array<{ part_num: string; name: string }>;
      }
    
      return {
        sets,
        shared_parts_count: sharedParts.length,
        shared_parts: sharedParts,
      };
    }
  • The zod schema defining the expected input parameters for the compare_sets tool.
    export const CompareSetsInput = z.object({
      set_nums: z.array(z.string()).min(2).max(4).describe(
        'Array of 2-4 LEGO set numbers to compare side by side'
      ),
    });
  • src/server.ts:206-211 (registration)
    The registration of the compare_sets tool within the server application, connecting the input schema and handler.
    'compare_sets',
    'Compare 2 to 4 LEGO sets side by side. Shows piece count, year, theme, minifig count, and shared parts between sets. Use this when someone is deciding between sets or wants to know what parts overlap.',
    CompareSetsInput.shape,
    async (params) => {
      try {
        const result = compareSetsHandler(db, params);

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