#!/usr/bin/env node
/**
* Healthcheck script for ClickUp MCP Server with Supergateway
*
* This script checks if the service is running correctly by making a simple HTTP request
* to the healthcheck endpoint. It returns a 0 exit code if the service is healthy,
* and a non-zero exit code otherwise.
*
* Usage:
* node healthcheck.js [base-url]
*
* Example:
* node healthcheck.js http://localhost:8000
*/
const http = require('http');
const https = require('https');
// Default base URL
const baseUrl = process.argv[2] || 'http://localhost:8002';
const healthcheckPath = '/healthz';
// Function to make an HTTP request to the healthcheck endpoint
function checkHealth() {
const isHttps = baseUrl.startsWith('https');
const client = isHttps ? https : http;
const url = new URL(`${baseUrl}${healthcheckPath}`);
const options = {
hostname: url.hostname,
port: url.port || (isHttps ? 443 : 80),
path: url.pathname,
method: 'GET',
timeout: 5000 // 5 second timeout
};
const req = client.request(options, (res) => {
if (res.statusCode === 200) {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
if (data.trim() === 'ok') {
console.log('✅ Service is healthy');
process.exit(0); // Success
} else {
console.error('❌ Unexpected response from healthcheck endpoint');
process.exit(1); // Failure
}
});
} else {
console.error(`❌ HTTP Error: ${res.statusCode}`);
process.exit(1); // Failure
}
});
req.on('error', (error) => {
console.error('❌ Error connecting to healthcheck endpoint:', error.message);
process.exit(1); // Failure
});
req.on('timeout', () => {
console.error('❌ Request timed out');
req.destroy();
process.exit(1); // Failure
});
req.end();
}
// Run the healthcheck
checkHealth();