Google Flights MCP, CLI and Python Library
fix: MCP prompt crashes, deprecated utcnow(), and one-way flight label (#76)
Punit Aranie72c67388b62
diff --git a/fli/cli/utils.py b/fli/cli/utils.pyindex ea1a0cc..ed3aafe 100644--- a/fli/cli/utils.py+++ b/fli/cli/utils.py@@ -161,7 +161,7 @@ def display_flight_results(flights: list):# Create segments tables for each directionall_segments = []for idx, flight in enumerate(flight_segments):- direction = "Outbound" if idx == 0 else "Return" if is_round_trip else ""+ direction = "" if not is_round_trip else ("Outbound" if idx == 0 else "Return")segments = Table(title=(f"{direction} Flight Segments" if direction else "Flight Segments"),box=box.ROUNDED,diff --git a/fli/mcp/server.py b/fli/mcp/server.pyindex 64ec7fb..a9da1ae 100755--- a/fli/mcp/server.py+++ b/fli/mcp/server.py@@ -9,7 +9,7 @@ import jsonimport osfrom collections.abc import Callablefrom dataclasses import dataclass-from datetime import datetime, timedelta+from datetime import datetime, timedelta, timezonefrom typing import Annotated, Anyfrom fastmcp import FastMCP@@ -20,7 +20,6 @@ from mcp.types import (Prompt,PromptArgument,PromptMessage,- Role,TextContent,Tool,ToolAnnotations,@@ -627,7 +626,7 @@ def _build_search_prompt(args: dict[str, str]) -> list[PromptMessage]:"""Create a helper prompt to guide flight searches."""origin = args.get("origin", "JFK").upper()destination = args.get("destination", "LHR").upper()- date = args.get("date") or datetime.utcnow().date().isoformat()+ date = args.get("date") or datetime.now(timezone.utc).date().isoformat()prefer_non_stop = args.get("prefer_non_stop", "true").lower()max_stops_hint = "NON_STOP" if prefer_non_stop in {"true", "1", "yes"} else "ANY"text = (@@ -636,7 +635,7 @@ def _build_search_prompt(args: dict[str, str]) -> list[PromptMessage]:f"Set `max_stops` to '{max_stops_hint}' and highlight the three most affordable options.")return [- PromptMessage(role=Role.USER, content=TextContent(type="text", text=text)),+ PromptMessage(role="user", content=TextContent(type="text", text=text)),]@@ -644,10 +643,9 @@ def _build_budget_prompt(args: dict[str, str]) -> list[PromptMessage]:"""Create a helper prompt to guide flexible date searches."""origin = args.get("origin", "SFO").upper()destination = args.get("destination", "NRT").upper()- start_date = (- args.get("start_date") or (datetime.utcnow().date() + timedelta(days=30)).isoformat()- )- end_date = args.get("end_date") or (datetime.utcnow().date() + timedelta(days=90)).isoformat()+ today = datetime.now(timezone.utc).date()+ start_date = args.get("start_date") or (today + timedelta(days=30)).isoformat()+ end_date = args.get("end_date") or (today + timedelta(days=90)).isoformat()duration = args.get("duration", "7")text = ("Use the `search_dates` tool to find the lowest fares between "@@ -655,7 +653,7 @@ def _build_budget_prompt(args: dict[str, str]) -> list[PromptMessage]:f"Set trip_duration to {duration} days and sort the results by price.")return [- PromptMessage(role=Role.USER, content=TextContent(type="text", text=text)),+ PromptMessage(role="user", content=TextContent(type="text", text=text)),]