Low Risk

get_metric_data

Retrieves CloudWatch metric data for a specific metric. This tool retrieves metric data from CloudWatch for a specific metric identified by its namespace, metric name, and dimensions, within a specified time range. It can use either standard GetMetricData API or CloudWatch Metrics Insights for m...

High parameter count (15 properties); Single-target operation

Part of the AWS Labs CloudWatch MCP Server MCP server. Enforce policies on this tool with Intercept, the open-source MCP proxy.

AI agents call get_metric_data to retrieve information from AWS Labs CloudWatch MCP Server without modifying any data. This is common in research, monitoring, and reporting workflows where the agent needs context before taking action. Because read operations don't change state, they are generally safe to allow without restrictions -- but you may still want rate limits to control API costs.

Even though get_metric_data only reads data, uncontrolled read access can leak sensitive information or rack up API costs. An agent caught in a retry loop could make thousands of calls per minute. A rate limit gives you a safety net without blocking legitimate use.

Read-only tools are safe to allow by default. No rate limit needed unless you want to control costs.

aws-labs-cloudwatch-mcp-server.yaml
tools:
  get_metric_data:
    rules:
      - action: allow

See the full AWS Labs CloudWatch MCP Server policy for all 19 tools.

Tool Name get_metric_data
Category Read
Risk Level Low

View all 19 tools →

Agents calling read-class tools like get_metric_data have been implicated in these attack patterns. Read the full case and prevention policy for each:

Browse the full MCP Attack Database →

Other tools in the Read risk category across the catalogue. The same policy patterns (rate-limit, allow) apply to each.

What does the get_metric_data tool do? +

Retrieves CloudWatch metric data for a specific metric. This tool retrieves metric data from CloudWatch for a specific metric identified by its namespace, metric name, and dimensions, within a specified time range. It can use either standard GetMetricData API or CloudWatch Metrics Insights for more advanced querying. The function automatically determines whether to use standard GetMetricData or Metrics Insights based on the parameters provided. If any Metrics Insights specific parameters are provided (group_by_dimension, schema_dimension_keys, limit, sort_order, or order_by_statistic), it will use Metrics Insights. When using group_by_dimension, you must include that dimension in schema_dimension_keys. For advanced use cases, the optional `queries` parameter accepts a list of `MetricDataQueryInput` objects and unlocks capabilities that the single-metric path cannot express: percentile statistics (p50, p90, p99...), metric math expressions (e.g. `errors / invocations`), and multi-metric batching (retrieving many metrics in a single API call). When `queries` is provided, `namespace`, `metric_name`, `dimensions`, and `statistic` are not used. `start_time` is optional; when omitted, it defaults to 3 hours before `end_time` (which itself defaults to the current UTC time). Usage: Use this tool to get actual metric data from CloudWatch for analysis or visualization. Returns: GetMetricDataResponse: An object containing the metric data results Example 1 (Standard GetMetricData): result = await get_metric_data( ctx, namespace="AWS/EC2", metric_name="CPUUtilization", start_time="2023-01-01T00:00:00Z", dimensions=[ Dimension(name="InstanceId", value="i-1234567890abcdef0") ], statistic="Average" # Period will be auto-calculated based on time window and target_datapoints ) Example 2 (Metrics Insights with group by): result = await get_metric_data( ctx, namespace="AWS/EC2", metric_name="CPUUtilization", start_time="2023-01-01T00:00:00Z", end_time="2023-01-02T00:00:00Z", statistic="AVG", schema_dimension_keys=["InstanceType"], group_by_dimension="InstanceType" # This will generate a query like: SELECT AVG("CPUUtilization") FROM SCHEMA("AWS/EC2", "InstanceType") GROUP BY "InstanceType" ) Example 3 (Metrics Insights with schema dimension keys): result = await get_metric_data( ctx, namespace="AWS/EC2", metric_name="CPUUtilization", start_time="2023-01-01T00:00:00Z", end_time="2023-01-02T00:00:00Z", statistic="AVG", schema_dimension_keys=["InstanceId", "InstanceType"], group_by_dimension="InstanceId" # This will generate a query like: SELECT AVG("CPUUtilization") FROM SCHEMA("AWS/EC2", "InstanceId", "InstanceType") GROUP BY "InstanceId" ) Example 4 (Metrics Insights with ORDER BY and LIMIT to find the top 5 EC2 instances with the highest CPU utilization): result = await get_metric_data( ctx, namespace="AWS/EC2", metric_name="CPUUtilization", start_time="2023-01-01T00:00:00Z", end_time="2023-01-02T00:00:00Z", statistic="AVG", schema_dimension_keys=["InstanceId"], group_by_dimension="InstanceId", sort_order="DESC", limit=5, order_by_statistic="MAX" # This will generate a query like: SELECT AVG("CPUUtilization") FROM SCHEMA("AWS/EC2", "InstanceId") GROUP BY "InstanceId" ORDER BY MAX() DESC LIMIT 5 ) Example 5 (Metrics Insights with ORDER BY without sort direction to find the EC2 instances with the highest CPU utilization ordered by default ASC): result = await get_metric_data( ctx, namespace="AWS/EC2", metric_name="CPUUtilization", start_time="2023-01-01T00:00:00Z", end_time="2023-01-02T00:00:00Z", statistic="AVG", schema_dimension_keys=["InstanceId"], group_by_dimension="InstanceId", order_by_statistic="MAX" # This will generate a query like: SELECT AVG("CPUUtilization") FROM SCHEMA("AWS/EC2", "InstanceId") GROUP BY "InstanceId" ORDER BY MAX() ) Example 6 (Metrics Insights without ORDER BY clause to find the EC2 instances with the highest CPU utilization in no specific order): result = await get_metric_data( ctx, namespace="AWS/EC2", metric_name="CPUUtilization", start_time="2023-01-01T00:00:00Z", end_time="2023-01-02T00:00:00Z", statistic="AVG", schema_dimension_keys=["InstanceId"], group_by_dimension="InstanceId" # This will generate a query like: SELECT AVG("CPUUtilization") FROM SCHEMA("AWS/EC2", "InstanceId") GROUP BY "InstanceId" # No ORDER BY clause is added since neither order_by_statistic nor sort_order is specified ) For each result: for metric_result in result.metricDataResults: print(f"Metric: {metric_result.label}") for datapoint in metric_result.datapoints: print(f" {datapoint.timestamp}: {datapoint.value}") Example 7 (Advanced queries - Lambda Latency Percentiles): Use the queries parameter for percentile statistics (p50, p90, p99). result = await get_metric_data( ctx, start_time="2025-12-21T00:00:00Z", queries=[ MetricDataQueryInput( id="p50", metric_stat=MetricStatInput( namespace="AWS/Lambda", metric_name="Duration", dimensions=[Dimension(name="FunctionName", value="my-api-function")], statistic="p50" ), label="Median Latency" ), MetricDataQueryInput( id="p99", metric_stat=MetricStatInput( namespace="AWS/Lambda", metric_name="Duration", dimensions=[Dimension(name="FunctionName", value="my-api-function")], statistic="p99" ), label="p99 Latency" ) ] ) Example 8 (Advanced queries - Error Rate Calculation with Math Expression): Use queries with math expressions to calculate derived metrics. result = await get_metric_data( ctx, start_time="2025-12-21T00:00:00Z", queries=[ MetricDataQueryInput( id="errors", metric_stat=MetricStatInput( namespace="AWS/Lambda", metric_name="Errors", dimensions=[Dimension(name="FunctionName", value="my-api-function")], statistic="Sum" ), return_data=False # Don't include raw errors in results ), MetricDataQueryInput( id="invocations", metric_stat=MetricStatInput( namespace="AWS/Lambda", metric_name="Invocations", dimensions=[Dimension(name="FunctionName", value="my-api-function")], statistic="Sum" ), return_data=False # Don't include raw invocations in results ), MetricDataQueryInput( id="error_rate", expression="(errors / invocations) * 100", label="Error Rate %" ) ] ) # Result contains only the calculated error_rate percentage. It is categorised as a Read tool in the AWS Labs CloudWatch MCP Server MCP Server, which means it retrieves data without modifying state.

How do I enforce a policy on get_metric_data? +

Add a rule in your Intercept YAML policy under the tools section for get_metric_data. You can allow, deny, rate-limit, or validate arguments. Then run Intercept as a proxy in front of the AWS Labs CloudWatch MCP Server MCP server.

What risk level is get_metric_data? +

get_metric_data is a Read tool with low risk. Read-only tools are generally safe to allow by default.

Can I rate-limit get_metric_data? +

Yes. Add a rate_limit block to the get_metric_data rule in your Intercept policy. For example, setting max: 10 and window: 60 limits the tool to 10 calls per minute. Rate limits are tracked per agent session and reset automatically.

How do I block get_metric_data completely? +

Set action: deny in the Intercept policy for get_metric_data. The AI agent will receive a policy violation error and cannot call the tool. You can also include a reason field to explain why the tool is blocked.

What MCP server provides get_metric_data? +

get_metric_data is provided by the AWS Labs CloudWatch MCP Server MCP server (awslabs.cloudwatch-mcp-server). Intercept sits as a proxy in front of this server to enforce policies before tool calls reach the server.

Let agents act without letting them run wild.

Deterministic policy on every MCP tool call. Per-identity grants. Full audit log.

// GET IN TOUCH

Have a question or want to learn more? Send us a message.

Message sent.

We'll get back to you soon.