Skip to main content
Glama
portel-dev

NCP - Natural Context Provider

by portel-dev
test-semantic-enhancement.ts9.12 kB
#!/usr/bin/env node /** * Test Semantic Enhancement with Real MCPs * * Tests the semantic enhancement engine with 111 real tools from 24 MCPs * to validate capability inference and semantic intent resolution at scale. */ import { SemanticEnhancementEngine } from '../discovery/semantic-enhancement-engine.js'; import * as fs from 'fs/promises'; import * as path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); interface TestCase { id: string; userQuery: string; expectedCapabilities: string[]; expectedIntents: string[]; description: string; } async function testSemanticEnhancement(): Promise<void> { console.log('🧪 Testing Semantic Enhancement Engine with 111 Real Tools'); console.log('=' .repeat(60)); // Load real MCP definitions to understand what tools we have const definitionsPath = path.join(__dirname, 'real-mcp-definitions.json'); const definitionsData = await fs.readFile(definitionsPath, 'utf-8'); const definitions = JSON.parse(definitionsData); console.log(`📊 Test Data:`); console.log(` Total MCPs: ${Object.keys(definitions.mcps).length}`); console.log(` Total Tools: ${Object.values(definitions.mcps).reduce((sum: number, mcp: any) => sum + Object.keys(mcp.tools).length, 0)}`); console.log(''); const engine = new SemanticEnhancementEngine(); // Test cases covering different domains represented in our 111 tools const testCases: TestCase[] = [ { id: 'git_commit', userQuery: 'commit my changes to git', expectedCapabilities: ['version_control', 'repository_management'], expectedIntents: ['git_commit', 'save_changes'], description: 'Git/GitHub operations - should map to github tools' }, { id: 'database_query', userQuery: 'query my database for user records', expectedCapabilities: ['database_operations', 'data_retrieval'], expectedIntents: ['database_query', 'select_data'], description: 'Database operations - should map to postgres/mysql/sqlite tools' }, { id: 'file_operations', userQuery: 'read configuration files from my project', expectedCapabilities: ['file_system', 'file_operations'], expectedIntents: ['file_read', 'configuration_access'], description: 'File system operations - should map to filesystem tools' }, { id: 'send_notification', userQuery: 'send a message to my team', expectedCapabilities: ['communication', 'messaging'], expectedIntents: ['send_message', 'team_notification'], description: 'Communication - should map to slack/discord/gmail tools' }, { id: 'search_web', userQuery: 'search for information about TypeScript', expectedCapabilities: ['web_search', 'information_retrieval'], expectedIntents: ['web_search', 'find_information'], description: 'Web search - should map to brave-search tools' }, { id: 'deploy_container', userQuery: 'deploy my application using containers', expectedCapabilities: ['containerization', 'deployment'], expectedIntents: ['container_deploy', 'application_deployment'], description: 'Container operations - should map to docker/kubernetes tools' }, { id: 'manage_cloud_resources', userQuery: 'list my EC2 instances and S3 buckets', expectedCapabilities: ['cloud_infrastructure', 'resource_management'], expectedIntents: ['cloud_list', 'infrastructure_query'], description: 'Cloud operations - should map to aws/cloudflare tools' }, { id: 'process_payment', userQuery: 'process a customer payment', expectedCapabilities: ['payment_processing', 'financial_operations'], expectedIntents: ['payment_charge', 'financial_transaction'], description: 'Financial operations - should map to stripe tools' }, { id: 'schedule_meeting', userQuery: 'schedule a team meeting for next week', expectedCapabilities: ['calendar_management', 'scheduling'], expectedIntents: ['create_event', 'schedule_meeting'], description: 'Calendar operations - should map to calendar tools' }, { id: 'update_spreadsheet', userQuery: 'update the quarterly report spreadsheet', expectedCapabilities: ['spreadsheet_operations', 'document_management'], expectedIntents: ['spreadsheet_update', 'data_entry'], description: 'Productivity tools - should map to google-sheets tools' } ]; let totalTests = 0; let passedTests = 0; const results: Array<{ testCase: TestCase; enhancements: any[]; success: boolean; details: string }> = []; for (const testCase of testCases) { totalTests++; console.log(`🔍 Testing: ${testCase.description}`); console.log(` Query: "${testCase.userQuery}"`); try { // Test with a representative tool from each category const sampleTools = [ { id: 'github:create_repository', description: 'Create a new GitHub repository' }, { id: 'postgres:query', description: 'Execute SQL query on PostgreSQL database' }, { id: 'filesystem:read_file', description: 'Read file contents from filesystem' }, { id: 'slack:send_message', description: 'Send message to Slack channel' }, { id: 'brave-search:web_search', description: 'Search the web using Brave Search' }, { id: 'docker:run_container', description: 'Run Docker container' }, { id: 'aws:list_ec2_instances', description: 'List EC2 instances' }, { id: 'stripe:create_charge', description: 'Process payment charge using Stripe' }, { id: 'calendar:create_event', description: 'Create new calendar event' }, { id: 'google-sheets:write_sheet', description: 'Write data to Google Sheets' } ]; let hasRelevantEnhancements = false; let enhancementDetails = ''; for (const tool of sampleTools) { const enhancements = engine.applySemanticalEnhancement( testCase.userQuery, tool.id, tool.description ); if (enhancements.length > 0) { hasRelevantEnhancements = true; enhancementDetails += `\n ${tool.id}: ${enhancements.length} enhancements`; // Check if any expected capabilities or intents are found const hasExpectedCapability = enhancements.some(e => testCase.expectedCapabilities.some(cap => e.enhancementReason.toLowerCase().includes(cap.toLowerCase().replace('_', ' ')) ) ); const hasExpectedIntent = enhancements.some(e => testCase.expectedIntents.some(intent => e.enhancementReason.toLowerCase().includes(intent.toLowerCase().replace('_', ' ')) ) ); if (hasExpectedCapability || hasExpectedIntent) { enhancementDetails += ' ✓'; } } } if (hasRelevantEnhancements) { passedTests++; console.log(` ✅ PASS - Found relevant semantic enhancements${enhancementDetails}`); results.push({ testCase, enhancements: [], success: true, details: enhancementDetails }); } else { console.log(` ❌ FAIL - No relevant semantic enhancements found`); results.push({ testCase, enhancements: [], success: false, details: 'No enhancements found' }); } } catch (error) { console.log(` ❌ ERROR - ${(error as Error).message}`); results.push({ testCase, enhancements: [], success: false, details: `Error: ${(error as Error).message}` }); } console.log(''); } // Summary console.log('📋 Test Results Summary'); console.log('=' .repeat(40)); console.log(`Total Tests: ${totalTests}`); console.log(`Passed: ${passedTests}`); console.log(`Failed: ${totalTests - passedTests}`); console.log(`Success Rate: ${Math.round((passedTests / totalTests) * 100)}%`); console.log(''); // Performance assessment if (passedTests >= totalTests * 0.8) { console.log('🎉 EXCELLENT: Semantic enhancement is working well with 111 real tools!'); console.log(' The system successfully identifies relevant tools for various user queries.'); } else if (passedTests >= totalTests * 0.6) { console.log('✅ GOOD: Semantic enhancement shows promise with 111 real tools.'); console.log(' Some improvements may be needed for better coverage.'); } else { console.log('⚠️ NEEDS IMPROVEMENT: Semantic enhancement requires optimization.'); console.log(' Consider expanding capability inference rules or semantic mappings.'); } console.log(''); console.log('🔄 Ready for production testing with real MCP ecosystem!'); } // CLI interface if (import.meta.url === `file://${process.argv[1]}`) { testSemanticEnhancement().catch(error => { console.error('❌ Test failed:', error.message); process.exit(1); }); }

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/portel-dev/ncp'

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