/* Verify MCP registry results via the service (not DB directly): - Prints top 20 by stars from a merged, deduped, resorted sample - Searches for a specific term (default: sequential) */ import { MCPRegistryService } from '../src/main/services/mcp-registry-service' import { databaseManager } from '../src/main/db/connection' type Server = { id: string name: string description?: string packageName?: string packageRegistry?: string repository?: { type: string; url: string } githubStars?: number installCount?: number } function asNum(n: unknown): number { const v = Number(n ?? 0); return Number.isFinite(v) ? v : 0 } function keyOf(s: Server): string { return s.packageName || s.repository?.url || s.id || s.name } function dedupe(list: Server[]): Server[] { const m = new Map(); for (const s of list) { const k = keyOf(s); if (!m.has(k)) m.set(k, s) } return Array.from(m.values()) } async function main() { const args = process.argv.slice(2).filter(a => a !== '--') const query = (args.length ? args.join(' ') : 'sequential').trim() const svc = MCPRegistryService.getInstance() const pagesToFetch = Number(process.env.VERIFY_PAGES || 40) const offsets = Array.from({ length: pagesToFetch }, (_, i) => i * 50) const results = await Promise.allSettled(offsets.map(off => svc.searchServers({ limit: 50, offset: off }))) const merged = dedupe(results.flatMap(r => r.status === 'fulfilled' ? (r.value.servers as Server[]) : [])) const sorted = merged.sort((a, b) => { const as = asNum(a.githubStars), bs = asNum(b.githubStars) if (as !== bs) return bs - as const ai = asNum(a.installCount), bi = asNum(b.installCount) if (ai !== bi) return bi - ai return a.name.localeCompare(b.name) }) console.log(`[verify] merged=${merged.length}`) console.log('[verify] Top 20 by stars:') sorted.slice(0, 20).forEach((s, i) => { console.log(`${String(i + 1).padStart(2,' ')}. ${s.name} | stars=${asNum(s.githubStars)} installs=${asNum(s.installCount)} repo=${s.repository?.url || ''}`) }) const searchRes = await svc.searchServers({ query, limit: 50, offset: 0 }) const found = (searchRes.servers as Server[]) console.log(` [verify] search("${query}") -> ${found.length}`) found.forEach(s => { console.log(`- ${s.name} | stars=${asNum(s.githubStars)} installs=${asNum(s.installCount)} pkg=${s.packageName || ''} repo=${s.repository?.url || ''}`) }) const seq = sorted.find(s => /sequential/i.test(s.name)) if (seq) { console.log(`\n[verify] Found in merged sample: ${seq.name} | stars=${asNum(seq.githubStars)} installs=${asNum(seq.installCount)} repo=${seq.repository?.url || ''}`) } else { console.log('\n[verify] Sequential not found in merged sample — try increasing VERIFY_PAGES') } try { databaseManager.close() } catch {} process.exit(0) } main().catch(err => { console.error('[verify] failed', err); process.exit(1) })