test-connection.jsā¢3.77 kB
// Simple test to check if MCP server is accessible
const http = require('http');
function makeRequest(method, params = {}) {
return new Promise((resolve, reject) => {
const data = JSON.stringify({
jsonrpc: '2.0',
id: Math.floor(Math.random() * 10000),
method,
params
});
const options = {
hostname: 'localhost',
port: 3100,
path: '/',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
};
const req = http.request(options, (res) => {
let body = '';
res.on('data', (chunk) => {
body += chunk;
});
res.on('end', () => {
try {
const response = JSON.parse(body);
resolve(response);
} catch (error) {
reject(new Error('Invalid JSON response'));
}
});
});
req.on('error', (error) => {
reject(error);
});
req.write(data);
req.end();
});
}
async function testConnection() {
try {
console.log('š Testing connection to MCP HTTP server at http://localhost:3100...\n');
// Test health endpoint
const healthCheck = new Promise((resolve, reject) => {
http.get('http://localhost:3100', (res) => {
let body = '';
res.on('data', (chunk) => { body += chunk; });
res.on('end', () => {
try {
const data = JSON.parse(body);
console.log('ā
Health check passed:', data);
resolve(data);
} catch (error) {
reject(error);
}
});
}).on('error', reject);
});
await healthCheck;
// Send initialize request
console.log('\nš¤ Sending initialize request...');
const initResponse = await makeRequest('initialize', {});
console.log('š„ Initialize response:', JSON.stringify(initResponse, null, 2));
// Send tools/list request
console.log('\nš¤ Sending tools/list request...');
const toolsResponse = await makeRequest('tools/list', {});
console.log('š„ Tools response:');
console.log('\nā
Available tools:', toolsResponse.result.tools.length);
toolsResponse.result.tools.forEach(tool => {
console.log(` - ${tool.name}: ${tool.description}`);
});
console.log('\nā
Test complete! MCP HTTP server is working correctly.');
process.exit(0);
} catch (error) {
console.error('\nā Connection error:', error.message);
console.log('\nā ļø Extension may not be activated yet.');
console.log(' To activate:');
console.log(' 1. Open VSCode');
console.log(' 2. Press Ctrl+Shift+P');
console.log(' 3. Run "Developer: Reload Window"');
console.log(' 4. Check status bar for "MCP LS:3100"');
process.exit(1);
}
}
// Timeout after 5 seconds
setTimeout(() => {
console.error('ā Connection timeout');
console.log('\nā ļø Extension is not running. Steps to activate:');
console.log(' 1. Open VSCode');
console.log(' 2. Press Ctrl+Shift+P');
console.log(' 3. Run "Developer: Reload Window"');
console.log(' 4. Check status bar (bottom-right) for "MCP LS:3100"');
console.log(' 5. If not showing, run "VSCode MCP LS: Show Status"');
process.exit(1);
}, 5000);
testConnection();