call_digitalocean_api
Interact with DigitalOcean API endpoints by specifying operation IDs and parameters, enabling direct API calls through the DigitalOcean MCP Server for streamlined cloud management.
Instructions
Call a DigitalOcean API endpoint
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| operationId | Yes | Operation ID of the endpoint to call | |
| parameters | No | Parameters for the API call |
Implementation Reference
- src/index.ts:298-320 (handler)The main handler function for the 'call_digitalocean_api' tool. It checks if the API client is configured, resolves the endpoint using findEndpoint, calls apiClient.callEndpoint with the parameters, and returns the result formatted as MCP content.private async handleCallApi(args: any) { if (!this.apiClient) { throw new Error('API client not configured. Use configure_digitalocean_api first.'); } const { operationId, parameters = {} } = args; const endpoint = findEndpoint(operationId); if (!endpoint) { throw new Error(`Endpoint not found: ${operationId}`); } const result = await this.apiClient.callEndpoint(endpoint, parameters); return { content: [ { type: 'text', text: `API call successful:\n\n${JSON.stringify(result, null, 2)}`, }, ], }; }
- src/api-client.ts:19-57 (helper)The core implementation that builds the request URL, processes parameters for query/body/path, makes the axios request to DigitalOcean API, and handles errors.async callEndpoint(endpoint: DOEndpoint, params: Record<string, any> = {}): Promise<any> { const url = this.buildUrl(endpoint.path, params); const requestConfig: AxiosRequestConfig = { method: endpoint.method, url, }; // Add query parameters const queryParams: Record<string, any> = {}; const bodyParams: Record<string, any> = {}; endpoint.parameters.forEach(param => { if (params[param.name] !== undefined) { if (param.in === 'query') { queryParams[param.name] = params[param.name]; } else if (param.in === 'body' || param.in === 'formData') { bodyParams[param.name] = params[param.name]; } } }); if (Object.keys(queryParams).length > 0) { requestConfig.params = queryParams; } if (['POST', 'PUT', 'PATCH'].includes(endpoint.method) && Object.keys(bodyParams).length > 0) { requestConfig.data = bodyParams; } try { const response = await this.client.request(requestConfig); return response.data; } catch (error: any) { if (error.response) { throw new Error(`API Error: ${error.response.status} - ${error.response.data?.message || error.message}`); } throw error; } }
- src/index.ts:131-145 (schema)Input schema defining operationId (required) and parameters (object).inputSchema: { type: 'object', properties: { operationId: { type: 'string', description: 'Operation ID of the endpoint to call', }, parameters: { type: 'object', description: 'Parameters for the API call', additionalProperties: true, }, }, required: ['operationId'], },
- src/index.ts:128-146 (registration)Registration of the tool in the ListTools response, including name, description, and schema.{ name: 'call_digitalocean_api', description: 'Call a DigitalOcean API endpoint', inputSchema: { type: 'object', properties: { operationId: { type: 'string', description: 'Operation ID of the endpoint to call', }, parameters: { type: 'object', description: 'Parameters for the API call', additionalProperties: true, }, }, required: ['operationId'], }, } as Tool,
- src/index.ts:177-178 (registration)Dispatch in the CallToolRequest handler switch statement to the tool handler.case 'call_digitalocean_api': return await this.handleCallApi(args);