Skip to main content
Glama

api_check

Test API health status from the catalog to verify connectivity and functionality using the MCP SFTP Orchestrator server.

Instructions

Lance un test de santé sur une API du catalogue.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
aliasYesAlias de l'API à tester.
server_aliasYesAlias du serveur depuis lequel lancer le test.

Implementation Reference

  • The handler function for the 'api_check' tool. It retrieves the API configuration, builds a customized curl command for the health check endpoint (supporting GET/POST, htpasswd, API key auth), executes it remotely via SSH on the specified server using the queue system, parses the HTTP code and response time, and returns a structured result.
    async (params) => { try { const apiConfig = await apis.getApi(params.alias); const endpoint = apiConfig.health_check_endpoint || ''; const url = `${apiConfig.url}${endpoint}`; const method = apiConfig.health_check_method || 'GET'; let curlCmd = `curl -X ${method} -o /dev/null -s -w '%{http_code}:%{time_total}'`; // Gérer l'authentification htpasswd if ((apiConfig.auth_method === 'htpasswd' || apiConfig.auth_method === 'both') && apiConfig.htpasswd_user && apiConfig.htpasswd_pass) { curlCmd += ` -u ${apiConfig.htpasswd_user}:${apiConfig.htpasswd_pass}`; } // Gérer l'authentification par clé API if ((apiConfig.auth_method === 'api_key' || apiConfig.auth_method === 'both') && apiConfig.api_key) { const scheme = apiConfig.auth_scheme ? `${apiConfig.auth_scheme} ` : ''; curlCmd += ` -H '${apiConfig.auth_header_name || 'Authorization'}: ${scheme}${apiConfig.api_key}'`; } curlCmd += ` ${url}`; const job = queue.addJob({ type: 'ssh', alias: params.server_alias, cmd: curlCmd }); 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) { return { content: [{ type: "text", text: `ERREUR: ${e.message}` }], isError: true }; } }
  • Zod schema defining the input parameters: 'alias' (string, API alias to test) and 'server_alias' (string, server alias from which to run the curl command).
    inputSchema: z.object({ alias: z.string().describe("Alias de l'API à tester."), server_alias: z.string().describe("Alias du serveur depuis lequel lancer le test.") })
  • server.js:181-227 (registration)
    The server.registerTool call that registers the 'api_check' tool with the MCP server, including name, metadata (title, description), input schema, and inline handler function.
    server.registerTool( "api_check", { title: "Vérifier la santé d'une API via son alias", description: "Lance un test de santé sur une API du catalogue.", inputSchema: z.object({ alias: z.string().describe("Alias de l'API à tester."), server_alias: z.string().describe("Alias du serveur depuis lequel lancer le test.") }) }, async (params) => { try { const apiConfig = await apis.getApi(params.alias); const endpoint = apiConfig.health_check_endpoint || ''; const url = `${apiConfig.url}${endpoint}`; const method = apiConfig.health_check_method || 'GET'; let curlCmd = `curl -X ${method} -o /dev/null -s -w '%{http_code}:%{time_total}'`; // Gérer l'authentification htpasswd if ((apiConfig.auth_method === 'htpasswd' || apiConfig.auth_method === 'both') && apiConfig.htpasswd_user && apiConfig.htpasswd_pass) { curlCmd += ` -u ${apiConfig.htpasswd_user}:${apiConfig.htpasswd_pass}`; } // Gérer l'authentification par clé API if ((apiConfig.auth_method === 'api_key' || apiConfig.auth_method === 'both') && apiConfig.api_key) { const scheme = apiConfig.auth_scheme ? `${apiConfig.auth_scheme} ` : ''; curlCmd += ` -H '${apiConfig.auth_header_name || 'Authorization'}: ${scheme}${apiConfig.api_key}'`; } curlCmd += ` ${url}`; const job = queue.addJob({ type: 'ssh', alias: params.server_alias, cmd: curlCmd }); 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) { return { content: [{ type: "text", text: `ERREUR: ${e.message}` }], isError: true }; } } );
  • Helper function ssh.parseApiHealth parses the curl output (format 'HTTP_CODE:time_total') into a structured object with status ('UP'/'DOWN'/'ERROR'), http_code, response_time_ms, handling errors gracefully. Exported from ssh.js and used in the api_check handler.
    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