test-tools.jsโข6.34 kB
#!/usr/bin/env node
// Comprehensive tool testing for Worksona MCP Server
const { spawn } = require('child_process');
const path = require('path');
console.log('๐ง Testing Worksona MCP Server Tools...\n');
const serverPath = path.join(__dirname, 'dist', 'index.js');
const server = spawn('node', [serverPath], {
stdio: ['pipe', 'pipe', 'pipe']
});
let responses = [];
let requestId = 1;
server.stdout.on('data', (data) => {
const lines = data.toString().split('\n').filter(line => line.trim());
lines.forEach(line => {
try {
const response = JSON.parse(line);
if (response.jsonrpc) {
responses.push(response);
}
} catch (e) {
// Not JSON, probably server logs
console.log('Server:', line);
}
});
});
server.stderr.on('data', (data) => {
console.log('Server Error:', data.toString().trim());
});
// Wait for server to initialize
setTimeout(async () => {
console.log('๐ Server initialized, starting tool tests...\n');
try {
// Test 1: Initialize
console.log('๐ Test 1: Initialize Protocol');
await sendRequest({
jsonrpc: '2.0',
id: requestId++,
method: 'initialize',
params: {}
});
// Test 2: List Tools
console.log('๐ Test 2: List Available Tools');
await sendRequest({
jsonrpc: '2.0',
id: requestId++,
method: 'tools/list',
params: {}
});
// Test 3: List Agents
console.log('๐ Test 3: List Agents Tool');
await sendRequest({
jsonrpc: '2.0',
id: requestId++,
method: 'tools/call',
params: {
name: 'list_agents',
arguments: { category: 'software-engineering' }
}
});
// Test 4: Suggest Agents
console.log('๐ Test 4: Suggest Agents Tool');
await sendRequest({
jsonrpc: '2.0',
id: requestId++,
method: 'tools/call',
params: {
name: 'suggest_agents',
arguments: {
request: 'help with React development',
max_suggestions: 3
}
}
});
// Test 5: Activate Agent
console.log('๐ Test 5: Activate Agent Tool');
await sendRequest({
jsonrpc: '2.0',
id: requestId++,
method: 'tools/call',
params: {
name: 'activate_agent',
arguments: {
agent_name: 'frontend-developer',
request: 'Create a simple React button component'
}
}
});
// Wait for all responses and analyze
setTimeout(() => {
analyzeResults();
}, 2000);
} catch (error) {
console.error('โ Test error:', error);
server.kill();
}
}, 3000);
function sendRequest(request) {
return new Promise((resolve) => {
server.stdin.write(JSON.stringify(request) + '\n');
setTimeout(resolve, 500); // Give time for response
});
}
function analyzeResults() {
console.log('\n' + '='.repeat(60));
console.log('๐ Analyzing Test Results...\n');
let testsPassed = 0;
let totalTests = 5;
// Check initialize response
const initResponse = responses.find(r => r.id === 1);
if (initResponse && initResponse.result && initResponse.result.serverInfo) {
console.log('โ
Test 1 - Initialize: PASSED');
console.log(` Server: ${initResponse.result.serverInfo.name} v${initResponse.result.serverInfo.version}`);
testsPassed++;
} else {
console.log('โ Test 1 - Initialize: FAILED');
}
// Check tools list response
const toolsResponse = responses.find(r => r.id === 2);
if (toolsResponse && toolsResponse.result && toolsResponse.result.tools) {
const tools = toolsResponse.result.tools;
console.log(`โ
Test 2 - List Tools: PASSED (${tools.length} tools available)`);
tools.forEach(tool => console.log(` - ${tool.name}: ${tool.description}`));
testsPassed++;
} else {
console.log('โ Test 2 - List Tools: FAILED');
}
// Check list agents response
const listAgentsResponse = responses.find(r => r.id === 3);
if (listAgentsResponse && listAgentsResponse.result && listAgentsResponse.result.content) {
console.log('โ
Test 3 - List Agents: PASSED');
testsPassed++;
} else {
console.log('โ Test 3 - List Agents: FAILED');
}
// Check suggest agents response
const suggestResponse = responses.find(r => r.id === 4);
if (suggestResponse && suggestResponse.result && suggestResponse.result.content) {
console.log('โ
Test 4 - Suggest Agents: PASSED');
testsPassed++;
} else {
console.log('โ Test 4 - Suggest Agents: FAILED');
}
// Check activate agent response
const activateResponse = responses.find(r => r.id === 5);
if (activateResponse && activateResponse.result && activateResponse.result.content) {
console.log('โ
Test 5 - Activate Agent: PASSED');
const content = activateResponse.result.content[0].text;
if (content.includes('Frontend Developer') || content.includes('frontend-developer')) {
console.log(' Agent activation working correctly');
}
testsPassed++;
} else {
console.log('โ Test 5 - Activate Agent: FAILED');
}
// Final results
console.log('\n' + '='.repeat(60));
console.log('๐งช Tool Test Results:');
console.log(`โ
Passed: ${testsPassed}/${totalTests} tests`);
console.log(`๐ Success Rate: ${Math.round((testsPassed/totalTests) * 100)}%`);
if (testsPassed === totalTests) {
console.log('\n๐ All tool tests passed! MCP server is fully functional.');
console.log('\n๐ Claude Desktop Configuration:');
console.log('Add this to ~/.claude-desktop/config.json:');
console.log(JSON.stringify({
"mcpServers": {
"worksona-agents": {
"command": "node",
"args": [`${__dirname}/dist/index.js`],
"cwd": __dirname
}
}
}, null, 2));
} else {
console.log('\nโ ๏ธ Some tests failed. Check the MCP protocol implementation.');
}
server.kill();
process.exit(testsPassed === totalTests ? 0 : 1);
}
// Handle server exit
server.on('close', (code) => {
if (code !== null && code !== 0 && code !== 143) { // 143 is SIGTERM
console.log(`โ Server exited with code ${code}`);
}
});
// Cleanup on script exit
process.on('SIGINT', () => {
console.log('\nโ ๏ธ Test interrupted');
server.kill();
process.exit(1);
});