stop-pod
Stop a running pod on RunPod to manage resources and control costs. Provide the pod ID to halt execution.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| podId | Yes | ID of the pod to stop |
Implementation Reference
- src/index.ts:283-294 (handler)The handler function for the 'stop-pod' tool. It takes a podId parameter, makes a POST request to the RunPod API endpoint `/pods/{podId}/stop` using the runpodRequest helper, and returns the JSON response as text content.async (params) => { const result = await runpodRequest(`/pods/${params.podId}/stop`, 'POST'); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
- src/index.ts:280-282 (schema)The input schema for the 'stop-pod' tool, defining the required 'podId' parameter as a string.{ podId: z.string().describe('ID of the pod to stop'), },
- src/index.ts:278-295 (registration)The registration of the 'stop-pod' tool on the MCP server using server.tool(), specifying name, input schema, and handler function.server.tool( 'stop-pod', { podId: z.string().describe('ID of the pod to stop'), }, async (params) => { const result = await runpodRequest(`/pods/${params.podId}/stop`, 'POST'); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } );
- src/index.ts:27-66 (helper)The runpodRequest helper function used by the 'stop-pod' handler (and other tools) to make authenticated HTTP requests to the RunPod API.async function runpodRequest( endpoint: string, method: string = 'GET', body?: Record<string, unknown> ) { const url = `${API_BASE_URL}${endpoint}`; const headers = { 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 API Error: ${response.status} - ${errorText}`); } // Some endpoints might not return JSON 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 API:', error); throw error; } }