Skip to main content
Glama
adeyholar

Claude Flight Search MCP Server

by adeyholar
README.md
# Claude Flight Search MCP Server

A Model Context Protocol (MCP) server that provides flight search capabilities for integration with Claude Desktop.

## Features

- āœˆļø Flight search between airports
- šŸ¢ Airport information lookup
- šŸ“Š Price comparison across multiple dates
- šŸ”„ Mock data for development (easily replaceable with real APIs)
- šŸ›”ļø Environment variable management for API keys

## Quick Start

### 1. Clone and Setup

```bash
git clone <your-repo-url>
cd claude-flight-search-mcp

# Create and activate conda environment
conda env create -f environment.yml
conda activate claude-flight-mcp

# Alternative: Create environment manually
# conda create -n claude-flight-mcp python=3.11 -y
# conda activate claude-flight-mcp
# pip install -r requirements.txt
```

### 2. Environment Configuration

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

```bash
# Optional: For real Amadeus API integration
AMADEUS_CLIENT_ID=your_amadeus_client_id
AMADEUS_CLIENT_SECRET=your_amadeus_client_secret
```

### 3. Test the Server

```bash
# Test the server directly
python src/flight_search_server.py
```

### 4. Configure Claude Desktop

Edit your Claude Desktop configuration file:

**Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
**macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
**Linux:** `~/.config/Claude/claude_desktop_config.json`

Add this configuration:

```json
{
  "mcpServers": {
    "flight-search": {
      "command": "python",
      "args": ["/full/path/to/claude-flight-search-mcp/src/flight_search_server.py"],
      "cwd": "/full/path/to/claude-flight-search-mcp",
      "env": {
        "PYTHONPATH": "/full/path/to/claude-flight-search-mcp/src"
      }
    }
  }
}
```

**Important:** Replace `/full/path/to/claude-flight-search-mcp` with the actual absolute path to your project directory.

### 5. Restart Claude Desktop

Restart Claude Desktop to load the new MCP server.

## Usage Examples

Once configured, you can ask Claude:

- "Search for flights from LAX to JFK on December 15th"
- "Find flights from London to Tokyo next week for 2 passengers"
- "What's the airport information for SFO?"
- "Compare flight prices from LAX to JFK over the next 7 days"

## Available Tools

### search_flights
Search for flights between airports with detailed results.

**Parameters:**
- `origin` (required): Origin airport code (3-letter IATA code)
- `destination` (required): Destination airport code (3-letter IATA code)
- `departure_date` (required): Departure date in YYYY-MM-DD format
- `return_date` (optional): Return date for round-trip flights
- `passengers` (optional): Number of passengers (default: 1)

### get_airport_info
Get detailed information about an airport.

**Parameters:**
- `airport_code` (required): 3-letter IATA airport code

### compare_flight_prices
Compare flight prices across multiple dates.

**Parameters:**
- `origin` (required): Origin airport code
- `destination` (required): Destination airport code
- `start_date` (required): Start date for comparison
- `days_range` (optional): Number of days to compare (default: 7)

## Current Airport Database

The server currently includes information for:
- LAX (Los Angeles International Airport)
- JFK (John F. Kennedy International Airport)
- LHR (London Heathrow Airport)
- NRT (Narita International Airport)

## Development

### Adding Real Flight API Integration

1. Sign up for [Amadeus for Developers](https://developers.amadeus.com/)
2. Get your API credentials
3. Add them to your `.env` file
4. Uncomment the Amadeus dependency in `requirements.txt`
5. Replace the mock data calls with real API calls

### Adding More Airports

Edit the `AIRPORT_DATABASE` dictionary in `src/flight_search_server.py` to add more airports.

### Running Tests

```bash
pytest tests/
```

### Code Formatting

```bash
black src/
flake8 src/
```

## Project Structure

```
claude-flight-search-mcp/
ā”œā”€ā”€ src/
│   └── flight_search_server.py    # Main MCP server
ā”œā”€ā”€ tests/                         # Test files
ā”œā”€ā”€ docs/                          # Documentation
ā”œā”€ā”€ examples/                      # Example configurations
ā”œā”€ā”€ requirements.txt               # Python dependencies
ā”œā”€ā”€ .env.example                   # Environment variable template
ā”œā”€ā”€ .gitignore                     # Git ignore rules
└── README.md                      # This file
```

## Troubleshooting

### Server Not Connecting
1. Check that the path in your Claude Desktop config is correct
2. Ensure Python virtual environment is properly set up
3. Verify all dependencies are installed
4. Check Claude Desktop logs for error messages

### Mock Data vs Real Data
The server currently uses mock flight data for development. To use real flight data, you'll need to:
1. Set up API credentials with a flight data provider
2. Implement the real API calls
3. Handle rate limiting and error responses

## Contributing

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests
5. Submit a pull request

## License

MIT License - see LICENSE file for details.
------------------------------------------------
# As-Built Documentation: Claude Flight Search MCP Server

**Project**: Flight Search Integration with Claude Desktop via Model Context Protocol (MCP)  
**Implementation Date**: September 2-3, 2025  
**Version**: 1.0.0  
**Status**: Deployed with Partial Functionality

---

## Executive Summary

Successfully implemented a Model Context Protocol (MCP) server that integrates flight search capabilities with Claude Desktop. The system includes Amadeus API integration, SQLite caching, price tracking, and intelligent fallback mechanisms. While API authentication is functional, flight search requests currently fall back to mock data, indicating parameter or endpoint configuration issues that require further investigation.

---

## System Architecture

### Overview
```
Claude Desktop ↔ MCP Protocol ↔ Flight Search Server ↔ Amadeus API
                                        ↓
                                SQLite Cache Database
```

### Components Implemented

**1. MCP Server Framework**
- Language: Python 3.11
- Framework: Anthropic MCP Server SDK
- Communication: Standard I/O protocol
- Deployment: Local conda environment

**2. Flight Search Service**
- Primary API: Amadeus for Developers (Test Environment)
- Fallback: Mock data generation
- Cache: SQLite database with 1-hour TTL
- Rate Limiting: Built-in via API quotas

**3. Database Layer**
- Engine: SQLite (flight_cache.db)
- Tables: flight_searches, price_tracking
- Purpose: API response caching and price history

---

## Technical Implementation

### Core Technologies
- **Python**: 3.11.13
- **MCP Framework**: 1.13.1
- **HTTP Client**: httpx 0.28.1
- **Environment Management**: python-dotenv 1.1.1
- **Database**: SQLite (built-in)
- **Deployment**: Conda environment management

### API Integration
- **Provider**: Amadeus for Developers
- **Environment**: Test (test.api.amadeus.com)
- **Authentication**: OAuth2 Client Credentials
- **Rate Limit**: 2,000 requests/month (free tier)
- **Token Management**: Automatic refresh with 60-second safety margin

### Supported Operations
1. **search_flights**: Individual flight searches with real-time pricing
2. **find_best_price**: Date range optimization across multiple days
3. **get_airport_info**: Airport details and metadata
4. **compare_flight_prices**: Price trends across date ranges
5. **get_price_history**: Historical pricing analysis (planned)

---

## Configuration

### Environment Variables
```bash
# API Credentials
AMADEUS_CLIENT_ID=WWVc2tHiHUvcsYq1eTiShAGqgTxpxolG
AMADEUS_CLIENT_SECRET=[REDACTED]

# Operational Settings
USE_REAL_API=true
API_FALLBACK_TO_MOCK=true
DEBUG=true
LOG_LEVEL=INFO

# Server Configuration
SERVER_NAME=flight-search
SERVER_VERSION=1.0.0
```

### Claude Desktop Integration
```json
{
  "mcpServers": {
    "flight-search": {
      "command": "D:\\ai\\conda\\envs\\claude-flight-mcp-3.11\\python.exe",
      "args": ["D:\\AI\\Gits\\claude-flight-search-mcp\\src\\flight_search_server.py"],
      "cwd": "D:\\AI\\Gits\\claude-flight-search-mcp",
      "env": {
        "PYTHONPATH": "D:\\AI\\Gits\\claude-flight-search-mcp\\src"
      }
    }
  }
}
```

---

## Airport Database

### Supported Airports (12 locations)
**North America**: LAX, JFK, SFO, IND, ATL, ORD, DEN, MIA  
**Europe**: LHR, CDG, FRA  
**Africa**: LOS  
**Asia**: NRT, DXB

### Airport Data Structure
```python
{
    "name": "Airport Name",
    "city": "City",
    "state": "State (if applicable)",
    "country": "Country",
    "timezone": "IANA timezone",
    "iata": "3-letter code",
    "icao": "4-letter code"
}
```

---

## Current Status

### Functional Components āœ…
- MCP server initialization and protocol handling
- Amadeus API authentication (OAuth2 token acquisition)
- SQLite database creation and management
- Airport database validation
- Mock data generation and formatting
- Claude Desktop integration via MCP protocol
- Environment variable management
- Error handling and logging
- Diagnostics and health checking

### Authentication Status āœ…
- **Token Endpoint**: Successfully authenticating with test.api.amadeus.com
- **Credentials**: Valid 32-character Client ID and 16-character Secret
- **Token Lifecycle**: Automatic refresh with 1799-second expiration
- **Headers**: Proper Content-Type and Authorization formatting

### Known Issues āŒ
- **Flight Search API**: Requests falling back to mock data despite successful authentication
- **Root Cause**: Likely parameter formatting or endpoint configuration issues
- **Impact**: All flight searches return $1,285 mock pricing instead of real market data
- **Routes Affected**: Both domestic (LAX-JFK) and international (IND-LOS) routes

### Data Quality
- **Mock Data**: Realistic airline codes, routing via appropriate hubs
- **Price Simulation**: Static $1,285 across all dates and routes
- **Expected Real Data**: $700-900 range for IND-LOS based on market research

---

## File Structure

```
claude-flight-search-mcp/
ā”œā”€ā”€ src/
│   ā”œā”€ā”€ flight_search_server.py     # Main MCP server (28,737 bytes)
│   └── flight_search_server_clean.py  # Clean backup version
ā”œā”€ā”€ diagnostics.py                  # Comprehensive system diagnostics
ā”œā”€ā”€ .env                           # Environment configuration
ā”œā”€ā”€ .env.example                   # Template for environment setup
ā”œā”€ā”€ environment.yml                # Conda environment specification
ā”œā”€ā”€ requirements.txt               # Python dependencies
ā”œā”€ā”€ flight_cache.db               # SQLite cache (auto-generated)
ā”œā”€ā”€ README.md                     # Project documentation
└── .gitignore                    # Git exclusions
```

---

## API Endpoints Used

### Authentication
- **URL**: `https://test.api.amadeus.com/v1/security/oauth2/token`
- **Method**: POST
- **Headers**: `Content-Type: application/x-www-form-urlencoded`
- **Status**: āœ… Working

### Flight Search
- **URL**: `https://test.api.amadeus.com/v2/shopping/flight-offers`
- **Method**: GET
- **Headers**: `Authorization: Bearer {token}`, `Content-Type: application/json`
- **Status**: āŒ Parameter or configuration issue

### Parameters Sent
```json
{
    "originLocationCode": "IND",
    "destinationLocationCode": "LOS", 
    "departureDate": "2024-09-26",
    "adults": 1,
    "max": 10,
    "currencyCode": "USD"
}
```

---

## Performance Characteristics

### Response Times
- **Authentication**: ~500ms (cached for 30 minutes)
- **Mock Data Generation**: ~100ms
- **Database Queries**: <10ms
- **End-to-End Search**: ~600ms (mock mode)

### Resource Usage
- **Memory**: ~50MB baseline
- **Storage**: 50KB (cache database grows with usage)
- **API Quota**: 0-3 calls per search (depending on date range)

### Caching Strategy
- **Duration**: 1 hour per search combination
- **Key Format**: `{origin}_{destination}_{date}_{passengers}`
- **Invalidation**: Time-based expiration only

---

## Diagnostics and Monitoring

### Health Check Results
```
Environment Check: āœ… All systems operational
Dependencies: āœ… All packages installed correctly  
Configuration: āœ… Environment variables properly set
Server File: āœ… All components present and valid
API Authentication: āœ… Successfully obtaining tokens
Server Startup: āœ… All imports and initialization successful
Claude Integration: āœ… MCP protocol properly configured
```

### Logging Implementation
- **Startup**: Service initialization with configuration status
- **API Calls**: Token requests and flight search attempts
- **Errors**: Detailed error messages with context
- **Fallbacks**: Clear indication when using mock data

---

## Security Implementation

### Credential Management
- Environment variable isolation
- No hardcoded secrets in source code
- .gitignore protection for sensitive files
- Test environment credentials only

### Data Protection
- Local SQLite database (no external data exposure)
- No persistent storage of API responses beyond cache TTL
- No personal data collection or retention

---

## Testing and Validation

### Test Coverage
- **Unit Tests**: Basic functionality validation
- **Integration Tests**: MCP protocol communication
- **API Tests**: Authentication flow verification
- **End-to-End Tests**: Claude Desktop interaction

### Validation Methods
- Manual flight searches via Claude interface
- Diagnostics script comprehensive checking
- Direct API credential testing via curl
- Mock data fallback verification

---

## Future Development Requirements

### Immediate Priorities
1. **Debug Flight Search API**: Investigate parameter formatting and endpoint configuration
2. **Error Handling**: Implement specific error codes and user-friendly messages
3. **Date Validation**: Ensure proper date format and future date handling
4. **Route Coverage**: Verify test API route availability

### Enhancement Opportunities
1. **Real-time Price Alerts**: Database-driven price monitoring
2. **Multi-airline Aggregation**: Additional API provider integration
3. **Advanced Filtering**: Cabin class, airline preferences, layover duration
4. **Historical Analytics**: Price trend analysis and prediction
5. **Production Migration**: Upgrade to production Amadeus API

### Scalability Considerations
1. **API Quota Management**: Intelligent request batching and prioritization
2. **Database Optimization**: Indexing and query optimization
3. **Caching Strategy**: Redis migration for distributed caching
4. **Load Balancing**: Multiple API provider failover

---

## Lessons Learned

### Successful Patterns
- **MCP Integration**: Standard I/O protocol handles Claude communication efficiently
- **Fallback Architecture**: Mock data ensures service availability during API issues
- **Environment Management**: Conda provides consistent dependency resolution
- **Diagnostics**: Comprehensive health checking significantly reduced debugging time

### Challenges Encountered
- **API Documentation**: Amadeus test vs production endpoint differences
- **Date Handling**: Timezone and format considerations for international routes
- **Error Context**: Distinguishing between authentication and search failures
- **Development vs Production**: Test environment limitations on route coverage

### Technical Debt
- **Hard-coded Airport Database**: Should migrate to external data source
- **Static Mock Data**: Should reflect realistic price variations
- **Limited Error Handling**: Needs more granular error classification
- **Manual Configuration**: Claude Desktop config requires manual path updates

---

## Conclusion

The Claude Flight Search MCP Server represents a functional proof-of-concept with strong architectural foundations. While the Amadeus API authentication is working correctly, the flight search functionality requires parameter debugging to transition from mock data to real pricing. The system demonstrates successful MCP protocol implementation and provides a solid foundation for a year-long development and testing initiative.

The implementation successfully proves the viability of integrating external APIs with Claude Desktop through the MCP protocol, establishing patterns for future API integrations and demonstrating the value of intelligent fallback mechanisms in maintaining service reliability.

---

**Document Version**: 1.0  
**Last Updated**: September 3, 2025  
**Next Review**: Upon resolution of flight search API issues