Hector · one MCP for agency ad data

Hector Architecture

One MCP server that answers questions across Amazon + DSP, Flipkart, Nykaa, Blinkit, Zepto, Instamart, Shopify, Meta, Google and DV360. Vendor data is normalised into one Postgres model. Tools are organised by job, not by vendor, and most of them load only when a question needs them.

System overview

Vendors feed one store on a schedule. Tools read the store, never the vendor live, so questions cost no vendor API calls.

flowchart LR
  subgraph V["Vendors"]
    direction TB
    A1["Amazon Ads + SP-API + DSP"]
    A2["Meta · Google · DV360"]
    A3["Shopify"]
    A4["Flipkart (partner / export)"]
    A5["Blinkit · Zepto · Instamart · Nykaa
(portal exports, no public API)"] end subgraph I["Ingest"] direction TB I1["API pullers"] I2["Report / portal parsers"] end subgraph D["Postgres 17 · one data model"] direction TB D1["Tenancy: agency → users → advertisers"] D2["Product master: SKU ↔ ASIN / FSN / item ids"] D3["Facts: ads · sales · stock · POs · search terms
listing · audience · attribution · reviews"] D4["Row-level security on advertiser_id"] end subgraph M["Hector MCP"] direction TB M1["7 core tools, always listed"] M2["8 groups, loaded on demand
find_capability"] end subgraph C["Clients"] direction TB C1["Hector chat (AgentUX)"] C2["Claude.ai / Desktop / Code"] end A1 --> I1 A2 --> I1 A3 --> I1 A4 --> I2 A5 --> I2 I1 --> D I2 --> D D --> M M --> C1 M --> C2

How one question is answered

Each tool call runs in its own Postgres transaction scoped to the caller's brands. The model gets a compact table back, not raw vendor JSON.

sequenceDiagram
  participant U as User
  participant A as Agent (chat / Claude)
  participant H as Hector MCP
  participant P as Postgres
  U->>A: Why is Revitalift soft on Nykaa?
  A->>H: get_performance (core tool)
  A->>H: find_capability "keywords, reviews"
  H-->>A: loads keyword_optimizer + marketplace_listing
  A->>H: get_keyword_market, get_reviews, get_inventory
  H->>P: BEGIN READ ONLY · SET LOCAL hector.advertiser_ids = 'loreal_paris'
  P-->>H: rows for that brand only (RLS)
  H-->>A: small markdown tables, INR, caveats
  A-->>U: cause + action (organic rank loss to Competitor C)

Table architecture

Everything a brand owns carries advertiser_id. Vendors are rows (platform = 'blinkit'), not separate tables or tools.

erDiagram
  agencies ||--o{ users : employs
  agencies ||--o{ advertisers : manages
  users ||--o{ user_advertiser_access : "can see"
  advertisers ||--o{ user_advertiser_access : ""
  advertisers ||--o{ connections : "platform accounts"
  advertisers ||--o{ products : sells
  products ||--o{ product_map : "ASIN / FSN / item id"
  advertisers ||--o{ campaigns : runs
  campaigns ||--o{ keyword_targets : bids
  campaigns ||--o{ fact_ad_daily : "daily results"
  campaigns ||--o{ fact_search_term_daily : "search terms"
  products ||--o{ fact_sales_daily : "sell-out"
  products ||--o{ fact_listing_daily : "listing health"
  products ||--o{ fact_inventory_daily : "darkstore stock"
  products ||--o{ fact_fc_inventory_daily : "warehouse stock"
  products ||--o{ purchase_orders : "QC POs"
  products ||--o{ reviews : reviews
  advertisers ||--o{ fact_keyword_market_weekly : "keyword market"
  advertisers ||--o{ fact_audience_weekly : audience
  advertisers ||--o{ fact_attribution_weekly : "cross-channel"
  advertisers ||--o{ fact_qc_market_daily : "QC share"
  advertisers ||--o{ advertiser_notes : memory

  advertisers {
    text id PK
    text business_model
    numeric target_roas
    numeric target_tacos
  }
  campaigns {
    text id PK
    text advertiser_id FK
    text platform
    text ad_type
    numeric daily_budget_inr
  }
  fact_ad_daily {
    date date
    text campaign_id FK
    text sku
    text city
    numeric spend_inr
    bigint orders
    numeric ad_revenue_inr
  }
  fact_search_term_daily {
    date date
    text campaign_id FK
    text keyword
    text search_term
    numeric spend_inr
    bigint orders
  }
  product_map {
    text sku FK
    text platform
    text platform_item_id
  }
TableGrainAnswersFed by
Tenancy + reference
agencies · users · user_advertiser_accessrow per user / grantwho can see which brands (role: admin, account manager, client viewer)Hector
advertisersbrandbusiness model, KPI targetsHector
connectionsbrand × platformaccount ids, ingest method, last syncall
products · product_mapSKU · SKU × platformone SKU linked to ASIN, FSN, Blinkit / Zepto / Shopify idsall
Ads
campaignscampaigntype, objective, status, budgetall ad platforms
fact_ad_dailyday × campaign × SKU × cityspend, clicks, ROAS, viewability, VCR, DPV, new-to-brandAmazon, DSP, Flipkart, Nykaa, QC, Meta, Google, DV360
keyword_targetskeyword × campaignbids, match types, negativessearch platforms
fact_search_term_dailyday × campaign × search termwhat shoppers typed, wasted vs converting spend (reconciles to campaign spend)Amazon, Flipkart, Nykaa, QC, Google
fact_keyword_market_weeklyweek × platform × termsearch volume, our click/conversion share, top competitorAmazon, Flipkart, Nykaa
Sales + listings
fact_sales_dailyday × platform × SKU × cityorganic + paid sell-out, TACoS, MERAmazon, Flipkart, QC, Nykaa, Shopify
fact_listing_dailyday × platform × SKUsessions, conversion, Buy Box, BSR, rating, returnsAmazon, Flipkart, Shopify
reviewsreviewrating, theme, sentiment, textAmazon, Flipkart, Nykaa
Stock + supply
fact_inventory_dailyday × QC platform × SKU × citydarkstore availability (OSA), units on handBlinkit, Zepto, Instamart
fact_fc_inventory_dailyday × platform × SKU × locationFBA / Flipkart / Shopify available, inbound, days of coverAmazon, Flipkart, Shopify
purchase_ordersPOfill rate, expiriesBlinkit, Zepto, Instamart
fact_qc_market_dailyday × QC platform × citycategory market shareBlinkit, Zepto, Instamart
Audience + cross-channel
fact_audience_weeklyweek × platform × segmentage, gender, device, city tier, new vs returningMeta, Google, DV360, Amazon DSP
fact_attribution_weeklyweek × source channelMeta / YouTube / DV360 clicks that became Amazon salesAmazon Attribution
fact_conversion_pathsmonth × pathad sequences before purchase, order value, days to convertAMC
Memory + audit
advertiser_notes · action_lognote · changeclient instructions; every budget / keyword changeHector

Tools

Grouped by the job the user is doing. The platform registry decides which groups a user is offered, so a Meta-only brand never sees quick-commerce tools.

GroupToolsLoaded
corelist_accounts, get_performance, morning_check, get_brand_context, save_note, find_capability, run_capabilityalways
inventory_supplyget_inventory, get_purchase_orderson demand
marketplace_listingget_listing_health, get_reviewson demand
digital_shelfget_share_of_voice, get_market_shareon demand
keyword_optimizerget_search_terms, get_keyword_market, recommend_keywords, update_keywordson demand
audience_insightsget_audience, get_cross_channelon demand
campaign_actionslist_campaigns, update_campaignon demand, not for client logins
sql_explorerrun_query (read-only)on demand
referencedescribe_platforms, describe_data_model, describe_metricson demand

Live data and vendors without APIs

Tools always read Hector's data model, never the vendor directly. Freshness is handled behind the tools, so how a vendor's data arrives can change without changing the MCP.

flowchart LR
  Q["Question"] --> T["Tool"]
  T --> F{"Data fresh enough?"}
  F -- "yes" --> DB[("Hector data model")]
  F -- "no · API vendor
Amazon, Meta, Google, Shopify" --> R1["Pull that brand, platform
and date range now"] R1 --> DB F -- "no · portal-only vendor
Blinkit, Zepto, Instamart, Nykaa" --> R2["Queue a refresh job
(portal automation)"] R2 -.-> DB R2 --> N["Answer now with 'as of' time,
update when the pull lands"]

Key decisions

Demo data only: 4 fictional brands plus L'Oréal Paris as an illustrative example, 90 days, with planted problems for the agent to find. None of the numbers are real. Production still needs real ingest connectors, OAuth instead of API keys, and vendor write APIs for campaign and keyword changes.