# Testing the MCP Server

This guide covers how to test your AWS Logs MCP server to ensure it's working properly.

## Test Client

AWS Logs MCP includes a built-in test client that can be used to verify your setup.

### Setting Up the Test Client

1. Navigate to the test client directory:
   ```bash
   cd test-client
   ```

2. Install dependencies:
   ```bash
   pnpm install
   ```

3. Set up AWS credentials by exporting them in your terminal:
   ```bash
   export AWS_REGION=us-east-1
   export AWS_ACCESS_KEY_ID=your_access_key
   export AWS_SECRET_ACCESS_KEY=your_secret_key
   export AWS_SESSION_TOKEN=your_session_token  # If using temporary credentials
   ```

   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)
   ```

4. Run the test client:
   ```bash
   ./run-client.sh
   ```

   Or manually:
   ```bash
   pnpm build
   pnpm start
   ```

### What the Test Client Does

The test client performs the following:

1. Connects to the MCP server (by default at `http://localhost:3000/sse`)
2. Lists available tools
3. Tests AWS connection
4. Allows you to run sample queries for CloudWatch Logs and CloudTrail events

The output will show whether each operation succeeds or fails, helping you verify your setup.

## Using FastMCP

You can also test the MCP server using the FastMCP CLI tool:

```bash
npx fastmcp dev dist/index.js
```

This will:

1. Start the MCP server
2. Provide an interactive CLI interface to test available tools
3. Allow you to invoke tools with custom parameters

## Manual Testing with cURL

You can manually test the server using cURL or similar tools:

### Testing the Health Endpoint

```bash
curl http://localhost:3000/health
```

Expected response:
```json
{
  "status": "healthy",
  "version": "1.0.0",
  "timestamp": "2023-01-15T12:34:56.789Z",
  "aws": {
    "connectivity": true,
    "region": "us-east-1"
  }
}
```

### Testing MCP Direct Endpoint

```bash
curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -d '{
    "tool": "testAwsConnection",
    "params": {}
  }'
```

## Troubleshooting Tests

If you encounter issues during testing:

1. **Connection refused**: Ensure the MCP server is running and listening on the expected port
2. **AWS credential errors**: Verify credentials are correctly set up with proper permissions
3. **Tool not found errors**: Ensure you're using the correct tool name
4. **Parameter validation errors**: Check that your parameters match the expected schema

For detailed error information, check the MCP server logs, which will provide information about the specific error and context.