Skip to main content
Glama
amranu

DigitalOcean MCP Server

by amranu

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
NameRequiredDescriptionDefault
operationIdYesOperation ID of the endpoint to call
parametersNoParameters for the API call

Implementation Reference

  • 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)}`,
          },
        ],
      };
    }
  • 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;
      }
    }
  • 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);
Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/amranu/digitalocean-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server