Merge pull request #204 from mixelpixx/fix/issue-199-jlcpcb-prebuilt-download

fix(jlcpcb): download prebuilt catalog instead of broken JLCSearch offset loop (#199)
This commit is contained in:
mixelpixx
2026-05-30 09:29:48 -04:00
committed by GitHub
6 changed files with 1061 additions and 377 deletions

View File

@@ -10,21 +10,33 @@ export function registerJLCPCBApiTools(server: McpServer, callKicadScript: Funct
// Download JLCPCB parts database
server.tool(
"download_jlcpcb_database",
`Download the complete JLCPCB parts catalog to local database.
`Download the JLCPCB parts catalog to a local SQLite database for fast offline search.
This is a one-time setup that downloads ~2.5M+ parts from JLCSearch API.
No API credentials required - uses public JLCSearch API.
Sources (no API credentials required by default):
- cdfer (default): in-stock subset (~600k parts, ~1.5 GB download). Single file,
no extra tools — the most reliable path, especially on Windows.
- yaqwsx: the FULL catalog (all parts incl. out-of-stock, ~10 GB extracted).
Use source="yaqwsx" if you specifically want everything. Requires a 7z CLI.
- official: official JLCPCB API, used only if JLCPCB_APP_ID/JLCPCB_API_KEY/
JLCPCB_API_SECRET are set.
The download takes 5-10 minutes and creates a local SQLite database
for fast offline searching.`,
One-time setup; downloads resume automatically if interrupted. Re-run with
force=true to refresh.`,
{
force: z
.boolean()
.optional()
.default(false)
.describe("Force re-download even if database exists"),
source: z
.enum(["cdfer", "yaqwsx", "official"])
.optional()
.describe(
'Force one source. "cdfer" (default) = in-stock subset, no 7z needed. ' +
'"yaqwsx" = FULL ~10GB catalog (needs a 7z CLI). "official" = JLCPCB API (needs creds).',
),
},
async (args: { force?: boolean }) => {
async (args: { force?: boolean; source?: "cdfer" | "yaqwsx" | "official" }) => {
const result = await callKicadScript("download_jlcpcb_database", args);
if (result.success) {
return {
@@ -33,11 +45,20 @@ for fast offline searching.`,
type: "text",
text:
`✓ Successfully downloaded JLCPCB parts database\n\n` +
`Source: ${result.source}\n` +
(result.catalog_last_modified
? `Catalog dated: ${result.catalog_last_modified}` +
(typeof result.catalog_age_days === "number"
? ` (~${result.catalog_age_days} days old)`
: "") +
`\n`
: "") +
`Total parts: ${result.total_parts}\n` +
`Basic parts: ${result.basic_parts}\n` +
`Extended parts: ${result.extended_parts}\n` +
`Database size: ${result.db_size_mb} MB\n` +
`Database path: ${result.db_path}`,
`Database path: ${result.db_path}` +
(result.warning ? `\n\n⚠ ${result.warning}` : ""),
},
],
};
@@ -46,9 +67,7 @@ for fast offline searching.`,
content: [
{
type: "text",
text:
`✗ Failed to download JLCPCB database: ${result.message || "Unknown error"}\n\n` +
`Make sure JLCPCB_API_KEY and JLCPCB_API_SECRET environment variables are set.`,
text: `✗ Failed to download JLCPCB database: ${result.message || "Unknown error"}`,
},
],
};