πŸͺ Hoo Tim Analytics Agent

Live AI agent + MCP tools for a Selangor snack distributor

Gemini 2.0 Flash MCP Framework BYO API Key Vanilla JS GitHub Pages

πŸ“‹ Project Overview & Problem Statement

Challenge: Malaysian FMCG distributors operate on thin margins (20–25% gross) with long reseller tails β€” one distributor might service 200–400 outlets across supermarkets, minimarkets, petrol stations, and sundry shops, spread across 9 Selangor districts from Sabak Bernam to Sepang. The data exists (every order line is captured in the invoicing system) but it never turns into insight. The boss asks "which outlets are slipping?" and the spreadsheet takes hours to answer.

Solution: Hoo Tim Analytics Agent is a live AI agent that answers distribution questions in seconds. The user brings their own Gemini API key, the agent selects from a catalog of 5 MCP tools, queries pre-aggregated distribution data, and writes a grounded answer with tables and recommendations in plain Malaysian English. Unlike static demos, every answer is generated live β€” no hardcoded responses.

Why this matters: Existing producer-distributor transitions (e.g. Apollo's FY26Q1 "distribution network reconfiguration") show that Malaysian snack producers are actively rethinking their partners. A distributor that can demonstrate live SKU performance, outlet-level health, and delivery reliability β€” not just ship-and-forget β€” becomes the kind of "robust and agile distributor" producers want to keep.

Notice: Hoo Tim Biscuits is a fictional Malaysian snack distributor created for portfolio purposes. The dataset is synthetic. No affiliation with any real brand.

πŸ“Š Data at a Glance

RM 2.45M
December Revenue
6,074
Order Lines
300
Active Resellers
40
SKUs
9
Selangor Districts
24.2%
Gross Margin

πŸ”§ MCP Tool Catalog (5 Tools)

The agent picks tools based on the question β€” each tool runs deterministic queries against the pre-aggregated dataset in the browser, then hands the result to Gemini for narrative synthesis.

get_aggregate(dim) β€” Group-by aggregation over district / channel / category / SKU (revenue, cost, margin, quantity).

get_top_n(dim, n, direction) β€” Top or bottom N by a metric. Powers "top 10 SKUs" and "slow movers".

get_cross_tab(row_dim, col_dim) β€” 2D breakdowns (district Γ— channel, category Γ— channel).

get_delivery_performance(group_by) β€” On-time / slightly late / very late percentages by district or channel.

get_time_series(period) β€” Daily trend or Christmas–New Year campaign window (15–31 Dec vs 1–14 Dec).

❓ 15 Preset Questions

Organised by analytical focus area β€” each one answerable from the dataset.

Sales Performance

  • Which 10 SKUs generated the highest revenue, and what share of total sales?
  • Which SKUs are slow movers (bottom 10 by volume)?

Channel & Outlet Intelligence

  • Revenue split across channels, and best revenue per outlet?
  • Top 20 resellers by revenue and their concentration?
  • Resellers ordering below their channel average (at-risk)?

Geographic Coverage

  • Revenue split across the 9 Selangor districts, and under-served ones?
  • Strongest vs weakest district–channel combinations?

Category

  • Top category by December revenue, and its share?
  • Category mix variation across channels?

Margin

  • Category with highest total gross margin (RM profit)?
  • Category with thinnest gross margin % for price review?

Operations & Delivery

  • On-time delivery rate by district, and worst performers?
  • Channels suffering most from late deliveries?

Demand Timing

  • Daily order volume trend across December, and festive spike days?
  • Christmas–New Year (15–31 Dec) revenue share vs first half (1–14 Dec)?

πŸ—οΈ How It Works

1. Bring Your Own Key

Paste a Gemini API key at the top of the demo. It stays in the browser session only β€” never sent anywhere except directly to Google's Gemini API. Free tier works fine for testing.

2. Tool Dispatch

The agent uses keyword-based dispatch to pick relevant MCP tools from the catalog of 5. The MCP panel highlights the active tools; a dark terminal line logs the actual tool call with arguments and row counts.

3. In-Browser Query

Each tool runs deterministic queries against 129KB of pre-aggregated JSON β€” real numbers, not a sample. Results are always truthful to the underlying 6,074-row dataset.

4. Grounded Narrative

Gemini 2.0 Flash receives the tool outputs, the user's question, and strict grounding rules ("do not invent figures"). It writes a markdown answer with a table, a 1-sentence Insight, and a Recommendation bullet.

5. Live UI Feedback

Two-panel brown/gold layout. Left: persona and business context. Right: API key bar, tool catalog, 15 quick-ask buttons grouped by focus area, and a chat thread showing tool trace + agent answer.

6. No Backend Required

Single static HTML page + data.js, hosted on GitHub Pages. Zero server cost, zero API key management on the site side. A portfolio demo that works indefinitely without maintenance.

πŸ› οΈ Tech Stack

Gemini 2.0 Flash MCP-style Tools Python (precompute) Vanilla JS Poppins GitHub Pages

🎯 Who Benefits