Skip to main content
Glama
portel-dev

NCP - Natural Context Provider

by portel-dev
test-multi-mcp-orchestration.cjsβ€’8.55 kB
#!/usr/bin/env node /** * Multi-MCP Orchestration Test * * This test demonstrates the TRUE powerhouse: * Scheduled CODE that orchestrates multiple MCPs internally * * Run: node tests/manual/test-multi-mcp-orchestration.cjs */ const { spawn } = require('child_process'); const readline = require('readline'); const fs = require('fs').promises; const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const colors = { reset: '\x1b[0m', bright: '\x1b[1m', green: '\x1b[32m', blue: '\x1b[34m', cyan: '\x1b[36m', yellow: '\x1b[33m', red: '\x1b[31m', magenta: '\x1b[35m', }; function log(msg, color = 'reset') { console.log(`${colors[color]}${msg}${colors.reset}`); } function header(title) { console.log('\n' + '═'.repeat(70)); log(` ${title}`, 'bright'); console.log('═'.repeat(70) + '\n'); } async function question(prompt) { return new Promise(resolve => { rl.question(`${colors.cyan}${prompt}${colors.reset} `, resolve); }); } async function main() { header('πŸš€ Multi-MCP Orchestration Demo'); log('This demo shows CODE orchestrating MULTIPLE MCPs:', 'cyan'); console.log(' β€’ analytics MCP - get system stats'); console.log(' β€’ schedule MCP - list active schedules'); console.log(' β€’ mcp MCP - list configured MCPs'); console.log(' β€’ filesystem MCP - write report file'); console.log(''); log('ALL in ONE scheduled code block!', 'green'); console.log(''); const answer = await question('Ready to see multi-MCP orchestration? (y/n)'); if (answer.toLowerCase() !== 'y') { log('Demo cancelled.', 'yellow'); rl.close(); return; } header('πŸ“ The Orchestration Code'); const orchestrationCode = ` // This code orchestrates MULTIPLE MCPs internally! // Step 1: Get analytics stats (analytics MCP) const stats = await analytics.overview({ period: 1, today: true }); // Step 2: Get active schedules (schedule MCP) const schedules = await schedule.list(); // Step 3: Get configured MCPs (mcp MCP) const mcps = await mcp.list(); // Step 4: Build comprehensive report const timestamp = new Date().toISOString(); const report = \`# NCP System Report Generated: \${timestamp} ## System Analytics \${stats} ## Active Schedules \${JSON.stringify(schedules, null, 2)} ## Configured MCPs \${JSON.stringify(mcps, null, 2)} ## Status All systems operational \`; // Step 5: Write report to file (filesystem MCP) await filesystem.write_file({ path: '/tmp/ncp-report-\${Date.now()}.md', content: report }); // Return summary return { success: true, mcps_orchestrated: 4, report_generated: true, timestamp: timestamp }; `.trim(); log('Here\'s the code that will be scheduled:', 'yellow'); console.log(''); console.log(orchestrationCode); console.log(''); log('Notice:', 'cyan'); console.log(' βœ… Calls analytics.overview() - analytics MCP'); console.log(' βœ… Calls schedule.list() - schedule MCP'); console.log(' βœ… Calls mcp.list() - mcp MCP'); console.log(' βœ… Calls filesystem.write_file() - filesystem MCP'); console.log(' βœ… All in ONE code block!'); console.log(''); const runNow = await question('Execute this code now (not scheduled yet)? (y/n)'); if (runNow.toLowerCase() !== 'y') { log('Skipping execution.', 'yellow'); rl.close(); return; } header('⚑ Executing Multi-MCP Orchestration'); log('Running code that orchestrates 4 MCPs...', 'cyan'); console.log(''); // Create a simplified version that actually works const testCode = ` const timestamp = new Date().toISOString(); // Get analytics let analyticsData = 'Getting analytics...'; try { const stats = await analytics.overview({ period: 1, today: true }); analyticsData = typeof stats === 'string' ? stats : JSON.stringify(stats); } catch (e) { analyticsData = 'Analytics unavailable: ' + e.message; } // Get schedules let schedulesData = 'Getting schedules...'; try { const scheds = await schedule.list(); schedulesData = typeof scheds === 'string' ? scheds : JSON.stringify(scheds, null, 2); } catch (e) { schedulesData = 'Schedules unavailable: ' + e.message; } // Get MCPs let mcpsData = 'Getting MCPs...'; try { const mcpList = await mcp.list(); mcpsData = typeof mcpList === 'string' ? mcpList : JSON.stringify(mcpList, null, 2); } catch (e) { mcpsData = 'MCPs unavailable: ' + e.message; } // Build report const report = \`# NCP System Report Generated: \${timestamp} ## System Analytics \${analyticsData} ## Active Schedules \${schedulesData} ## Configured MCPs \${mcpsData} ## Status Report generated successfully by orchestrating 4 MCPs! \`; // Write to file const filename = \`/tmp/ncp-report-\${Date.now()}.md\`; try { await filesystem.write_file({ path: filename, content: report }); } catch (e) { return { error: 'Failed to write file: ' + e.message, report: report }; } return { success: true, mcps_orchestrated: ['analytics', 'schedule', 'mcp', 'filesystem'], report_file: filename, timestamp: timestamp, report_preview: report.substring(0, 200) + '...' }; `; // Write code to temp file const codeFile = '/tmp/ncp-orchestration-test.js'; await fs.writeFile(codeFile, testCode); // Execute using ncp code tool log('Executing via NCP Code-Mode...', 'blue'); console.log(''); const proc = spawn('node', [ 'dist/index.js', 'run', 'ncp:code', '--code', testCode ], { cwd: process.cwd(), stdio: 'inherit' }); await new Promise((resolve, reject) => { proc.on('close', code => { if (code === 0) resolve(); else reject(new Error(`Process exited with code ${code}`)); }); }); header('πŸ“Š Results'); log('βœ… Code executed successfully!', 'green'); console.log(''); log('What happened:', 'cyan'); console.log(' 1. Called analytics.overview() β†’ got system stats'); console.log(' 2. Called schedule.list() β†’ got active schedules'); console.log(' 3. Called mcp.list() β†’ got configured MCPs'); console.log(' 4. Called filesystem.write_file() β†’ saved report'); console.log(''); log('All 4 MCPs orchestrated in ONE code execution!', 'green'); console.log(''); const checkReport = await question('Check the generated report file? (y/n)'); if (checkReport.toLowerCase() === 'y') { try { const files = await fs.readdir('/tmp'); const reportFiles = files.filter(f => f.startsWith('ncp-report-')); if (reportFiles.length > 0) { const latest = reportFiles.sort().reverse()[0]; const content = await fs.readFile(`/tmp/${latest}`, 'utf8'); console.log(''); log(`Report: /tmp/${latest}`, 'cyan'); console.log(''); console.log(content.substring(0, 500) + '...'); } } catch (e) { log('Could not read report: ' + e.message, 'yellow'); } } header('🎯 Now Schedule It!'); log('To schedule this orchestration:', 'cyan'); console.log(''); console.log('```bash'); console.log('ncp run schedule:create'); console.log('```'); console.log(''); console.log('When prompted:'); console.log(' β€’ Name: multi-mcp-report'); console.log(' β€’ Tool: ncp:code'); console.log(' β€’ Schedule: 0 9 * * * (daily at 9 AM)'); console.log(' β€’ Code: (paste the orchestration code above)'); console.log(''); log('Then it will run automatically every day!', 'green'); console.log(''); header('πŸ’‘ More Orchestration Patterns'); log('1. Backup Pipeline', 'cyan'); console.log(' filesystem.list() β†’ filesystem.read() β†’ filesystem.write() β†’ schedule.create()'); console.log(''); log('2. Health Monitoring', 'cyan'); console.log(' analytics.performance() β†’ schedule.list() β†’ mcp.doctor() β†’ schedule.pause()'); console.log(''); log('3. Auto-Healing', 'cyan'); console.log(' mcp.doctor() β†’ schedule.pause() β†’ mcp.remove() β†’ mcp.add() β†’ schedule.resume()'); console.log(''); log('4. Dynamic Scheduling', 'cyan'); console.log(' analytics.usage() β†’ schedule.list() β†’ schedule.update() (adjust frequency)'); console.log(''); header('πŸŽ‰ Demo Complete!'); log('Key Takeaway:', 'bright'); console.log(''); log(' Schedule CODE, not tools!', 'green'); log(' Code can orchestrate ANY and ALL MCPs!', 'green'); console.log(''); log(' This is the TRUE automation powerhouse! πŸš€', 'magenta'); console.log(''); rl.close(); } main().catch(error => { console.error('Test error:', error); rl.close(); 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