test-connection.js•2.49 kB
#!/usr/bin/env node
/**
* Simple script to test connection to Superprecio API
* Run: node test-connection.js
*/
import { createApiClient } from './build/client/superPrecioApi.js';
import dotenv from 'dotenv';
// Load environment variables
dotenv.config();
async function testConnection() {
console.log('🧪 Testing Superprecio MCP Server Connection...\n');
const apiUrl = process.env.SUPERPRECIO_API_URL || 'http://localhost:3000';
console.log(`📡 API URL: ${apiUrl}`);
try {
const client = createApiClient();
// Test 1: Health Check
console.log('\n1️⃣ Testing health check...');
const isHealthy = await client.healthCheck();
if (isHealthy) {
console.log(' ✅ Health check passed');
} else {
console.log(' ❌ Health check failed');
console.log(' ⚠️ Make sure Superprecio is running at:', apiUrl);
process.exit(1);
}
// Test 2: Search Products
console.log('\n2️⃣ Testing search products...');
const searchResult = await client.searchProducts({
search: 'arroz',
maxResults: 3,
order: 'OrderByPriceASC',
});
if (searchResult && searchResult.allData) {
console.log(' ✅ Search successful');
console.log(` 📊 Found products in ${searchResult.columns} supermarkets`);
console.log(` 🏪 Supermarkets: ${searchResult.markets.map(m => m.name).join(', ')}`);
} else {
console.log(' ❌ Search failed');
}
// Test 3: Get Supermarket List
console.log('\n3️⃣ Testing supermarket list...');
if (searchResult && searchResult.markets) {
console.log(' ✅ Supermarket list retrieved');
searchResult.markets.forEach((market, idx) => {
console.log(` ${idx + 1}. ${market.name}`);
});
}
console.log('\n✅ All tests passed!');
console.log('\n🚀 The MCP server is ready to use!');
console.log('\nNext steps:');
console.log('1. Configure Claude Desktop (see QUICK_START.md)');
console.log('2. Restart Claude Desktop');
console.log('3. Start chatting with your price expert!\n');
} catch (error) {
console.error('\n❌ Test failed with error:');
console.error(error.message);
console.error('\nTroubleshooting:');
console.error('1. Is Superprecio running? Try: curl', apiUrl);
console.error('2. Is the API URL correct in .env file?');
console.error('3. Are there any firewall issues?\n');
process.exit(1);
}
}
testConnection();