endpoint-health
Check the health and operational status of a serverless endpoint, including worker counts and job statistics, to monitor performance and availability.
Instructions
Get the health and operational status of a Serverless endpoint, including worker counts and job statistics.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| endpointId | Yes | ID of the Serverless endpoint to check health for |
Implementation Reference
- src/index.ts:1019-1038 (registration)Registration of the 'endpoint-health' tool via server.tool() on the MCP server. Defines tool name, description, input schema (endpointId), and handler.
// Endpoint Health server.tool( 'endpoint-health', 'Get the health and operational status of a Serverless endpoint, including worker counts and job statistics.', { endpointId: endpointIdSchema.describe('ID of the Serverless endpoint to check health for'), }, async (params) => { const result = await serverlessRequest(params.endpointId, '/health'); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } ); - src/index.ts:1026-1037 (handler)Handler function for endpoint-health tool. Calls serverlessRequest with the given endpointId and '/health' path, returns the JSON result as text content.
async (params) => { const result = await serverlessRequest(params.endpointId, '/health'); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } - src/index.ts:747-749 (schema)Zod schema for endpointId, a string matching alphanumeric characters, hyphens, and underscores.
const endpointIdSchema = z .string() .regex(/^[a-zA-Z0-9_-]+$/, 'Invalid endpoint ID format'); - src/index.ts:277-318 (helper)Helper function that makes authenticated HTTP requests to the RunPod Serverless API. Used by endpoint-health to call the /health endpoint.
async function serverlessRequest( endpointId: string, path: string, method: string = 'GET', body?: Record<string, unknown> ) { const url = `${SERVERLESS_API_BASE_URL}/${endpointId}${path}`; const headers: Record<string, string> = { Authorization: `Bearer ${API_KEY}`, 'Content-Type': 'application/json', }; const options: NodeFetchRequestInit = { method, headers, }; if (body && (method === 'POST' || method === 'PATCH')) { options.body = JSON.stringify(body); } try { const response = await fetch(url, options); if (!response.ok) { const errorText = await response.text(); throw new Error( `RunPod Serverless API Error: ${response.status} - ${errorText}` ); } const contentType = response.headers.get('content-type'); if (contentType && contentType.includes('application/json')) { return await response.json(); } return { success: true, status: response.status }; } catch (error) { console.error('Error calling RunPod Serverless API:', error); throw error; } }