Skip to content

armgit / fli

Public Imported from GitHub
0

Google Flights MCP, CLI and Python Library

fix(mcp): align 2-tuple price source and simplify multi-city legs

Punit Arani03972f46648a
diff --git a/fli/mcp/server.py b/fli/mcp/server.py
index 6496cd6..70f5b96 100755
--- a/fli/mcp/server.py
+++ b/fli/mcp/server.py
@@ -329,15 +329,16 @@ def _serialize_flight_result(flight: Any, is_round_trip: bool = False) -> dict[s
],
}
- # Multi-city (3+ legs): combined price is on the final leg.
- price_segment = segments[-1]
+ # Multi-city (3+ legs) or 2-leg non-round-trip: combined price on the
+ # final leg (matches Google Flights pricing and the CLI display logic).
+ price_segment = segments[-1] if len(segments) > 2 else segments[0]
return {
"price": price_segment.price,
"currency": price_segment.currency or CONFIG.default_currency,
"legs": [
- serialized_leg
+ _serialize_flight_leg(leg)
for segment in segments
- for serialized_leg in [_serialize_flight_leg(leg) for leg in segment.legs]
+ for leg in segment.legs
],
}
diff --git a/tests/cli/test_utils.py b/tests/cli/test_utils.py
index aeda70f..e481eb0 100644
--- a/tests/cli/test_utils.py
+++ b/tests/cli/test_utils.py
@@ -271,6 +271,21 @@ def test_display_round_trip_price_not_doubled():
assert "$634.00" not in output
+def test_display_multi_city_three_legs():
+ """Multi-city (3+ legs) should render without errors, showing final-leg price."""
+ leg1 = _make_flight_result(price=0.0, flight_number="AA100")
+ leg2 = _make_flight_result(price=0.0, flight_number="DL200")
+ leg3 = _make_flight_result(price=800.0, flight_number="UA300")
+
+ output = _capture_display([(leg1, leg2, leg3)])
+
+ assert "$800.00" in output
+ assert "Multi-city Flight" in output
+ assert "Leg 1" in output
+ assert "Leg 2" in output
+ assert "Leg 3" in output
+
+
def test_display_round_trip_price_asymmetric():
"""When leg prices differ, total should be the outbound price, not the sum."""
outbound = _make_flight_result(price=400.0)
diff --git a/tests/mcp/test_mcp_server_fixes.py b/tests/mcp/test_mcp_server_fixes.py
index 06bbd3b..8ae23fe 100644
--- a/tests/mcp/test_mcp_server_fixes.py
+++ b/tests/mcp/test_mcp_server_fixes.py
@@ -152,6 +152,16 @@ class TestSerializeFlightResult:
assert result["price"] == 900.0
assert len(result["legs"]) == 3
+ def test_two_tuple_without_round_trip_uses_outbound_price(self):
+ """A 2-element tuple with is_round_trip=False should use outbound price."""
+ outbound = _make_flight(price=350.0, legs=[_make_leg("JFK", "LAX")])
+ return_flight = _make_flight(price=350.0, legs=[_make_leg("LAX", "JFK")])
+
+ result = _serialize_flight_result((outbound, return_flight), is_round_trip=False)
+
+ assert result["price"] == 350.0
+ assert len(result["legs"]) == 2
+
def test_uses_flight_currency_when_available(self):
"""Serialization should emit the per-result returned currency."""
flight = _make_flight(price=275.0)