#!/usr/bin/env node
/**
* Test script for ClickUp MCP Server with Supergateway
*
* This script tests the connection to the ClickUp MCP server through Supergateway
* by connecting to the SSE endpoint and sending a simple request to list available tools.
*
* Usage:
* node test-connection.js [base-url]
*
* Example:
* node test-connection.js http://localhost:8002
*/
const http = require('http');
const https = require('https');
const { EventSource } = require('eventsource');
const { v4: uuidv4 } = require('uuid');
// Default base URL
const baseUrl = process.argv[2] || 'http://localhost:8002';
const ssePath = '/sse';
const messagePath = '/message';
console.log(`Testing connection to ${baseUrl}...`);
// Create EventSource for SSE endpoint
const es = new EventSource(`${baseUrl}${ssePath}`);
// Handle SSE connection open
es.onopen = () => {
console.log('✅ Connected to SSE endpoint');
console.log('Sending request to list available tools...');
// Send a request to list tools
sendRequest({
jsonrpc: '2.0',
method: 'mcp.tools.list',
params: {},
id: uuidv4()
});
};
// Handle SSE messages
es.onmessage = (event) => {
try {
const data = JSON.parse(event.data);
console.log('\n📩 Received message:');
console.log(JSON.stringify(data, null, 2));
// Check if this is a response to our request
if (data.result && data.result.tools) {
console.log(`\n✅ Successfully received ${data.result.tools.length} tools from the ClickUp MCP server`);
console.log('Tool names:');
data.result.tools.forEach(tool => {
console.log(`- ${tool.name}`);
});
// Close the connection after receiving the response
console.log('\nTest completed successfully! The integration is working correctly.');
es.close();
process.exit(0);
}
} catch (error) {
console.error('Error parsing message:', error);
}
};
// Handle SSE errors
es.onerror = (error) => {
console.error('❌ Error connecting to SSE endpoint:', error);
es.close();
process.exit(1);
};
// Function to send a request to the message endpoint
function sendRequest(data) {
const isHttps = baseUrl.startsWith('https');
const client = isHttps ? https : http;
const url = new URL(`${baseUrl}${messagePath}`);
const options = {
hostname: url.hostname,
port: url.port || (isHttps ? 443 : 80),
path: url.pathname,
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
};
const req = client.request(options, (res) => {
if (res.statusCode !== 200) {
console.error(`❌ HTTP Error: ${res.statusCode}`);
es.close();
process.exit(1);
}
res.on('data', (chunk) => {
// We don't need to do anything with the response data
// as we'll receive the response via SSE
});
});
req.on('error', (error) => {
console.error('❌ Error sending request:', error);
es.close();
process.exit(1);
});
req.write(JSON.stringify(data));
req.end();
}