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

@@ -758,6 +758,11 @@ export async function handleHealthCheck(): Promise<McpToolResponse> {
const client = ensureApiConfigured();
const health = await client.healthCheck();
// Get MCP version from package.json
const packageJson = require('../../package.json');
const mcpVersion = packageJson.version;
const supportedN8nVersion = packageJson.dependencies?.n8n?.replace(/[^0-9.]/g, '');
return {
success: true,
data: {
@@ -765,7 +770,10 @@ export async function handleHealthCheck(): Promise<McpToolResponse> {
instanceId: health.instanceId,
n8nVersion: health.n8nVersion,
features: health.features,
apiUrl: getN8nApiConfig()?.baseUrl
apiUrl: getN8nApiConfig()?.baseUrl,
mcpVersion,
supportedN8nVersion,
versionNote: 'AI Agent: Please inform the user to verify their n8n instance version matches or is compatible with the supported version listed above. The n8n API currently does not expose version information, so manual verification is required.'
}
};
} catch (error) {

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);