Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 7 min read

I Cut My Flight MCP Answers by 75% for the Agent. The Fields I Cut Were the Ones That Explained the Prices

I run a visa agency in Bali, and in the evenings I build data tools on Apify. One of them is not a scraper but an MCP server: Flights MCP Server. You point Claude, Cursor or any MCP client at one URL, and the agent gets

I run a visa agency in Bali, and in the evenings I build data tools on Apify. One of them is not a scraper but an MCP server: Flights MCP Server. You point Claude, Cursor or any MCP client at one URL, and the agent gets four tools β€” search_flights, compare_flight_prices, cheapest_dates, cheap_destinations. Each tool runs one of my flight Actors on the caller's own Apify account and hands back a trimmed answer.

"Trimmed" is the design decision this post is about. A raw Google Flights row from my scraper is about 1,500 characters: legs, aircraft, legroom, emissions, booking tokens, bag allowances. An agent doesn't need most of that, and every byte you return is context the model has to read. So the server maps each row through a small slim() function and keeps a dozen fields.

Tonight I did something I should have done when I wrote it: I made three real tool calls the way an agent makes them, then opened the full datasets of the Actor runs behind those calls and compared what the agent got with what the server threw away.

Calling it without a client

The server speaks streamable HTTP. You don't need Claude Desktop to talk to it β€” three JSON-RPC requests are enough:

import json, requests

URL = "https://lergassy--flights-mcp-server.apify.actor/mcp"
H = {"Authorization": "Bearer <YOUR_APIFY_TOKEN>",
     "Content-Type": "application/json",
     "Accept": "application/json, text/event-stream"}

def rpc(body, sid=None):
    h = dict(H, **({"mcp-session-id": sid} if sid else {}))
    r = requests.post(URL, headers=h, json=body)
    data = [l[5:] for l in r.text.splitlines() if l.startswith("data:")]
    return r.headers.get("mcp-session-id", sid), (json.loads(data[-1]) if data else None)

sid, _ = rpc({"jsonrpc": "2.0", "id": 1, "method": "initialize",
              "params": {"protocolVersion": "2025-03-26", "capabilities": {},
                         "clientInfo": {"name": "probe", "version": "1"}}})
rpc({"jsonrpc": "2.0", "method": "notifications/initialized", "params": {}}, sid)
_, res = rpc({"jsonrpc": "2.0", "id": 2, "method": "tools/call",
              "params": {"name": "search_flights",
                         "arguments": {"origin": "DPS", "destination": "SIN",
                                       "departureDate": "2027-03-15", "limit": 10}}}, sid)
print(res["result"]["content"][0]["text"])

The numbers from my session, from a test account with no warm server:

Request HTTP Time Response size
initialize 200 3.2 s 196 B
tools/list 200 0.15 s 4,139 B
search_flights DPS→SIN, 15 Mar 2027 200 18.5 s 3,850 B
cheapest_dates DPS→SIN, March 2027 200 17.3 s 1,195 B
cheap_destinations from DPS 200 15.4 s 2,506 B

The 3.2 seconds on initialize is the Standby server waking up. The 15–18 seconds on each tool is a full Actor run being started, finishing and having its dataset read. An agent that chains three tools makes the user wait close to a minute.

The raw dataset behind search_flights was 15,468 characters for 10 rows. The agent received 3,850. A 75% cut. Now, what was in the other 75%.

1. Every fare was "high". High compared to what?

The agent got eight itineraries. All eight carried "priceLevel": "high" β€” Jetstar JQ86 at $81, KLM at $82, three Scoot flights at $100, Singapore Airlines at $137 and $149.

That's Google's own verdict, and the tool description promises it ("Google's own low/typical/high price verdict"). What the agent can't do with it is answer the follow-up any traveller asks next: how much would a normal price be?

The answer was sitting in every raw row:

"priceLevel": "high",
"typicalPriceLow": 40,
"typicalPriceHigh": 70

Google thinks this route usually costs $40–70. The cheapest fare that day is $81, so "high" means "about $11 over the top of normal", not "double". My slim() kept the label and dropped the two numbers that give it meaning. An agent told "high" with no range will repeat the word or invent a typical price.

Rule I'm taking from this: when you shorten a row for a model, never keep a verdict without the numbers it was derived from. A label is a compression of data; the agent can't decompress it.

2. Bali to Surabaya for $85 β€” one way or return?

cheap_destinations from DPS returned ten places, cheapest first:

City Airport Price Date the agent saw
Surabaya SUB $85 2026-11-30
Labuan Bajo LBJ $104 2026-11-30
Yogyakarta YIA $136 2026-11-30
Perth PER $183 2027-02-07
Darwin DRW $217 2027-04-18
Cairns CNS $258 2027-03-05
Melbourne AVV $261 2027-02-18
Adelaide ADL $328 2027-02-11
Brisbane BNE $347 2027-02-21
Sydney SYD $352 2027-03-01

Every one of those prices is a round trip. The raw rows say so: "tripType": "round_trip", a returnDate (Surabaya back on 7 December, Perth back on 13 February), and a tripLengthDays. The slim version kept departureDate and dropped all three.

So an agent asked "where can I fly cheaply from Bali?" would read "Surabaya $85, 30 November" and very reasonably tell the user it's $85 to get there. In fact it's $85 there and back, on dates the user never chose. Compare that with search_flights on the same server, where price is one-way unless you pass returnDate. Same field name, two meanings, and nothing in the answer to tell them apart.

Two smaller things in the same table. "Melbourne" is AVV β€” Avalon, about an hour from the city, not Tullamarine (MEL). The city name came from Google; the airport code is the only honest field there, and I'm glad that one survived. And the first three dates are seven days from the day I ran it: the explore view prices the nearest bookable week, so these numbers are a snapshot of next week, not a seasonal truth.

3. Two flights the agent never heard about

I asked for limit: 10. The tool said "found": 8. The run summary row in the Actor's dataset said:

Run summary: 10 row(s) delivered, 0 free; charged flight Γ—10 = $0.01.

The two missing ones were TransNusa 8B553 at 10:20 and Garuda Indonesia GA842 at 14:00 β€” real, nonstop departures on that date that came back without a price. The server filters price out-of-hand (items.filter(i => i.price)), which is reasonable for "cheapest fare" questions and wrong for "what flies DPS–SIN on the 15th?". Garuda being invisible to an agent answering a Bali question is not a small omission.

It's also a billing mismatch: the caller paid the underlying Actor for 10 rows and their agent saw 8. If a tool drops rows, it should say how many and why β€” "found": 8, "unpriced": 2 costs a dozen bytes.

4. The calendar marked five cheapest days out of seven

cheapest_dates for March 2027 is the tool I like most: one call, 31 days of lowest fares. The agent got the ten cheapest days and a count. Here is the whole month from the raw dataset (* = flagged isCheapest):

01  65   02  65   03  48*  04  48*  05  48*  06  48*  07  76
08 300   09  48*  10  54   11  48   12  48   13  65   14  82
15  81   16  66   17  62   18  62   19  62   20  70   21  76
22  65   23  59   24  55   25  55   26  70   27  76   28 114
29  66   30  66   31  55

Seven days cost $48. Five were flagged as cheapest; 11 and 12 March, at the same $48, were not. The flag comes from a cheapestDates list in the calendar summary, and that list is capped at five entries. An agent that trusts the flag ("the cheapest days are the 3rd–6th and the 9th") will skip two equally cheap options β€” and the 11th–12th is a Thursday–Friday, which for a lot of travellers is the more useful pair.

Two more things the full month shows that the top-ten cut hides. The 15th β€” the date I'd just searched β€” costs $81 in the calendar, exactly what search_flights returned, so the two tools agree with each other; good. And 8 March costs $300, six times its neighbours. I can't say from one read whether that's a spike or a glitch, and the agent never sees it. If the user's question is "is there any day in March I should avoid?", the answer is in the data and not in the response.

What it cost

Three answering tool calls were charged at $0.03 each. The Actor runs behind them were billed separately on the same account: $0.01 for the 10-row search, $0.0062 for the 31-day calendar, $0.002 for ten destinations. About $0.11 for a session that answered three questions. A call that can't answer anything is not charged β€” that part works as designed.

When not to use this

  • Batch pricing. If you want fares for 500 routes overnight, call the underlying Actors directly from code. The MCP layer adds per-call overhead and trims fields you will want.
  • Anything needing the full itinerary. Legs, aircraft, legroom, bag allowance and emissions are all in the raw row and none of them reach the agent.
  • Hard latency budgets. 15–18 seconds per tool is fine in a planning chat and too slow for an interactive widget.

What I'm changing

The fixes are obvious once you see the raw data side by side: keep typicalPriceLow/typicalPriceHigh next to priceLevel, keep tripType and returnDate on destinations, report unpriced flights instead of silently dropping them, and flag every day that ties the lowest calendar price rather than the first five.

The general lesson is the one I'd pass to anyone wrapping a scraper as an agent tool: trimming is an editorial decision, not a formatting one. Before you ship a slim() function, run one real call, open the raw row next to the trimmed one, and ask of every dropped field: could the agent's next sentence be wrong without it? For three of mine, the answer was yes.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.