feat: add version info to health check and fix healthz endpoint

- Fixed health check to use correct /healthz endpoint instead of /health
- Added MCP version (mcpVersion) and supported n8n version (supportedN8nVersion) to health check response
- Added versionNote field with instructions for AI agents about manual version verification
- n8n API limitation: instance version cannot be determined automatically
- Updated axios usage for healthz endpoint access with proper error handling
This commit is contained in:
czlonkowski
2025-07-18 14:01:11 +02:00
parent 92d1b7b273
commit a1992f9964
5 changed files with 42 additions and 638 deletions

View File

@@ -87,17 +87,32 @@ export class N8nApiClient {
// Health check to verify API connectivity
async healthCheck(): Promise<HealthCheckResponse> {
try {
// First try the health endpoint
const response = await this.client.get('/health');
return response.data;
// Try the standard healthz endpoint (available on all n8n instances)
const baseUrl = this.client.defaults.baseURL || '';
const healthzUrl = baseUrl.replace(/\/api\/v\d+\/?$/, '') + '/healthz';
const response = await axios.get(healthzUrl, {
timeout: 5000,
validateStatus: (status) => status < 500
});
if (response.status === 200 && response.data?.status === 'ok') {
return {
status: 'ok',
features: {} // Features detection would require additional endpoints
};
}
// If healthz doesn't work, fall back to API check
throw new Error('healthz endpoint not available');
} catch (error) {
// If health endpoint doesn't exist, try listing workflows with limit 1
// If healthz endpoint doesn't exist, try listing workflows with limit 1
// This is a fallback for older n8n versions
try {
await this.client.get('/workflows', { params: { limit: 1 } });
return {
status: 'ok',
features: {} // We can't determine features without proper health endpoint
features: {}
};
} catch (fallbackError) {
throw handleN8nApiError(fallbackError);