Skip to main content
Glama
code-alchemist01

MCP Cloud Services Server

get_metrics

Retrieve performance metrics for cloud resources across AWS, Azure, and GCP to monitor system health and analyze operational data over specified time periods.

Instructions

Get metrics for a cloud resource

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
providerYesCloud provider
resourceIdYesResource ID
metricNameYesMetric name (e.g., CPUUtilization, NetworkIn)
startTimeYesStart time (ISO 8601)
endTimeYesEnd time (ISO 8601)
periodNoPeriod in seconds

Implementation Reference

  • Core handler function that retrieves metrics from AWS CloudWatch for the specified resource, metric, and time period, returning sorted Metric objects.
    async function getAWSMetrics(
      resourceId: string,
      metricName: string,
      startTime: string,
      endTime: string,
      period: number
    ): Promise<Metric[]> {
      try {
        const credentials = await credentialManager.getCredentials('aws');
        if (!credentials) {
          throw new Error('AWS credentials not found');
        }
    
        const client = new CloudWatchClient({
          region: credentials.region || 'us-east-1',
          credentials: credentials.accessKeyId && credentials.secretAccessKey
            ? {
                accessKeyId: credentials.accessKeyId,
                secretAccessKey: credentials.secretAccessKey,
              }
            : undefined,
        });
    
        // Determine namespace based on resource type
        let namespace = 'AWS/EC2';
        if (resourceId.includes('lambda')) {
          namespace = 'AWS/Lambda';
        } else if (resourceId.includes('rds')) {
          namespace = 'AWS/RDS';
        }
    
        const command = new GetMetricStatisticsCommand({
          Namespace: namespace,
          MetricName: metricName,
          Dimensions: [
            {
              Name: namespace === 'AWS/EC2' ? 'InstanceId' : 'FunctionName',
              Value: resourceId,
            },
          ],
          StartTime: new Date(startTime),
          EndTime: new Date(endTime),
          Period: period,
          Statistics: ['Average', 'Maximum', 'Minimum'],
        });
    
        const response = await client.send(command);
    
        const metrics: Metric[] = [];
        if (response.Datapoints) {
          for (const datapoint of response.Datapoints) {
            if (datapoint.Timestamp && datapoint.Average !== undefined) {
              metrics.push({
                name: metricName,
                value: datapoint.Average,
                unit: datapoint.Unit || 'Count',
                timestamp: datapoint.Timestamp,
              });
            }
          }
        }
    
        return metrics.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
      } catch (error) {
        throw new Error(`Failed to get AWS metrics: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Input schema defining the parameters for the get_metrics tool, including provider, resource ID, metric name, time range, and optional period.
    inputSchema: {
      type: 'object',
      properties: {
        provider: {
          type: 'string',
          enum: ['aws', 'azure', 'gcp'],
          description: 'Cloud provider',
        },
        resourceId: {
          type: 'string',
          description: 'Resource ID',
        },
        metricName: {
          type: 'string',
          description: 'Metric name (e.g., CPUUtilization, NetworkIn)',
        },
        startTime: {
          type: 'string',
          description: 'Start time (ISO 8601)',
        },
        endTime: {
          type: 'string',
          description: 'End time (ISO 8601)',
        },
        period: {
          type: 'number',
          description: 'Period in seconds',
          default: 3600,
        },
      },
      required: ['provider', 'resourceId', 'metricName', 'startTime', 'endTime'],
    },
  • Tool registration object for 'get_metrics' included in the monitoringTools array.
    {
      name: 'get_metrics',
      description: 'Get metrics for a cloud resource',
      inputSchema: {
        type: 'object',
        properties: {
          provider: {
            type: 'string',
            enum: ['aws', 'azure', 'gcp'],
            description: 'Cloud provider',
          },
          resourceId: {
            type: 'string',
            description: 'Resource ID',
          },
          metricName: {
            type: 'string',
            description: 'Metric name (e.g., CPUUtilization, NetworkIn)',
          },
          startTime: {
            type: 'string',
            description: 'Start time (ISO 8601)',
          },
          endTime: {
            type: 'string',
            description: 'End time (ISO 8601)',
          },
          period: {
            type: 'number',
            description: 'Period in seconds',
            default: 3600,
          },
        },
        required: ['provider', 'resourceId', 'metricName', 'startTime', 'endTime'],
      },
    },
  • Dispatch handler within handleMonitoringTool that processes get_metrics requests and calls the AWS-specific implementation.
    case 'get_metrics': {
      const resourceId = params.resourceId as string;
      const metricName = params.metricName as string;
      const startTime = params.startTime as string;
      const endTime = params.endTime as string;
      const period = (params.period as number) || 3600;
    
      if (provider === 'aws') {
        return await getAWSMetrics(resourceId, metricName, startTime, endTime, period);
      }
      return { message: `Metrics not yet implemented for ${provider}` };
    }
  • src/server.ts:74-76 (registration)
    MCP server request handler routes tool calls matching monitoringTools (including get_metrics) to the appropriate handler.
    } else if (monitoringTools.some((t) => t.name === name)) {
      result = await handleMonitoringTool(name, args || {});
    } else if (securityTools.some((t) => t.name === name)) {

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/code-alchemist01/Cloud-mcp_server'

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