test-simple.jsโข1.98 kB
// Simple HTTP-based testing using fetch (Node.js 18+ built-in)
// For older Node versions, install: npm install node-fetch
const MCP_URL = 'http://localhost:3001/mcp';
async function callTool(toolName, arguments) {
try {
const response = await fetch(MCP_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'tools/call',
params: { name: toolName, arguments },
id: Date.now()
})
});
const data = await response.json();
return data;
} catch (error) {
return { error: error.message };
}
}
async function listTools() {
try {
const response = await fetch(MCP_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'tools/list',
id: 1
})
});
const data = await response.json();
return data;
} catch (error) {
return { error: error.message };
}
}
// Run tests
async function test() {
console.log('='.repeat(50));
console.log('HTTP-based MCP Tool Testing');
console.log('='.repeat(50));
// List tools
console.log('\n๐ Listing available tools...');
const toolsList = await listTools();
console.log(JSON.stringify(toolsList, null, 2));
// Test mark_attendance
console.log('\n๐งช Testing mark_attendance...');
const result1 = await callTool('mark_attendance', {
studentId: '12345',
date: '2024-01-15',
status: 'present'
});
console.log(JSON.stringify(result1, null, 2));
// Test get_repo_info
console.log('\n๐งช Testing get_repo_info...');
const result2 = await callTool('get_repo_info', {
repoOwner: 'sadaf987',
repoName: 'test_MCP'
});
console.log(JSON.stringify(result2, null, 2));
console.log('\n' + '='.repeat(50));
console.log('Testing Complete');
console.log('='.repeat(50));
}
test().catch(console.error);