#!/usr/bin/env node
const SERVER_URL = process.argv[2] || 'http://localhost:3000';
const MCP_ENDPOINT = `${SERVER_URL}/mcp`;
console.log(`🧪 Testing MCP HTTP transport at ${MCP_ENDPOINT}\n`);
async function testMcpServer() {
try {
// Test 1: List tools
console.log('1️⃣ Testing tools/list...');
const listResponse = await fetch(MCP_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'tools/list'
})
});
const listResult = await listResponse.json();
console.log('✓ Tools available:', listResult.result?.tools?.map(t => t.name).join(', ') || 'None');
// Test 2: Echo tool
console.log('\n2️⃣ Testing echo tool...');
const echoResponse = await fetch(MCP_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 2,
method: 'tools/call',
params: {
name: 'echo',
arguments: {
message: 'Hello from HTTP client!'
}
}
})
});
const echoResult = await echoResponse.json();
console.log('✓ Echo response:', echoResult.result?.content?.[0]?.text || 'No response');
// Test 3: Get current time
console.log('\n3️⃣ Testing get-current-time tool...');
const timeResponse = await fetch(MCP_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 3,
method: 'tools/call',
params: {
name: 'get-current-time',
arguments: {}
}
})
});
const timeResult = await timeResponse.json();
console.log('✓ Time response:', timeResult.result?.content?.[0]?.text || 'No response');
// Test 4: Calculator
console.log('\n4️⃣ Testing calculate tool...');
const calcResponse = await fetch(MCP_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 4,
method: 'tools/call',
params: {
name: 'calculate',
arguments: {
expression: '15 * 4 + 10'
}
}
})
});
const calcResult = await calcResponse.json();
console.log('✓ Calculation result:', calcResult.result?.content?.[0]?.text || 'No response');
console.log('\n🎉 All HTTP tests passed!');
} catch (error) {
console.error('❌ Test failed:', error.message);
process.exit(1);
}
}
testMcpServer();