UNPKG

@solana8800/sun_ecommerce_mcp

Version:

Model Context Protocol server for Sun eCommerce Platform (Pure JavaScript) - enables AI assistants to understand and control the complete eCommerce system

86 lines (73 loc) • 3.22 kB
#!/usr/bin/env node import { SunEcommerceApiClient } from '../client/api-client.js'; import { ToolHandler } from '../tools/tool-handler.js'; // Simple test script for MCP Server async function testMcpServer() { console.log('šŸš€ Testing Sun eCommerce MCP Server...'); // Initialize API client const apiClient = new SunEcommerceApiClient({ baseUrl: process.env.SUN_ECOMMERCE_API_URL || 'http://42.96.60.253:8080', apiVersion: process.env.SUN_ECOMMERCE_API_VERSION || 'v1', timeout: parseInt(process.env.SUN_ECOMMERCE_API_TIMEOUT || '30000'), retries: parseInt(process.env.SUN_ECOMMERCE_API_RETRIES || '3'), authToken: process.env.SUN_ECOMMERCE_API_TOKEN, enableLogging: process.env.SUN_ECOMMERCE_ENABLE_LOGGING !== 'false', }); const toolHandler = new ToolHandler(apiClient); try { // Test 1: List Categories (this endpoint works) console.log('\nšŸ“‚ Test 1: List Categories'); try { const categoriesResult = await toolHandler.handleTool('list_categories', {}); console.log('āœ… List Categories successful:', JSON.stringify(categoriesResult, null, 2)); } catch (error) { console.log('āŒ List Categories failed:', error instanceof Error ? error.message : error); } // Test 2: Search Products (this endpoint works) console.log('\nšŸ” Test 2: Search Products'); try { const productsResult = await toolHandler.handleTool('search_products', { limit: 5, offset: 0 }); console.log('āœ… Search Products successful:', JSON.stringify(productsResult, null, 2)); } catch (error) { console.log('āŒ Search Products failed:', error instanceof Error ? error.message : error); } // Test 3: Direct API call to categories console.log('\nšŸ“” Test 3: Direct API - Categories'); try { const categories = await apiClient.listCategories(); console.log('āœ… Direct Categories API successful:', categories); } catch (error) { console.log('āŒ Direct Categories API failed:', error instanceof Error ? error.message : error); } // Test 4: Direct API call to products console.log('\nšŸ“” Test 4: Direct API - Products'); try { const products = await apiClient.searchProducts({ limit: 3 }); console.log('āœ… Direct Products API successful:', products); } catch (error) { console.log('āŒ Direct Products API failed:', error instanceof Error ? error.message : error); } // Test 5: System health check console.log('\nšŸ„ Test 5: System Health'); try { const health = await apiClient.getSystemHealth(); console.log('āœ… System Health successful:', health); } catch (error) { console.log('āŒ System Health failed:', error instanceof Error ? error.message : error); } } catch (error) { console.error('šŸ’„ Test failed with error:', error instanceof Error ? error.message : error); } console.log('\nšŸ Test completed!'); } // Run the test if this file is executed directly if (process.argv[1] === new URL(import.meta.url).pathname) { testMcpServer().catch((error) => { console.error('Failed to run test:', error); process.exit(1); }); } export { testMcpServer };