agentleFS
AWSKnown publisherawslabs/Log-Analyzer-with-MCP/CLAUDE.md

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.

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
  1. Distinctive:

    Async Operations: All tool methods are async for CloudWatch Insights query polling

    line 68
  2. Distinctive:

    License header: All Python files require Apache-2.0 header

    line 101
  3. Very specific:

    Returns: All tools return json.dumps(..., indent=2)

    line 103
  4. Very specific:

    Error handling: Use @handle_exceptions decorator or return JSON errors

    line 104
  5. Very specific:

    AWS params: Always support profile and region parameters

    line 105
  6. Distinctive:

    Don't raise exceptions in tools - return JSON errors

    line 149

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

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 environment

Running 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 formatting

CLI 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 correlation

Data Flow

AI Assistant / CLI Client → MCP Server (server.py) → Tool Classes → boto3 CloudWatch Logs Client → AWS

Key Patterns

  1. AWS Config Decorator: @with_aws_config() wraps tools to handle AWS profile/region override per-call
  2. Exception Handling: @handle_exceptions in tools/__init__.py returns JSON errors instead of raising exceptions
  3. Async Operations: All tool methods are async for CloudWatch Insights query polling
  4. Resource URIs: MCP resources exposed via URIs like logs://groups/{name}, logs://groups/{name}/streams
  5. Time Range Flexibility: Tools accept either hours offset or start_time/end_time ISO8601 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

ClassFilePurpose
CloudWatchLogsResourceresources/cloudwatch_logs_resource.pyExposes log groups, streams, samples as resources
CloudWatchLogsSearchToolstools/search_tools.pysearch_logs(), search_logs_multi(), filter_log_events()
CloudWatchLogsAnalysisToolstools/analysis_tools.pysummarize_log_activity(), find_error_patterns()
CloudWatchLogsCorrelationToolstools/correlation_tools.pycorrelate_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_exceptions decorator or return JSON errors
  • AWS params: Always support profile and region parameters
  • Linting: See .pre-commit-config.yaml for 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 PROFILE

Dependency Management

uv add <package>             # Add dependency
uv add --dev <package>       # Add dev dependency
uv remove <package>          # Remove dependency
uv sync                      # Sync environment

Git 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.server

Common Pitfalls

  1. Don't raise exceptions in tools - return JSON errors
  2. Decorator order: @mcp.tool() before @with_aws_config()
  3. Tool function bodies are pass - logic lives in tool classes
  4. Support both hours offset and ISO8601 start_time/end_time for time ranges

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.