get_part
Retrieve detailed specifications, color options, and mold variants for LEGO parts using part numbers to identify components accurately.
Instructions
Get complete details for a specific LEGO part including available colours and mold/print variants. Use this when you know a part number (like 3001) and need its specifications, colour availability, or related parts.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| part_num | Yes | Part number to look up (e.g. "3001") |
Implementation Reference
- src/tools/get-part.ts:48-118 (handler)The main handler function for the 'get_part' tool which performs DB queries and returns detailed part information.
export function handler(db: Database.Database, params: GetPartParams): GetPartResult { const partRow = db.prepare(` SELECT p.part_num, p.name, pc.name as category_name, p.part_material FROM parts p LEFT JOIN part_categories pc ON p.part_cat_id = pc.id WHERE p.part_num = ? `).get(params.part_num) as { part_num: string; name: string; category_name: string | null; part_material: string | null; } | undefined; if (!partRow) { const suggestions = db.prepare( 'SELECT part_num, name FROM parts WHERE part_num LIKE ? OR LOWER(name) LIKE LOWER(?) LIMIT 5' ).all(`${params.part_num}%`, `%${params.part_num}%`) as Array<{ part_num: string; name: string }>; return { found: false, message: `No part found with number "${params.part_num}"`, suggestions: suggestions.length > 0 ? suggestions.map(s => `${s.part_num} (${s.name})`) : undefined, }; } // Get available colours from inventory data const colors = db.prepare(` SELECT DISTINCT c.id as color_id, c.name as color_name, c.rgb as color_rgb FROM inventory_parts ip JOIN colors c ON ip.color_id = c.id WHERE ip.part_num = ? ORDER BY c.name `).all(params.part_num) as PartColorInfo[]; // Get part relationships where this part is the parent const childRelations = db.prepare(` SELECT pr.rel_type, pr.child_part_num as part_num, p.name as part_name FROM part_relationships pr LEFT JOIN parts p ON pr.child_part_num = p.part_num WHERE pr.parent_part_num = ? ORDER BY pr.rel_type, pr.child_part_num `).all(params.part_num) as RelatedPart[]; // Get part relationships where this part is the child const parentRelations = db.prepare(` SELECT pr.rel_type, pr.parent_part_num as part_num, p.name as part_name FROM part_relationships pr LEFT JOIN parts p ON pr.parent_part_num = p.part_num WHERE pr.child_part_num = ? ORDER BY pr.rel_type, pr.parent_part_num `).all(params.part_num) as RelatedPart[]; const allRelations = [...childRelations, ...parentRelations]; const molds = allRelations.filter(r => r.rel_type === 'M'); const prints = allRelations.filter(r => r.rel_type === 'P'); const alternates = allRelations.filter(r => r.rel_type === 'A' || r.rel_type === 'T'); return { found: true, part: { part_num: partRow.part_num, name: partRow.name, category_name: partRow.category_name, part_material: partRow.part_material, colors, molds, prints, alternates, }, }; } - src/tools/get-part.ts:6-8 (schema)The input schema definition for the 'get_part' tool using Zod.
export const GetPartInput = z.object({ part_num: z.string().describe('Part number to look up (e.g. "3001")'), }); - src/server.ts:117-125 (registration)The MCP tool registration for 'get_part' in the server.
server.tool( 'get_part', 'Get complete details for a specific LEGO part including available colours and mold/print variants. Use this when you know a part number (like 3001) and need its specifications, colour availability, or related parts.', GetPartInput.shape, async (params) => { try { const result = getPartHandler(db, params); return { content: [{ type: 'text' as const, text: formatGetPart(result) }] }; } catch (err) {