# Local Deployment Guide

This guide provides instructions for deploying and using AWS Logs MCP on your local machine.

## Prerequisites

Before you begin, ensure you have the following installed:

- Node.js (v18 or later)
- npm or pnpm
- Docker (optional, for containerized deployment)
- AWS CLI (for configuring credentials)

## Setup

### Installation

1. Clone the repository:

```bash
git clone https://github.com/your-username/aws-logs-mcp.git
cd aws-logs-mcp
```

2. Install dependencies:

```bash
pnpm install
```

### AWS Credentials

To access AWS services, you need to configure credentials:

1. **Using AWS CLI** (recommended):

```bash
aws configure
```

Enter your AWS Access Key ID, Secret Access Key, default region, and output format when prompted.

2. **Using Environment Variables**:

Create a `.env` file in the project root:

```
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
```

### Configuration

Edit `src/config/env.ts` if you need to customize:

- Server port
- Logging level
- Maximum log entries
- Other application-specific settings

## Running the Server

### Direct Execution

1. Build the project:

```bash
pnpm build
```

2. Start the server:

```bash
pnpm start
```

For development with auto-restart:

```bash
pnpm dev
```

### Docker

A Docker setup is available for easy deployment:

1. Build the Docker image:

```bash
docker build -t aws-logs-mcp:latest .
```

2. Run the container:

```bash
docker run -d \
  --name aws-logs-mcp \
  -p 3000:3000 \
  -e AWS_REGION=us-east-1 \
  -e AWS_ACCESS_KEY_ID=your_key \
  -e AWS_SECRET_ACCESS_KEY=your_secret \
  aws-logs-mcp:latest
```

Alternatively, use Docker Compose:

```bash
docker-compose up -d
```

## Using the Client

Once the server is running, you can use the included test client:

1. Navigate to the test client directory:

```bash
cd test-client
```

2. Install client dependencies (if not already done):

```bash
pnpm install
```

3. Run the client:

```bash
pnpm start
```

The client will connect to your locally running MCP server and allow you to:
- Query CloudWatch logs
- Retrieve CloudTrail events
- Test connection to AWS services

## Troubleshooting

### Common Issues

1. **Connection Errors**:
   - Verify the server is running on the expected port
   - Check that the client is configured to connect to the correct server URL

2. **AWS Authentication Errors**:
   - Ensure your AWS credentials are valid and have the necessary permissions
   - Verify the AWS region is correctly set
   - Try using AWS CLI to test the credentials: `aws sts get-caller-identity`

3. **Server Startup Issues**:
   - Check the logs for detailed error messages
   - Verify all required environment variables are set
   - Ensure no other application is using the configured port

If you continue experiencing issues, please consult the server logs for detailed error messages or submit an issue on GitHub.