simple-test.js•3.3 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 testMCPServer() {
console.log('🚀 Testing MCP Goose Subagents Server...\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 1: List available tools
console.log('📋 Test 1: Listing available tools...');
const listToolsRequest = {
jsonrpc: '2.0',
id: 1,
method: 'tools/list'
};
server.stdin.write(JSON.stringify(listToolsRequest) + '\n');
// Test 2: Create a recipe
setTimeout(() => {
console.log('\n🧪 Test 2: Creating a test recipe...');
const createRecipeRequest = {
jsonrpc: '2.0',
id: 2,
method: 'tools/call',
params: {
name: 'create_goose_recipe',
arguments: {
recipe_name: 'simple-tester',
role: 'test_engineer',
instructions: 'You are a test engineer who writes simple tests',
extensions: ['developer']
}
}
};
server.stdin.write(JSON.stringify(createRecipeRequest) + '\n');
}, 2000);
// Test 3: List active subagents
setTimeout(() => {
console.log('\n📊 Test 3: Listing active subagents...');
const listSubagentsRequest = {
jsonrpc: '2.0',
id: 3,
method: 'tools/call',
params: {
name: 'list_active_subagents',
arguments: {}
}
};
server.stdin.write(JSON.stringify(listSubagentsRequest) + '\n');
}, 4000);
// Capture responses
let responseCount = 0;
server.stdout.on('data', (data) => {
const response = data.toString().trim();
if (response) {
responseCount++;
console.log(`\n✅ Response ${responseCount}:`);
try {
const parsed = JSON.parse(response);
if (parsed.result?.tools) {
console.log(' Available tools:', parsed.result.tools.map(t => t.name).join(', '));
} else if (parsed.result?.content) {
console.log(' Content:', parsed.result.content[0]?.text?.substring(0, 200) + '...');
} else {
console.log(' Raw response:', JSON.stringify(parsed, null, 2).substring(0, 300) + '...');
}
} catch (e) {
console.log(' Raw data:', response.substring(0, 200) + '...');
}
}
});
// Cleanup after 10 seconds
setTimeout(() => {
console.log('\n🧹 Cleaning up...');
server.kill();
if (responseCount > 0) {
console.log('🎉 MCP server is working! Received', responseCount, 'responses.');
} else {
console.log('⚠️ No responses received. Check server logs above.');
}
process.exit(0);
}, 8000);
server.on('error', (error) => {
console.error('❌ Server error:', error.message);
process.exit(1);
});
}
testMCPServer().catch(console.error);