CloudWatch MCP Server
This simplified MCP server provides a streamlined way to interact with AWS CloudWatch resources through the MCP protocol. It exposes CloudWatch log groups, log queries, and alarms as resources and tools.
Features
- List all CloudWatch log groups with their metadata
- List all CloudWatch alarms with their current states
- Query CloudWatch logs using CloudWatch Insights across multiple log groups
- Discover available fields across multiple log groups with shared schema
- Automatic JSON parsing for @message field in log queries
- Check if specific log groups exist
- Get detailed information about specific log groups
- Filter alarms by state (all alarms or only those in ALARM state)
- Retrieve all saved CloudWatch Logs Insights queries
Prerequisites
- Python 3.12 or higher
- AWS credentials configured (via environment variables, AWS CLI, or IAM role)
- MCP CLI (version 0.1.1 or higher)
- Boto3 (AWS SDK for Python)
Setup
- Make sure you have Python 3.12+ installed.
- Create a virtual environment (optional but recommended):
- Install dependencies:
- Configure AWS credentials if you haven't already:Or set environment variables:
Project Structure
cloudwatch_server.py
- MCP server implementation for CloudWatch integrationaws_cloudwatch.py
- Simplified AWS CloudWatch integration moduletest_cloudwatch.py
- Command-line utility to test the CloudWatch integration
Running the server
Start the MCP server:
Or using the MCP CLI:
Using the MCP server
Resources
The server exposes the following resources:
cloudwatch://log-groups
- Lists all CloudWatch log groupscloudwatch://log-groups/{log_group_name}
- Gets detailed information about a specific log groupcloudwatch://alarms
- Lists all CloudWatch alarmscloudwatch://alarms/in-alarm
- Lists only CloudWatch alarms currently in ALARM statecloudwatch://saved-queries
- Lists all saved CloudWatch Logs Insights queries
Tools
The server provides the following tools:
query_logs
- Query CloudWatch logs using CloudWatch Insights- Parameters:
log_group_names
: Single log group name or list of log group names to queryquery_string
: CloudWatch Insights query stringstart_time
: (Optional) Start time for the query in Unix timestamp millisecondsend_time
: (Optional) End time for the query in Unix timestamp milliseconds
- Features:
- Automatically parses JSON in @message field
- Returns structured data for JSON messages
- Handles multiple log groups in a single query
- Parameters:
discover_log_fields
- Discover available fields across multiple log groups- Parameters:
log_group_names
: Single log group name or list of log group names to analyze
- Features:
- Efficiently discovers fields across multiple log groups
- Assumes shared schema across log groups
- Detects nested JSON fields in @message
- Identifies field types (number, boolean, string, array)
- Parameters:
log_group_exists
- Check if CloudWatch log groups exist- Parameters:
log_group_names
: Single log group name or list of log group names to check
- Returns:
- Dictionary mapping each log group to its existence status
- Parameters:
get_saved_queries
- Fetch all saved CloudWatch Logs Insights queries- No parameters required
Testing the CloudWatch integration
You can test the CloudWatch integration directly using the provided test script:
Examples with MCP CLI
Using the MCP CLI:
License
MIT
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
简化的 MCP 服务器,提供通过 MCP 协议与 AWS CloudWatch 资源(日志组、日志查询和警报)交互的简化方式。
Related MCP Servers
- AsecurityFlicenseAqualityAn MCP server that provides tools for interacting with AWS S3 buckets, enabling direct access to S3 operations through the Model Context Protocol.Last updated -1
- -securityFlicense-qualityAn MCP server that allows AI assistants to access AWS CloudWatch logs by listing log groups and reading log entries.Last updated -25
Log Analyzer with MCPofficial
-securityAlicense-qualityA Model Context Protocol server that provides AI assistants access to AWS CloudWatch Logs, enabling browsing, searching, summarizing, and correlating logs across multiple AWS services.Last updated -113Apache 2.0- -securityFlicense-qualityAn MCP server that enables interaction with Google Cloud Logging API, allowing users to write, read, and manage log entries and configurations through natural language.Last updated -