# AWS Logs MCP Test Client

This is a test client for the AWS Logs MCP (Model Context Protocol) server. It connects to the server and demonstrates how to use the AWS CloudWatch and CloudTrail tools provided by the MCP.

## Code Structure

- **`src/config/`**: Configuration-related code
  - `env.ts`: Environment configuration utilities
- **`src/services/`**: Service implementations
  - `aws-service.ts`: Service for AWS interactions
  - `client-service.ts`: Service for MCP client operations
- **`src/types/`**: TypeScript type definitions
  - `client.ts`: Types for client operations
- **`src/utils/`**: Utility functions
  - `error-utils.ts`: Error handling utilities
  - `logger.ts`: Logging utilities
- **`src/index.ts`**: Main application entry point
- **`src/aws-test.ts`**: Standalone AWS connection test

## Setup

1. Install dependencies:
   ```
   pnpm install
   ```

2. Configure AWS credentials (two options):

   ### Option 1: Use exported AWS credentials (recommended)
   
   Export your AWS credentials in your terminal:
   ```bash
   export AWS_REGION=us-east-1
   export AWS_ACCESS_KEY_ID=your_access_key_id
   export AWS_SECRET_ACCESS_KEY=your_secret_access_key
   # Optional if using temporary credentials
   export AWS_SESSION_TOKEN=your_session_token
   ```

   Alternatively, use the AWS CLI to export credentials:
   ```bash
   eval $(aws configure export-credentials)
   # Or for a specific profile
   eval $(aws configure export-credentials --profile your-profile)
   ```

   ### Option 2: Use .env file
   
   - Copy the example environment file:
     ```
     cp .env.example .env
     ```
   - Edit `.env` and add your AWS credentials:
     ```
     AWS_REGION=us-east-1
     AWS_ACCESS_KEY_ID=your_access_key_id
     AWS_SECRET_ACCESS_KEY=your_secret_access_key
     ```

## Test AWS Connection

Before connecting to the MCP server, you can test your AWS connection directly:

```
pnpm test-aws
```

This will attempt to connect to AWS CloudWatch Logs to verify your credentials are working correctly.

## Run the Test Client

### Using exported credentials (recommended)

If you've exported your AWS credentials, run the client using the provided script:

```
./run-client.sh
```

### Using .env file

If you've configured your .env file:

```
pnpm start
```

The client will:
1. Connect to the MCP server
2. List available tools
3. Test the AWS connection via the MCP server
4. Close the connection

## Troubleshooting

### AWS Connection Issues

If you encounter AWS connection errors like `UnrecognizedClientException` or `InvalidSignatureException`:

1. Verify your AWS credentials are correct in the `.env` file
2. Check that your credentials have permissions to access CloudWatch Logs
3. Try using an AWS profile instead of direct access keys:
   ```
   AWS_PROFILE=your_profile_name
   ```
4. Make sure your AWS region is set correctly

### MCP Server Connection Issues

If you can't connect to the MCP server:

1. Ensure the server is running at the URL specified in MCP_SERVER_URL 
2. Check that the port is correct and accessible
3. Verify network connectivity between your client and the server
4. The client now uses the streamable HTTP transport to connect to the `/mcp` endpoint
5. If you're running an older server version that only supports SSE, you'll need to update your server