VPS_stopVirtualMachineV1
Stop a virtual machine by providing its ID. This powers off running VPS instances.
Instructions
Stop a specified virtual machine.
If the virtual machine is already stopped, the request will still be processed without any effect.
Use this endpoint to power off running VPS instances.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| virtualMachineId | Yes | Virtual Machine ID |
Implementation Reference
- src/core/tools/vps.js:1792-1825 (schema)Schema/definition for VPS_stopVirtualMachineV1 tool. It defines a POST request to /api/vps/v1/virtual-machines/{virtualMachineId}/stop with a required virtualMachineId (integer) input parameter.
{ "name": "VPS_stopVirtualMachineV1", "description": "Stop a specified virtual machine.\n\nIf the virtual machine is already stopped, the request will still be processed without any effect.\n\nUse this endpoint to power off running VPS instances.", "method": "POST", "path": "/api/vps/v1/virtual-machines/{virtualMachineId}/stop", "inputSchema": { "type": "object", "properties": { "virtualMachineId": { "type": "integer", "description": "Virtual Machine ID" } }, "required": [ "virtualMachineId" ] }, "security": [ { "apiToken": [] } ], "group": "vps" } ]; - src/core/tools/vps.ts:1802-1825 (schema)TypeScript type definition/schema for VPS_stopVirtualMachineV1 tool. Same definition as the JS counterpart.
{ "name": "VPS_stopVirtualMachineV1", "description": "Stop a specified virtual machine.\n\nIf the virtual machine is already stopped, the request will still be processed without any effect.\n\nUse this endpoint to power off running VPS instances.", "method": "POST", "path": "/api/vps/v1/virtual-machines/{virtualMachineId}/stop", "inputSchema": { "type": "object", "properties": { "virtualMachineId": { "type": "integer", "description": "Virtual Machine ID" } }, "required": [ "virtualMachineId" ] }, "security": [ { "apiToken": [] } ], "group": "vps" } - src/core/runtime.js:1879-1966 (handler)The actual execution handler for VPS_stopVirtualMachineV1. Since this tool is not marked as 'custom', it is executed via the generic executeApiCall method. The method takes the tool's POST method and path (/api/vps/v1/virtual-machines/{virtualMachineId}/stop), substitutes {virtualMachineId} from params, and makes an HTTP POST request to the Hostinger API.
async executeApiCall(tool, params) { // Get method and path from tool const method = tool.method; let path = tool.path; // Clone params to avoid modifying the original const requestParams = { ...params }; // Replace path parameters with values from params Object.entries(requestParams).forEach(([key, value]) => { const placeholder = `{${key}}`; if (path.includes(placeholder)) { path = path.replace(placeholder, encodeURIComponent(String(value))); delete requestParams[key]; // Remove used parameter } }); // Build the full URL const baseUrl = this.baseUrl.endsWith("/") ? this.baseUrl : `${this.baseUrl}/`; const cleanPath = path.startsWith("/") ? path.slice(1) : path; const url = new URL(cleanPath, baseUrl).toString(); this.log('debug', `API Request: ${method} ${url}`); try { // Configure the request const config = { method: method.toLowerCase(), url, headers: { ...this.headers }, timeout: 60000, // 60s validateStatus: function (status) { return status < 500; // Resolve only if the status code is less than 500 } }; const bearerToken = process.env['API_TOKEN'] || process.env['APITOKEN']; // APITOKEN for backwards compatibility if (bearerToken) { config.headers['Authorization'] = `Bearer ${bearerToken}`; } else { this.log('error', `Bearer Token environment variable not found: API_TOKEN`); } // Add parameters based on request method if (["GET", "DELETE"].includes(method)) { // For GET/DELETE, send params as query string config.params = { ...(config.params || {}), ...requestParams }; } else { // For POST/PUT/PATCH, send params as JSON body config.data = requestParams; config.headers["Content-Type"] = "application/json"; } this.log('debug', "Request config:", { url: config.url, method: config.method, params: config.params, headers: Object.keys(config.headers) }); // Execute the request const response = await axios(config); this.log('debug', `Response status: ${response.status}`); return response.data; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); this.log('error', `API request failed: ${errorMessage}`); if (axios.isAxiosError(error)) { const responseData = error.response?.data; const responseStatus = error.response?.status; this.log('error', 'API Error Details:', { status: responseStatus, data: typeof responseData === 'object' ? JSON.stringify(responseData) : responseData }); // Rethrow with more context for better error handling const detailedError = new Error(`API request failed with status ${responseStatus}: ${errorMessage}`); detailedError.response = error.response; throw detailedError; } throw error; } } - src/servers/vps.js:3-6 (registration)Registration: The tools list from src/core/tools/vps.js (which includes VPS_stopVirtualMachineV1) is imported and passed to startServer, which initializes the MCPServer and registers all tools.
import { startServer } from '../core/runtime.js'; import tools from '../core/tools/vps.js'; startServer({ name: 'hostinger-vps-mcp', version: '0.1.41', tools });