Flight Booking MCP Server
README.md
# Flight Booking MCP Server
> A Model Context Protocol server that gives AI assistants flight search, booking, and GPT-powered Q&A.





## Overview
Flight Booking MCP Server is a prototype Model Context Protocol (MCP) server built with FastMCP. It exposes a mock flight-booking domain to MCP-compatible AI clients through all three MCP primitives: tools, resources, and prompts. An assistant can search flights, create bookings, read airport and airline reference data, and use reusable prompt templates for recommendations and rebooking.
The server also includes an `ask_openai` tool that lets the model delegate free-form questions to GPT-3.5 through a lazily initialised OpenAI client. All flight data is hardcoded, so the project works as a compact, readable reference for building MCP servers in Python.
## Features
- **Flight search:** `search_flights` filters a flight list by origin and destination airport codes.
- **Booking creation:** `create_booking` returns a confirmation with a generated booking reference.
- **Reference resources:** `file://airports` and `file://airlines` expose airport and airline data (airline fleet sizes included) for clients to read.
- **Prompt templates:** `find_best_flight` (budget and cabin preference) and `handle_disruption` (original flight and reason) guide recommendations and rebooking.
- **GPT-3.5 integration:** `ask_openai` sends a question to `gpt-3.5-turbo`. The client is created on first use, and a missing API key or API error comes back as a readable message.
- **CLI entry point:** `main.py` starts the server, warns when `OPENAI_API_KEY` is missing, and handles shutdown and errors.
- **Test scripts (partial):** `simple_test.py` and `test_server.py` are print-based smoke scripts with no assertions. `test_server.py` uses private `mcp` internals and may not work on newer SDK versions. See `TESTING_GUIDE.md`.
## Architecture
The project is a single-process MCP server that communicates over stdio. `main.py` imports the FastMCP instance from `server.py` and runs it. `server.py` registers tools, resources, and prompts with decorators and serves them from in-memory data.
```mermaid
flowchart LR
subgraph sg1["Client"]
n_client["MCP client (AI assistant)"]
end
subgraph sg2["Backend"]
n_main["main.py entry point"]
n_server["FastMCP server (server.py)"]
end
subgraph sg3["Data"]
n_data[("Hardcoded flight and airport data")]
end
subgraph sg5["External services"]
n_openai{{"OpenAI API (GPT-3.5)"}}
end
n_client -->|MCP over stdio| n_main
n_main -->|mcp.run| n_server
n_server -->|tool and resource lookups| n_data
n_server -->|chat completion for ask_openai| n_openai
```
**How it works**
1. An MCP client (an AI assistant) launches `python main.py` and talks to it over stdio.
2. `main.py` calls `mcp.run()` on the FastMCP instance defined in `server.py`.
3. For flight and reference-data requests, the server reads the hardcoded in-memory data.
4. For `ask_openai`, the server creates an OpenAI client on first use from `OPENAI_API_KEY` and returns GPT-3.5's reply.
## Tech Stack
| Layer | Technology |
| --- | --- |
| Language | Python 3.10+ |
| MCP framework | MCP Python SDK (FastMCP) |
| AI | OpenAI Python SDK (`gpt-3.5-turbo`) |
| Tooling | uv, setuptools |
## Project Structure
```
.
├── main.py # Entry point: starts the server, checks the API key
├── server.py # FastMCP server: tools, resources, prompts
├── simple_test.py # Smoke-test script
├── test_server.py # Additional smoke-test script
├── TESTING_GUIDE.md # Notes on testing
├── pyproject.toml # Project metadata and dependencies
├── uv.lock
├── .env.example
└── LICENSE
```
## Getting Started
### Prerequisites
- Python 3.10+
- An OpenAI API key (optional, only needed for `ask_openai`)
- [uv](https://docs.astral.sh/uv/) (optional)
### Installation
```bash
git clone https://github.com/zain-mirza-1060/flight-booking-mcp-server.git
cd flight-booking-mcp-server
pip install -e .
```
### Environment Variables
| Variable | Description | Required |
| --- | --- | --- |
| `OPENAI_API_KEY` | API key for the `ask_openai` tool. The server runs without it, but that tool returns an error. | No |
```bash
cp .env.example .env
export OPENAI_API_KEY="your-openai-api-key-here"
```
### Running locally
```bash
python main.py
```
To inspect the server interactively with the MCP CLI:
```bash
mcp dev server.py
```
### Running tests
```bash
python simple_test.py
```
This script prints results rather than asserting them. `test_server.py` accesses private attributes (`mcp._tools`) and may fail on newer SDK versions.
## Usage
### Tools
| Tool | Arguments | Example result |
| --- | --- | --- |
| `search_flights` | `origin`, `destination` | `search_flights("LAX", "JFK")` returns flight `AA100` at 350 |
| `create_booking` | `flight_id`, `passenger_name` | `create_booking("AA100", "John Doe")` returns reference `BOOK-AA100-JOH` |
| `ask_openai` | `question` | Returns GPT-3.5's answer as text |
### Resources
- `file://airports` lists LAX, JFK, and LHR.
- `file://airlines` lists AA, BA, DL, and UA with country and fleet size.
### Prompts
- `find_best_flight(budget, preferences="economy")`
- `handle_disruption(original_flight, reason)`
## Roadmap
- [ ] Replace hardcoded data with real flight data
- [ ] Persist bookings
## License
Released under the MIT License, see [LICENSE](LICENSE).
This server cannot be deployed
Maintenance
ActivityInactive
ResponsivenessNo recent community issues