find_mocs
Discover community-designed LEGO builds you can create using parts from a specific set. Find alternative models to build with bricks you already own.
Instructions
Find community alternate builds (MOCs) that can be made from a specific LEGO set's parts. Use this when someone wants to know what else they can build with parts they already own.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| set_num | Yes | LEGO set number (e.g. "75192-1" for the Millennium Falcon) |
Implementation Reference
- src/tools/find-mocs.ts:29-77 (handler)The handler function performs the database query to retrieve MOC (My Own Creation) data for a given set.
export function handler(db: Database.Database, params: FindMocsParams): FindMocsResult { const setNum = params.set_num; // Look up the set name const setRow = db.prepare('SELECT name FROM sets WHERE set_num = ?').get(setNum) as { name: string } | undefined; // Check if the mocs table exists (it may not be in the schema yet) const mocsTableExists = db.prepare( "SELECT name FROM sqlite_master WHERE type='table' AND name='mocs'" ).get() as { name: string } | undefined; if (!mocsTableExists) { return { set_num: setNum, set_name: setRow?.name ?? null, mocs: [], moc_data_available: false, }; } // Check if the mocs table has any data const mocCount = (db.prepare('SELECT COUNT(*) AS cnt FROM mocs').get() as { cnt: number }).cnt; if (mocCount === 0) { return { set_num: setNum, set_name: setRow?.name ?? null, mocs: [], moc_data_available: false, }; } // Query MOCs for this set const mocs = db.prepare(` SELECT set_num AS moc_set_num, name, num_parts FROM mocs WHERE set_num IN ( SELECT moc_set_num FROM moc_parts WHERE set_num = ? ) ORDER BY num_parts DESC `).all(setNum) as MocSummary[]; return { set_num: setNum, set_name: setRow?.name ?? null, mocs, moc_data_available: true, }; } - src/tools/find-mocs.ts:6-8 (schema)The input validation schema for the find_mocs tool.
export const FindMocsInput = z.object({ set_num: z.string().describe('LEGO set number (e.g. "75192-1" for the Millennium Falcon)'), }); - src/tools/find-mocs.ts:81-107 (helper)Helper function to format the result of the find_mocs tool for display.
export function formatFindMocs(result: FindMocsResult): string { const lines: string[] = []; const setLabel = result.set_name ? `${result.set_name} (${result.set_num})` : result.set_num; if (!result.moc_data_available) { lines.push(`# Alternate Builds for ${setLabel}\n`); lines.push('No MOC data available in this database.'); lines.push(`Visit https://rebrickable.com/sets/${result.set_num}/mocs/ for community alternate builds.`); return lines.join('\n'); } if (result.mocs.length === 0) { lines.push(`# Alternate Builds for ${setLabel}\n`); lines.push('No alternate builds (MOCs) found for this set.'); lines.push(`Check https://rebrickable.com/sets/${result.set_num}/mocs/ for the latest community contributions.`); return lines.join('\n'); } lines.push(`# Alternate Builds for ${setLabel} (${result.mocs.length} found)\n`); for (const moc of result.mocs) { lines.push(`- **${moc.name}** (${moc.moc_set_num}): ${moc.num_parts} parts`); } return lines.join('\n'); }