MCP Tool: codeshare_sync_audit
Overview
codeshare_sync_audit is a BigQuery MCP tool that performs a daily 1-to-1
mirror audit between an operating carrier's own-metal schedule and a specific
codeshare partner's marketed schedule. It detects schedule discrepancies that
require a partner change.
The audit flags one of three actions for each future flight date:
| Action | Meaning |
|---|---|
| ADD | Operating flight exists, but partner has no matching marketing record |
| DELETE | Partner markets a flight with no operating record |
| UPDATE | Both records exist, but attributes differ |
Example Prompts
Background
Codeshare synchronisation is validated in both directions:
| Direction | Table | DEI | Purpose |
|---|---|---|---|
| Operating carrier → partner | ssim_4 on the operating record | 10, 50 | Link operating flight to partner marketing flight |
| Partner → operating carrier | ssim_4 on the partner record | 50, 127 | Link marketing flight back to operating flight |
Both sides must be audited to catch ghost marketing records and missing partner links.
Key SQL invariants
- Whitespace-agnostic regex — handles variable DEI padding like
DL 1vsDL 1 - INT64 casting — flight numbers are cast before comparison
- COALESCE NULL date handling — open-ended schedules use the dataset maximum date
- UTC normalisation — UTC offsets are compared as hours after dividing by 100
- Future-only filter — only dates on or after
CURRENT_DATE()are audited - Service type =
Jonly — excludes surface and helicopter equipment
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
dataset_id | string (template) | Yes | — | Published SSIM dataset id (e.g. ssim_published_2026w21) |
operating_carrier | string | Yes | — | IATA code of the operating carrier |
flight_range_start | integer | Yes | 1 | Lower bound of operating flight number range |
flight_range_end | integer | Yes | 9999 | Upper bound of operating flight number range |
partner_carrier | string | Yes | — | IATA code of the marketing partner carrier |
Flight range defaults
| Intent | flight_range_start | flight_range_end |
|---|---|---|
| All flights | 1 | 9999 |
| Explicit range | specified | specified |
| Start only | specified | 9999 |
| End only | 1 | specified |
operating_carrier and partner_carrier must always be provided.
How the tool resolves DEI links
Operating side
ssim_3filtered byflight_airline_designator = operating_carrierflight_number BETWEEN flight_range_start AND flight_range_endservice_type = 'J',operating_airline_disclosure IS NULL- join
ssim_4ondata_element_identifier IN (10, 50) - filter DEI text for the partner carrier
- extract and cast linked partner flight number to
INT64
Partner side
ssim_3filtered byflight_airline_designator = partner_carrierservice_type = 'J',operating_airline_disclosure IN ('L', 'S', 'Z')- join
ssim_4ondata_element_identifier IN (50, 127) - filter DEI text for the operating carrier
- extract and cast linked operating flight number to
INT64
Output Columns
Results are pattern-grouped: all consecutive dates requiring the same fix are collapsed into a single row.
| Column | Description |
|---|---|
MKT_CARRIER | Partner carrier IATA code |
MKT_FLT | Partner marketing flight number |
OP_FLT | Operating carrier flight number |
DEP | Departure station IATA code |
ARR | Arrival station IATA code |
SCHEDULER_ACTION | ADD, DELETE, or UPDATE |
MISMATCH_DETAIL | Pipe-delimited list of differing attributes (UPDATE only) |
START_DATE | First date in this discrepancy block |
END_DATE | Last date in this discrepancy block |
TOTAL_DAYS | Number of dates in this block |
OP_DEP_LOCAL | Operating carrier local departure time (HHMM integer) |
OP_ARR_LOCAL | Operating carrier local arrival time (HHMM integer) |
OP_UTC_DEP | Operating carrier UTC departure offset (2-digit hours) |
OP_UTC_ARR | Operating carrier UTC arrival offset (2-digit hours) |
OP_EQUIP | Operating carrier aircraft type code |
OP_MEALS | Operating carrier meal service code |
OP_DEP_TERM | Operating carrier departure terminal |
OP_ARR_TERM | Operating carrier arrival terminal |
All headers are uppercase.
Row limit: 20 000 rows (source: bigquery-source-override-rows). The SQL
imposes no additional LIMIT clause. If the result exceeds 50 rows, the
analytics agent saves the data as a session artifact and passes it to the
artifact agent before CSV export.
Agent Routing
The root agent routes this tool to analytics_agent.
Trigger phrases:
- "run the codeshare sync audit for [partner] and [operating carrier]"
- "daily mirror audit for [carrier] flights [range] with partner [partner]"
- "audit all [carrier] flights with partner [partner]"
- "check if [partner]'s marketed flights match [carrier]'s operating schedule"
- "find discrepancies between [carrier] operating flights and [partner] marketing"
- "what needs to be added, deleted or updated in [partner]'s schedule for [carrier]?"
- "run the schedule synchronisation audit for [carrier] / [partner]"
Large result handling
codeshare_sync_audit is registered in the analytics agent's tools_to_csv
list. After every call:
- The result is saved as a session artifact named
codeshare_sync_audit.csv. - If the result has ≤ 100 rows, the CSV data is returned directly.
- If the result has > 100 rows, the callback returns only the row count and
next-action prompt. The agent then follows post-results rules for
CODESHARE_SYNC_AUDIT.
Direct Execution — No Confirmation Required
The analytics agent calls this tool as soon as operating_carrier and
partner_carrier are known. There is no confirmation round-trip.
Execution sequence:
- Call
bigquery_list_dataset_idsto resolvedataset_id. - Apply flight range defaults if no range was specified.
- Call
codeshare_sync_auditimmediately with all resolved parameters.
This replaces the previous mandatory two-turn handshake.
Dataset Resolution
The current schedule dataset is the last entry when all dataset ids are sorted alphabetically (year takes priority over week number):
ssim_published_2025w52 ← previous
ssim_published_2026w21 ← current ✓
Do not subtract 1 from the week number at year boundaries.
2026w01 - 1 ≠ 2026w00.
Example Prompts & Expected Tool Calls
1. Audit AF-marketed flights for DL operating range 1–100
User prompt:
Run the codeshare sync audit for partner AF, operating carrier DL, flights 1 to 100.
Agent calls immediately:
dataset_id = ssim_published_2026w21
operating_carrier = DL
flight_range_start = 1
flight_range_end = 100
partner_carrier = AF
2. Audit all flights (no range specified)
User prompt:
Run the codeshare sync audit for all DL flights with partner AF.
Agent calls immediately:
dataset_id = ssim_published_2026w21
operating_carrier = DL
flight_range_start = 1
flight_range_end = 9999
partner_carrier = AF
3. Multi-carrier session — iterate through partners
User prompt:
I want to run the daily mirror audit for all KM codeshare partners.
Start with AZ for KM operating flights 2200–2299.
Agent flow:
- Run audit for
operating_carrier=KM,partner_carrier=AZ,flight_range_start=2200,flight_range_end=2299. - After CSV export, ask whether to proceed to the next range or the next partner.
- Continue with additional partner ranges.
4. Single discrepancy check
User prompt:
Find discrepancies between KM operating flights 2300-2399 and LH marketing.
Agent calls immediately:
dataset_id = ssim_published_2026w21
operating_carrier = KM
flight_range_start = 2300
flight_range_end = 2399
partner_carrier = LH
5. Schedule synchronisation check
User prompt:
Check if BT's marketed flights match KM's operating schedule for flights 2800-2849.
Agent calls immediately:
dataset_id = ssim_published_2026w21
operating_carrier = KM
flight_range_start = 2800
flight_range_end = 2849
partner_carrier = BT
Chat Display Rules
- If the audit returns ≤ 10 discrepancy blocks, display all rows as a markdown table with uppercase headers.
- If the audit returns > 10 blocks, show only the first 10 and say: "Showing first 10 of [Total] discrepancy blocks. Please export to CSV for the full report."
- After displaying results, ask: "Would you like to export these results to [partner_carrier]_[range_start]-[range_end]_Audit.csv?"
- If the user confirms export and the row count exceeds 50:
- Transfer to
artifact_agentwith explicit instructions to callload_filter_artifact_datafor rows1tototal. - Do not ask
artifact_agentfor filter criteria. - Then transfer to
csv_agent.
- Transfer to
- If the row count is ≤ 50, transfer directly to
csv_agent.
SQL Design Notes
The query uses five CTEs:
op_truth— operating carrier flights with confirmed DEI links to the partner.op_expanded— expands operating flights into daily dates with null-date guards and day-of-week filtering.mkt_reality— partner marketing flights whose DEI links point to the operating carrier.mkt_expanded— expands marketing flights into daily dates with the same guards.audit_join— full outer join on operating flight, partner flight, route, and date.
The final SELECT collapses consecutive matching dates into a single pattern block
and filters SCHEDULER_ACTION != 'MATCH'. No SQL-level LIMIT is applied;
row capping is handled by bigquery-source-override-rows.
Relationship to Other Tools
| Tool | Use case |
|---|---|
codeshare_sync_audit | Daily bi-directional mirror audit between one operating carrier flight range and one partner carrier |
codeshare_analysis | Codeshare classification and operating carrier resolution at a station |
hub_activity_extract_report | Full hub schedule extract for a single date |
execute_sql_tool | Ad-hoc SQL for cases not covered by custom tools |