Log-Analyzer-with-MCP
CLAUDE.md169 starsChanged 10 months agoApache-2.0View on GitHub
Log-Analyzer-with-MCP is an MCP (Model Context Protocol) server that provides AI assistants access to AWS CloudWatch Logs for searching, analysis, and cross-service correlation. The --stateless flag enables stateless HTTP mode for Amazon Bedrock AgentCore integration.
In this repositoryOne other file it gives its agents.
- AGENTS.mdAGENTS.md
The file
We split this CLAUDE.md into the rules it gives an agent
6 rules. About 0 are common, 3 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 68
Async Operations: All tool methods are async for CloudWatch Insights query polling
- Distinctive: line 101
License header: All Python files require Apache-2.0 header
- Very specific: line 103
Returns: All tools return json.dumps(..., indent=2)
- Very specific: line 104
Error handling: Use @handle_exceptions decorator or return JSON errors
- Very specific: line 105
AWS params: Always support profile and region parameters
- Distinctive: line 149
Don't raise exceptions in tools - return JSON errors
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
Log-Analyzer-with-MCP is an MCP (Model Context Protocol) server that provides AI assistants access to AWS CloudWatch Logs for searching, analysis, and cross-service correlation.
Commands
Installation & Setup
uv sync # Install dependencies
source .venv/bin/activate # Activate virtual environmentRunning the Server
# Via uvx (recommended for users)
uvx --from git+https://github.com/awslabs/Log-Analyzer-with-MCP cw-mcp-server [--profile PROFILE] [--region REGION] [--stateless]
# Local development
python -m cw_mcp_server.server [--profile PROFILE] [--region REGION] [--stateless]Linting & Formatting
pre-commit run --all-files # Run ruff linting and formattingCLI Client (for testing)
python src/client.py list-groups [--prefix PREFIX]
python src/client.py search LOG_GROUP "query" [--hours N]
python src/client.py summarize LOG_GROUP [--hours N]
python src/client.py find-errors LOG_GROUP
python src/client.py correlate LOG_GROUP1 LOG_GROUP2 "search_term"Architecture
Core Components
src/
├── client.py # Standalone CLI client for testing
└── cw_mcp_server/
├── server.py # Main MCP server entry point
├── resources/
│ └── cloudwatch_logs_resource.py # CloudWatch data as MCP resources
└── tools/
├── __init__.py # @handle_exceptions decorator
├── utils.py # Time range parsing utilities
├── search_tools.py # Log search/query tools
├── analysis_tools.py # Log analysis tools
└── correlation_tools.py # Cross-service correlationData Flow
AI Assistant / CLI Client → MCP Server (server.py) → Tool Classes → boto3 CloudWatch Logs Client → AWSKey Patterns
- AWS Config Decorator:
@with_aws_config()wraps tools to handle AWS profile/region override per-call - Exception Handling:
@handle_exceptionsintools/__init__.pyreturns JSON errors instead of raising exceptions - Async Operations: All tool methods are async for CloudWatch Insights query polling
- Resource URIs: MCP resources exposed via URIs like
logs://groups/{name},logs://groups/{name}/streams - Time Range Flexibility: Tools accept either
hoursoffset orstart_time/end_timeISO8601 timestamps
MCP Server Structure
- Entry Point:
cw_mcp_server.server:main() - Server Instance:
FastMCP("CloudWatch Logs Analyzer", stateless_http=args.stateless) - Decorators Used:
@mcp.tool(),@mcp.resource(),@mcp.prompt()
Tool Classes
| Class | File | Purpose |
CloudWatchLogsResource | resources/cloudwatch_logs_resource.py | Exposes log groups, streams, samples as resources |
CloudWatchLogsSearchTools | tools/search_tools.py | search_logs(), search_logs_multi(), filter_log_events() |
CloudWatchLogsAnalysisTools | tools/analysis_tools.py | summarize_log_activity(), find_error_patterns() |
CloudWatchLogsCorrelationTools | tools/correlation_tools.py | correlate_logs() for cross-group analysis |
Stateless Mode
The --stateless flag enables stateless HTTP mode for Amazon Bedrock AgentCore integration.
Tech Stack
- Python: 3.12+
- Package Manager: uv
- AWS SDK: boto3
- MCP Library: mcp[cli] with FastMCP
- Linting: ruff (via pre-commit)
Code Style
- License header: All Python files require Apache-2.0 header
- Docstrings: Google-style with Args/Returns
- Returns: All tools return
json.dumps(..., indent=2) - Error handling: Use
@handle_exceptionsdecorator or return JSON errors - AWS params: Always support
profileandregionparameters - Linting: See
.pre-commit-config.yamlfor pinned ruff version
Debugging
# MCP Inspector for interactive testing
npx @modelcontextprotocol/inspector python -m cw_mcp_server.server
# Enable debug logging
export MCP_LOG_LEVEL=debug
python -m cw_mcp_server.server
# Verify AWS credentials
aws sts get-caller-identity --profile PROFILEDependency Management
uv add <package> # Add dependency
uv add --dev <package> # Add dev dependency
uv remove <package> # Remove dependency
uv sync # Sync environmentGit Conventions
- Branch naming:
feat/,fix/,docs/,refactor/ - Commit format:
<type>: <description>(e.g.,feat: add time range filtering)
Testing
# Manual testing via CLI
python src/client.py list-groups --prefix /aws/lambda
python src/client.py search "/aws/lambda/my-function" "ERROR"
# MCP Inspector
npx @modelcontextprotocol/inspector python -m cw_mcp_server.serverCommon Pitfalls
- Don't raise exceptions in tools - return JSON errors
- Decorator order:
@mcp.tool()before@with_aws_config() - Tool function bodies are
pass- logic lives in tool classes - Support both
hoursoffset and ISO8601start_time/end_timefor time ranges
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

