test-session-issue.js•1.23 kB
// Test script to verify session ID handling
import http from 'http';
const SESSION_ID = 'test-session-123';
// Test 1: Send a request with a session ID
function testWithSessionId() {
const postData = JSON.stringify({
jsonrpc: '2.0',
method: 'mcp.list_tools',
params: {},
id: 1
});
const options = {
hostname: 'localhost',
port: 5002,
path: '/mcp',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json, text/event-stream',
'Content-Length': Buffer.byteLength(postData),
'mcp-session-id': SESSION_ID,
'Connection': 'close'
}
};
console.log('Sending request with session ID:', SESSION_ID);
const req = http.request(options, (res) => {
console.log(`\nResponse status: ${res.statusCode}`);
console.log('Response headers:', JSON.stringify(res.headers, null, 2));
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log('Response body:', data);
});
});
req.on('error', (error) => {
console.error('Request error:', error);
});
req.write(postData);
req.end();
}
// Run the test
testWithSessionId();