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
| Name | Required | Description | Default |
|---|---|---|---|
| alias | Yes | Alias de l'API à tester. | |
| server_alias | Yes | Alias du serveur depuis lequel lancer le test. |
Implementation Reference
- server.js:181-227 (registration)Registration of the 'api_check' tool using server.registerTool, including 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 }; } } );
- server.js:191-226 (handler)Inline handler function implementing the core logic: retrieves API configuration, constructs curl command with authentication handling, queues and executes SSH job on specified server, waits for result, parses health output using ssh.parseApiHealth.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 }; } }
- server.js:186-189 (schema)Zod inputSchema defining required parameters: alias (API alias) and server_alias (remote server for test).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.") })
- ssh.js:469-519 (helper)parseApiHealth helper function parses curl -w output to extract HTTP status code and response time in ms, determining UP/DOWN status.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 }; } }
- apis.js:77-84 (helper)getApi helper retrieves the configuration of a specific API by alias from the stored apis.json.async function getApi(alias) { await ensureInitialized(); const apiConfig = apis[alias]; if (!apiConfig) { throw new Error(`L'alias d'API '${alias}' est inconnu.`); } return apiConfig; }