search_filaments
Search 7,000+ 3D printing filaments by name, material, manufacturer, or color to find specifications like print temperatures, density, and available colors.
Instructions
Search 7,000+ 3D printing filaments by name, material type, manufacturer, or color. Returns filament specs including print temperatures, density, and available colors.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search text (filament name, material, manufacturer, or color) | |
| material | No | Filter by material type (e.g., "PLA", "PETG", "ABS") | |
| manufacturer | No | Filter by manufacturer name | |
| diameter | No | Filter by filament diameter in mm (1.75 or 2.85) | |
| limit | No | Max results (1-100, default 20) | |
| offset | No | Pagination offset |
Implementation Reference
- src/tools/search-filaments.ts:74-113 (handler)The actual handler logic for the `search_filaments` tool, which calls the database helper and formats the results.
async ({ query, material, manufacturer, diameter, limit, offset }) => { const clampedLimit = Math.max(1, Math.min(limit, 100)); const result = searchFilaments( db, query, { material, manufacturer, diameter }, clampedLimit, offset, ); if (result.total === 0) { return { isError: true, content: [ { type: 'text' as const, text: `No filaments found matching your search. Try broadening your query or use search_filaments with different filters.`, }, ], }; } const showing = result.rows.length; const lines: string[] = []; lines.push( `Found ${result.total} result${result.total === 1 ? '' : 's'}. Showing ${offset + 1}-${offset + showing} of ${result.total}:\n`, ); for (const row of result.rows) { lines.push(formatFilament(row)); } if (offset + showing < result.total) { lines.push( `\n--- Page ${Math.floor(offset / clampedLimit) + 1} of ${Math.ceil(result.total / clampedLimit)}. Use offset=${offset + clampedLimit} for next page. ---`, ); } return { content: [{ type: 'text' as const, text: lines.join('\n') }] }; }, - src/tools/search-filaments.ts:38-73 (registration)Registration of the `search_filaments` tool including its schema definition.
server.registerTool( 'search_filaments', { title: 'Search Filaments', description: 'Search 7,000+ 3D printing filaments by name, material type, manufacturer, or color. Returns filament specs including print temperatures, density, and available colors.', inputSchema: { query: z .string() .describe( 'Search text (filament name, material, manufacturer, or color)', ), material: z .string() .optional() .describe('Filter by material type (e.g., "PLA", "PETG", "ABS")'), manufacturer: z .string() .optional() .describe('Filter by manufacturer name'), diameter: z .number() .optional() .describe('Filter by filament diameter in mm (1.75 or 2.85)'), limit: z .number() .optional() .default(20) .describe('Max results (1-100, default 20)'), offset: z .number() .optional() .default(0) .describe('Pagination offset'), }, }, - src/data/db.ts:94-156 (helper)The underlying database search function called by the `search_filaments` tool.
export function searchFilaments( db: Database.Database, query: string, filters: SearchFilters = {}, limit = 20, offset = 0, ): SearchResult { const conditions: string[] = []; const params: (string | number)[] = []; // FTS match const sanitized = sanitizeFtsQuery(query); if (sanitized.length > 0) { // Add wildcard suffix for prefix matching const ftsTerms = sanitized .split(/\s+/) .filter(Boolean) .map((t) => `"${t}"*`) .join(' '); conditions.push( 'f.id IN (SELECT rowid FROM filaments_fts WHERE filaments_fts MATCH ?)', ); params.push(ftsTerms); } // Filters if (filters.material) { conditions.push('f.material_name = ?'); params.push(filters.material); } if (filters.manufacturer) { conditions.push('m.name = ?'); params.push(filters.manufacturer); } if (filters.diameter) { conditions.push('f.diameter = ?'); params.push(filters.diameter); } const where = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : ''; // Total count const countSql = ` SELECT COUNT(*) AS cnt FROM filaments f JOIN manufacturers m ON f.manufacturer_id = m.id ${where} `; const { cnt } = db.prepare(countSql).get(...params) as { cnt: number }; // Page of results const dataSql = ` ${FILAMENT_BASE_SELECT} ${where} ORDER BY f.name LIMIT ? OFFSET ? `; const rows = db .prepare(dataSql) .all(...params, limit, offset) as FilamentRow[]; return { rows, total: cnt }; }