Skip to main content
Glama

✈️ Flight MCP Server — SQLite Demo

一个功能完备的 Model Context Protocol (MCP) 演示服务器,提供模拟的航班搜索与预订能力。

[!WARNING] 仅供模拟: 本系统中所有航班、库存和预订均使用虚构/示例数据纯模拟生成。本项目不会集成任何真实航空公司 API,不会预订真实航班。

项目简介

本项目是一个简洁、模块化的 Python 应用,设计目的是帮助学习 Model Context Protocol (MCP) 的基础知识。它作为一个本地后端服务器,无缝连接到 Claude Desktop,让 AI 在安全可控的前提下访问本地 SQLite 数据库,用于浏览 Demo 航班并完成预订。

Related MCP server: SQLite MCP Server

什么是 MCP?

Model Context Protocol (MCP) 是一种开放标准,允许像 Claude 这样的 AI 模型安全地连接到本地或远程的数据源、工具和服务。MCP 让模型不再靠猜测或幻觉来捏造数据,而是可以查询一个确定性的后端系统。

架构

系统的整体架构采用清晰的分层方式:

Claude Desktop (Client)
        ↓ (stdio JSON-RPC)
Python Flight MCP Server
        ↓
Services Layer (Business Logic)
        ↓
SQLite Database (Data Store)

技术栈

  • 语言: Python 3.11+

  • 包管理器: uv

  • 框架: 官方 MCP Python SDK(mcp)

  • 数据库: SQLite(本地文件)

  • 客户端: Claude Desktop

六个可用工具

该服务器向 AI 暴露六个功能完整的 MCP 工具:

  1. search_flights:按出发地、目的地和日期查找可用航班。

  2. get_flight:获取指定航班的完整详情与元数据。

  3. check_seats:查询航班的实时余座情况。

  4. book_flight:创建新的模拟预订(需要用户确认)。

  5. get_booking:通过 PNR 编号查看已有预订的详情。

  6. cancel_booking:取消预订并恢复座位库存。

SQLite Demo 数据库

系统使用本地 SQLite 数据库(data/flightmcp.db)存储航班库存和预订状态。 注意:实际的 .db 文件已被版本控制排除,避免陈旧状态问题。

如需用全新的演示数据初始化数据库,请运行:

uv run python scripts/seed_database.py

安装与设置

请确保已安装 uv,然后同步依赖项:

uv sync

运行测试

项目内置了一套稳健的 pytest 测试套件,用于后端验证。

uv run pytest

运行 MCP 服务器

如需手动验证服务器能否正常启动(它会持续运行并等待 stdio 通信):

uv run flight-mcp

(所有应用日志都会严格输出到 stderr,以保证 stdout 上 MCP 协议输出的干净整洁。)

配置 Claude Desktop

若要将此 MCP 服务器连接到 Claude Desktop,请编辑 Claude Desktop 的配置文件(在 macOS 上通常位于 ~/Library/Application Support/Claude/claude_desktop_config.json)。

Claude Desktop 配置示例:

{
  "mcpServers": {
    "flight-mcp": {
      "command": "/opt/homebrew/bin/uv",
      "args": [
        "run",
        "--directory",
        "/Users/baratharjun/Desktop/medai",
        "flight-mcp"
      ],
      "cwd": "/Users/baratharjun/Desktop/medai"
    }
  }
}

注意:请根据本地项目目录和 uv 安装路径修改绝对路径。

工具使用示例

连接到 Claude Desktop 之后,你可以用自然语言交互:

用户: “帮我找一班 2026-09-05 从 Chennai 到 Delhi 的航班。” Claude 调用 search_flights 并读取 SQLite 数据库。

用户: “航班 1 还有多少个座位?” Claude 调用 check_seats。

用户: “我要预订航班 1。我的名字是 Test User,邮箱是 [test@example.com](mailto:test@example.com),电话是 9999999999。” Claude 确认请求并询问用户是否确认。

用户: “确认。” Claude 调用 book_flight 并返回一个虚构的预订号(例如 FLM-XXXXXX)。

Available Tools

6 tools
book_flightA

Create a simulated flight booking in the local SQLite database. This does NOT purchase a real airline ticket or process payment. Use this ONLY after receiving explicit user confirmation to book.

Inputs: flight_id (required), passenger_name (required), passenger_email (required), passenger_phone (required), +1 more.

cancel_bookingB

Cancel a simulated booking and restore the seat availability.

Inputs: booking_reference (required).

check_seatsB

Check currently available seats for a demo flight.

Inputs: flight_id (required).

get_bookingA

Retrieve a simulated booking by its reference code (e.g. FLM-XXXXXX).

Inputs: booking_reference (required).

get_flightA

Retrieve complete information for one fictional flight by its ID.

Inputs: flight_id (required).

search_flightsB

Search the local sample flight inventory. This tool returns fictional/demo flight options and is not connected to live airline availability.

Inputs: date (required), origin (required), destination (required), airline, +2 more. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 6 tools

    Disambiguation5/5

    Each tool addresses a distinct resource and action: flight search, flight detail, seat availability, booking creation, booking retrieval, and booking cancellation. There is no ambiguity between tool purposes.

    Naming Consistency5/5

    All tool names follow a consistent snake_case verb_noun pattern (search_flights, get_flight, check_seats, book_flight, get_booking, cancel_booking). Naming is uniform and predictable.

    Tool Count5/5

    With 6 tools covering search, inspection, seat checking, booking, retrieval, and cancellation, the count is well-scoped for a demo flight booking server. Each tool earns its place without excess.

    Completeness4/5

    The core booking lifecycle is covered (search, read, book, retrieve, cancel). Minor gaps exist, such as no update booking or list bookings, but these are not critical for the demo scope and agents can work around them.

    Maintenance

    ActivitySlowing
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Provides Claude Desktop with secure access to multiple database connections, allowing users to query MySQL, PostgreSQL, SQLite, and SQL Server databases directly through natural language.
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables natural language interaction with local SQLite databases through Claude Desktop, translating plain English queries into SQL for data analysis and exploration.
      3
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables natural language querying of SAP flight data (airlines, flights, bookings) using Claude Code, with 19 tools for model introspection, SQL queries, and analytics.
      1
      -
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables querying and managing a CRM database through natural language conversations with Claude Desktop.
      -