Skip to main content
Glama

check_api_health

Monitor HTTP/S endpoint availability and response time from remote servers to verify API health status.

Instructions

Vérifie la disponibilité et le temps de réponse d'un endpoint HTTP/S.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
aliasYesAlias du serveur depuis lequel lancer le test.
urlYesURL complète de l'endpoint à tester.

Implementation Reference

  • The main handler function that implements the check_api_health tool. It runs a curl command via SSH on the specified server to test the API endpoint's availability and response time, parses the result using ssh.parseApiHealth, and returns formatted JSON 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 }; } }
  • Zod input schema defining parameters: 'alias' for server alias and 'url' for the HTTP endpoint 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 using server.registerTool, including title, description, schema, and handler function.
    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 }; } } );
  • Helper function parseApiHealth parses the output from the curl command to extract HTTP status code and response time in ms, determining if the API is 'UP' or 'DOWN', with comprehensive error handling.
    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 }; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/fkom13/mcp-sftp-orchestrator'

If you have feedback or need assistance with the MCP directory API, please join our Discord server