check_api_health
Monitor HTTP/S endpoint availability and response time from a remote server to ensure API reliability and performance.
Instructions
Vérifie la disponibilité et le temps de réponse d'un endpoint HTTP/S.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| alias | Yes | Alias du serveur depuis lequel lancer le test. | |
| url | Yes | URL complète de l'endpoint à tester. |
Implementation Reference
- server.js:313-338 (handler)Handler function that queues an SSH job to run curl on the remote server to check the HTTP status and response time of the given URL, parses the result using ssh.parseApiHealth, and returns structured output or error.async (params) => { try { const cmd = `curl -o /dev/null -s -w '%{http_code}:%{time_total}' ${params.url}`; const job = queue.addJob({ type: 'ssh', alias: params.alias, cmd: cmd }); ssh.executeCommand(job.id); const result = await waitForJobCompletion(job.id, config.syncTimeout); if (!result || result.status !== 'completed') { throw new Error(result ? result.error : `Timeout de la commande de monitoring pour ${params.alias}`); } const parsedOutput = ssh.parseApiHealth(result.output); return { content: [{ type: "text", text: JSON.stringify(parsedOutput, null, 2) }] }; } catch (e) { const errorPayload = { toolName: "check_api_health", errorCode: "MONITORING_ERROR", errorMessage: e.message }; return { content: [{ type: "text", text: JSON.stringify(errorPayload, null, 2) }], isError: true }; } }
- server.js:308-311 (schema)Input schema defining parameters: alias (server alias for SSH) and url (full URL to check).inputSchema: z.object({ alias: z.string().describe("Alias du serveur depuis lequel lancer le test."), url: z.string().url().describe("URL complète de l'endpoint à tester.") })
- server.js:303-339 (registration)Registration of the check_api_health tool with MCP server, including title, description, input schema, and handler reference.server.registerTool( "check_api_health", { title: "Vérifier la santé d'une API", description: "Vérifie la disponibilité et le temps de réponse d'un endpoint HTTP/S.", inputSchema: z.object({ alias: z.string().describe("Alias du serveur depuis lequel lancer le test."), url: z.string().url().describe("URL complète de l'endpoint à tester.") }) }, async (params) => { try { const cmd = `curl -o /dev/null -s -w '%{http_code}:%{time_total}' ${params.url}`; const job = queue.addJob({ type: 'ssh', alias: params.alias, cmd: cmd }); ssh.executeCommand(job.id); const result = await waitForJobCompletion(job.id, config.syncTimeout); if (!result || result.status !== 'completed') { throw new Error(result ? result.error : `Timeout de la commande de monitoring pour ${params.alias}`); } const parsedOutput = ssh.parseApiHealth(result.output); return { content: [{ type: "text", text: JSON.stringify(parsedOutput, null, 2) }] }; } catch (e) { const errorPayload = { toolName: "check_api_health", errorCode: "MONITORING_ERROR", errorMessage: e.message }; return { content: [{ type: "text", text: JSON.stringify(errorPayload, null, 2) }], isError: true }; } } );
- ssh.js:469-519 (helper)Helper function to parse the curl output from health checks into structured data: status (UP/DOWN/ERROR), http_code, response_time_ms.function parseApiHealth(output) { if (!output || typeof output !== 'string') { return { status: 'ERROR', http_code: 0, response_time_ms: 0, error: 'Sortie invalide ou vide' }; } try { const parts = output.trim().split(':'); if (parts.length !== 2) { return { status: 'ERROR', http_code: 0, response_time_ms: 0, error: 'Format de réponse invalide', raw_output: output }; } const [codeStr, timeStr] = parts; const http_code = parseInt(codeStr, 10); const response_time_ms = parseFloat(timeStr) * 1000; if (isNaN(http_code) || isNaN(response_time_ms)) { return { status: 'ERROR', http_code: 0, response_time_ms: 0, error: 'Valeurs non numériques', raw_output: output }; } return { status: http_code >= 200 && http_code < 300 ? 'UP' : 'DOWN', http_code: http_code, response_time_ms: Math.round(response_time_ms) }; } catch (e) { return { status: 'ERROR', http_code: 0, response_time_ms: 0, error: e.message, raw_output: output }; } }