UNPKG

sap-b1-mcp-server

Version:

SAP Business One Service Layer MCP Server

58 lines 2.22 kB
#!/usr/bin/env bun "use strict"; /** * Health check script for Docker container * This script is used by Docker HEALTHCHECK to verify the container is healthy */ const TIMEOUT = 5000; // 5 second timeout async function healthCheck() { try { const transport = process.env.MCP_TRANSPORT || 'stdio'; if (transport === 'http' || transport === 'streaming-http') { // For HTTP transport, check the health endpoint const port = process.env.MCP_HTTP_PORT || '3000'; const host = process.env.MCP_HTTP_HOST || 'localhost'; const url = `http://${host}:${port}/health`; const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), TIMEOUT); try { const response = await fetch(url, { signal: controller.signal, headers: { 'User-Agent': 'Docker-Healthcheck' } }); clearTimeout(timeoutId); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } const data = await response.json(); if (data.status !== 'healthy') { throw new Error(`Health check failed: ${data.status}`); } console.log(`✓ ${transport} transport health check passed`); } catch (error) { clearTimeout(timeoutId); throw error; } } else { // For STDIO transport, just verify the process is running // and can load the main modules without errors const { SAPMCPServer } = await import('./index.js'); if (!SAPMCPServer) { throw new Error('Failed to load SAPMCPServer'); } console.log('✓ STDIO transport health check passed'); } process.exit(0); } catch (error) { console.error('✗ Health check failed:', error); process.exit(1); } } // Run health check healthCheck(); //# sourceMappingURL=healthcheck.js.map