test-subagents.js•4.08 kB
#!/usr/bin/env node
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
async function testSubagentDelegation() {
console.log('🤖 Testing Subagent Delegation...\n');
// Start the MCP server
const serverPath = join(__dirname, '..', 'src', 'index.js');
const server = spawn('node', [serverPath], {
stdio: ['pipe', 'pipe', 'pipe'],
env: { ...process.env, ALPHA_FEATURES: 'true' }
});
server.stderr.on('data', (data) => {
console.log('🖥️ Server:', data.toString().trim());
});
// Wait for server to start
await new Promise(resolve => setTimeout(resolve, 1000));
// Test subagent delegation
console.log('🚀 Delegating task to subagents...');
const delegateRequest = {
jsonrpc: '2.0',
id: 1,
method: 'tools/call',
params: {
name: 'delegate_to_subagents',
arguments: {
task: 'Create a simple "Hello World" application with both frontend and backend',
agents: [
{
role: 'backend_developer',
instructions: 'Create a simple Node.js server that responds with "Hello from Backend!" on port 3000'
},
{
role: 'frontend_developer',
instructions: 'Create a simple HTML page that displays "Hello from Frontend!" and can call the backend'
}
],
execution_mode: 'parallel',
working_directory: join(__dirname, '..', 'test-output')
}
}
};
server.stdin.write(JSON.stringify(delegateRequest) + '\n');
let sessionId = null;
// Capture responses
server.stdout.on('data', (data) => {
const response = data.toString().trim();
if (response) {
console.log('\n✅ Delegation Response:');
try {
const parsed = JSON.parse(response);
if (parsed.result?.content) {
const content = parsed.result.content[0]?.text;
console.log(content);
// Extract session ID if present
const sessionMatch = content.match(/Session ID: ([a-f0-9-]+)/);
if (sessionMatch) {
sessionId = sessionMatch[1];
console.log('\n📝 Captured Session ID:', sessionId);
// Check status after a delay
setTimeout(() => {
console.log('\n📊 Checking subagent status...');
const statusRequest = {
jsonrpc: '2.0',
id: 2,
method: 'tools/call',
params: {
name: 'list_active_subagents',
arguments: {}
}
};
server.stdin.write(JSON.stringify(statusRequest) + '\n');
}, 3000);
}
}
} catch (e) {
console.log('Raw response:', response.substring(0, 500) + '...');
}
}
});
// Check for results after more time
setTimeout(() => {
if (sessionId) {
console.log('\n🔍 Checking for results...');
const resultsRequest = {
jsonrpc: '2.0',
id: 3,
method: 'tools/call',
params: {
name: 'get_subagent_results',
arguments: {
session_id: sessionId
}
}
};
server.stdin.write(JSON.stringify(resultsRequest) + '\n');
}
}, 8000);
// Cleanup after 15 seconds
setTimeout(() => {
console.log('\n🧹 Test completed. Cleaning up...');
server.kill();
console.log('\n🎯 Summary:');
console.log('- MCP server: ✅ Working');
console.log('- Tool delegation: ✅ Functional');
console.log('- Subagent creation: ✅ Initiated');
console.log('\nNote: Actual Goose subagent execution depends on Goose CLI configuration and model availability.');
process.exit(0);
}, 12000);
server.on('error', (error) => {
console.error('❌ Server error:', error.message);
process.exit(1);
});
}
testSubagentDelegation().catch(console.error);