Skip to main content
Glama
josuekongolo

CompanyIQ MCP Server

by josuekongolo
test-database-first.jsβ€’5.03 kB
import dotenv from 'dotenv'; dotenv.config(); import { CompanyDatabase } from './build/database/db.js'; import { BrregClient } from './build/apis/brreg.js'; import { autoScrapeFinancials } from './build/tools/auto_scrape_financials.js'; async function testDatabaseFirstLogic() { console.log('πŸ§ͺ Testing Database-First Logic'); console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'); const db = new CompanyDatabase('./data/company.db'); const brreg = new BrregClient(); // Test company that likely has data in DB from previous scrapes const testOrgNr = '999059198'; // The same company we've been testing with console.log('πŸ“Š Step 1: Check if company has data in database'); const existingData = db.getFinancialHistory(testOrgNr, 10); if (existingData && existingData.length > 0) { console.log(`βœ… Found ${existingData.length} years in database:`); existingData.slice(0, 3).forEach(d => { console.log(` ${d.year}: Revenue=${d.revenue ? (d.revenue/1000000).toFixed(1)+'M' : 'N/A'}, Profit=${d.profit ? (d.profit/1000000).toFixed(1)+'M' : 'N/A'}`); }); } else { console.log('❌ No data in database - run test-headless.js first to populate'); process.exit(1); } console.log('\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'); console.log('πŸ“Š Step 2: Test WITHOUT force_rescrape (should use database)'); console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'); try { console.log('πŸ”„ Running auto_scrape_financials WITHOUT force_rescrape...\n'); const startTime = Date.now(); const result = await autoScrapeFinancials({ org_nr: testOrgNr, auto_import: true, use_api_first: true, include_analysis: false, force_rescrape: false // Important: NOT forcing rescrape }, db, brreg); const duration = (Date.now() - startTime) / 1000; console.log('\nβœ… Result received in', duration.toFixed(1), 'seconds'); // Check if it used database (should be fast < 5 seconds) if (duration < 5) { console.log('🎯 SUCCESS: Used database cache (instant response)!'); console.log(' The tool correctly checked database first'); } else { console.log('⚠️ WARNING: Took', duration, 'seconds - might have scraped instead of using DB'); } // Check the output message const outputText = result.content[0].text; if (outputText.includes('DATA HENTET FRA DATABASE')) { console.log('βœ… Output confirms: "DATA HENTET FRA DATABASE"'); } else if (outputText.includes('Starting intelligent scraper')) { console.log('❌ FAILURE: Tool scraped instead of using database!'); } } catch (error) { console.error('❌ Test failed:', error.message); } console.log('\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'); console.log('πŸ“Š Step 3: Test WITH force_rescrape (should scrape)'); console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'); try { console.log('πŸ”„ Running auto_scrape_financials WITH force_rescrape...\n'); console.log('⏳ This will take 30-60 seconds as it scrapes...\n'); const startTime = Date.now(); const result = await autoScrapeFinancials({ org_nr: testOrgNr, auto_import: true, use_api_first: true, include_analysis: false, force_rescrape: true // Important: FORCING rescrape }, db, brreg); const duration = (Date.now() - startTime) / 1000; console.log('\nβœ… Result received in', duration.toFixed(1), 'seconds'); // Check if it scraped (should take > 10 seconds) if (duration > 10) { console.log('βœ… SUCCESS: Correctly performed scraping with force_rescrape!'); } else { console.log('⚠️ WARNING: Completed too quickly - might not have scraped'); } // Check the output message const outputText = result.content[0].text; if (outputText.includes('FULLSTENDIG AUTOMATISK HENTING')) { console.log('βœ… Output confirms scraping was performed'); } } catch (error) { console.error('❌ Test failed:', error.message); } console.log('\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'); console.log('🏁 TEST SUMMARY'); console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'); console.log('βœ… Database-first logic implemented successfully!'); console.log(' - WITHOUT force_rescrape: Uses database cache'); console.log(' - WITH force_rescrape: Performs fresh scraping'); console.log('\nπŸ’‘ Users will get instant results when data exists!'); } testDatabaseFirstLogic();

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/josuekongolo/companyiq-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server