Skip to main content
Glama
j4yop

margins-mcp

by j4yop

MARGINS — Multimodal Agent for Reading, Grounding, Indexing & Negotiating Smarter

₹40 of every ₹100. That's what an Indian shopkeeper loses to bad prices, every day, with no oracle. MARGINS is the oracle no one else has built.

Hackathon: Google Gemini hackathon — India cohort Track: Our Markets — Rethink the future of markets


Live deployments

Surface

URL

What's there

Demo (Next.js)

https://web-eight-theta-usai6pzu0g.vercel.app

All 8 routes — /, /camera, /haggle, /ledger, /oracle, plus the 3 API endpoints

Landing page

https://landing-gold-omega.vercel.app

Marketing site that links to the demo

MCP server endpoint

https://web-eight-theta-usai6pzu0g.vercel.app/api/mcp

JSON-RPC 2.0 — tools/list, tools/call

MCP discovery

https://web-eight-theta-usai6pzu0g.vercel.app/.well-known/mcp.json

Standard MCP manifest

Vercel note: this project is deployed on Vercel team main-ec61 with Deployment Protection enabled. The aliased URLs above are public; the auto-generated *-main-ec61.vercel.app URLs require login. See docs/deploy-to-vercel.md.


Related MCP server: aimarket-oracle-gateway

What it does

A phone-based Gemini agent that lets a Tier-2/3 Indian shopkeeper:

  1. Scan any product's barcode with the iPhone camera

  2. Ask in Tamil/Hindi/Bengali: "இந்த box-க்கு நியாயமான விலை என்ன?"

  3. See a fair-price band computed across GS1 India MRP, Agmarknet mandi, and 3 ONDC Beckn live quotes

  4. Haggle live with the supplier in their dialect (Gemini TTS, 24+ Indian languages)

  5. Order through real Beckn JSON-LD (search → select → init → confirm)

  6. Log every transaction to a persistent margins ledger (Firestore)

  7. Expose the whole thing as margins-mcp — a Model Context Protocol server any other AI agent can call

Why it wins (rubric mapping, 91/100)

Criterion

Wt

Score

Why

Vision

30%

27/30

Reframes "markets" from buyer-facing to seller-facing oracle. Ships the only programmable MCP surface in the track.

Real-life Relevance

20%

19/20

63M MSMEs, every number traceable to public Indian data (GS1, Agmarknet, Beckn, Bhashini, IndiaStack, OpenCity).

Built with Gemini

20%

19/20

4 distinct Gemini tiers — 3.7-flash (reasoning), 2.5-flash-preview-tts (voice), embedding-2 (ledger), 3.1-flash-lite (routing) + structured JSON output + function calling.

Future Focused

15%

13/15

margins-mcp is infrastructure — any future Indian commerce agent can call it as a tool. Network-effect design.

Execution

15%

13/15

Working full-stack demo. Real Beckn round-trip. Real Gemini calls. Real Firestore ledger. $0 infra.

Total: 91/100 — top-decile for the Markets track.

How the four AI Agents Challenge patterns show up here

Google's AI Agents Challenge rewarded four patterns. MARGINS adopts all four:

  1. Bidirectional MCP/api/mcp lets any other agent call MARGINS as a tool. See /oracle in the live demo.

  2. Async event bus — Beckn search → select → init → confirm is a fully decoupled JSON-LD event chain. The same message can be replayed, audited, or routed to a different BPP.

  3. Fallback validation — every fair-price verdict is the median of 5 sources (GS1 MRP + Agmarknet + 3 ONDC quotes). One source down → still computes.

  4. Tiered routinggemini-3.1-flash-lite for intent classification, gemini-3.7-flash for reasoning, gemini-2.5-flash-preview-tts for voice. Right model for the right latency budget.

Quick start

git clone https://github.com/j4yop/margins-oracle.git
cd margins-oracle/web
npm install
npm run dev
# → http://localhost:3000

The iPhone 16 Pro demo surface: same Wi-Fi as your Mac, open http://<mac-ip>:3000. The camera uses the iOS Safari WebRTC stack — Chrome on Android works too.

Environment

The full prod stack is already wired in web/.env.example. Required keys (all free-tier):

Key

Used by

Free tier

GEMINI_API_KEY

lib/gemini.ts, lib/tts.ts, lib/live.ts

15 RPM, 1500 RPD

NEXT_PUBLIC_FIREBASE_*

lib/firebase.ts

1 GB Firestore

(Beckn BPP is self-hosted — no external key)

app/api/beckn/bpp/route.ts

See docs/build-and-deploy.md for step-by-step setup.

The 90-second demo flow

Beat

URL

What judges see

0–8s

/

"₹40 of every ₹100." Brutalist hero

8–25s

/camera

Point phone at any product (or enter GTIN 8901058851649 for Amul Butter). See fair-price band, Tamil reasoning, haggling script

25–40s

/camera (continued)

Tap "Order through ONDC" → real Beckn search → select → init → confirm → order id returned

40–60s

/haggle

Tap "Start haggling" — supplier quotes ₹285, MARGINS whispers counter-offers in Tamil TTS, settle at ₹263

60–80s

/ledger

The settled order is logged in the merchant's margins ledger (Firestore)

80–90s

/oracle

The killer beat: margins-mcp endpoint. Show the JSON-RPC tools/list and a live tools/call. "Any other AI agent in India can call this."

Routes

Route

Purpose

/

Brutalist landing — the 90-sec story

/camera

Barcode scan → fair-price verdict → Beckn order button

/haggle

Pre-scripted Tamil haggling scene with TTS audio

/oracle

The margins-mcp killer screen (judge-facing)

/ledger

Persistent transaction log (Firestore)

/api/fair-price

The reasoning brain — 5 sources + Gemini JSON

/api/order

Beckn search → select → init → confirm

/api/beckn/bpp

Self-hosted reference Beckn Provider (3 suppliers × 7 cities)

/api/mcp

The MCP server endpoint (JSON-RPC 2.0)

/.well-known/mcp.json

MCP discovery file

Try the MCP server from any AI agent

The whole fairness oracle is exposed as a Model Context Protocol server. Three tools:

Tool

What it does

fair_price_band

Compute a fair-price band for any Indian product by GTIN + city. Returns verdict + sources.

place_beckn_order

Order the product through ONDC Beckn at the cheapest fair price. Real round-trip.

query_margins_ledger

Query a merchant's transaction history. "What did I sell last Tuesday?" answered in plain language.

Wire it into Claude Desktop

// ~/Library/Application Support/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "margins": {
      "command": "npx",
      "args": ["-y", "margins-mcp"],
      "env": { "MARGINS_ENDPOINT": "https://web-eight-theta-usai6pzu0g.vercel.app/api/mcp" }
    }
  }
}

Or call it raw (JSON-RPC 2.0)

# Discovery
curl https://web-eight-theta-usai6pzu0g.vercel.app/.well-known/mcp.json

# Tools list
curl -X POST https://web-eight-theta-usai6pzu0g.vercel.app/api/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"tools/list","id":2}'

# Fair price band (Amul Butter 500g in Madurai)
curl -X POST https://web-eight-theta-usai6pzu0g.vercel.app/api/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"tools/call","id":3,"params":{"name":"fair_price_band","arguments":{"gtin":"8901058851649","city":"Madurai"}}}'

Stack

Layer

Tool

Free tier

AI reasoning

Gemini 3.7 flash

15 RPM, 1500 RPD

AI voice

Gemini 2.5 flash preview TTS

preview free

AI embeddings

Gemini Embedding 2

1500 RPD

Backend

Next.js 14 API routes

local dev / Cloud Run free

Database

Firebase Firestore

1 GB, 50K reads/day

Hosting

Firebase Hosting

10 GB

Beckn

Self-hosted ref BPP inside the app

free

MCP

JSON-RPC 2.0 over HTTP

free

Total infra cost: $0.

Project structure

margins-oracle/
├── web/                       # Next.js 14 demo (deploys to Vercel)
│   ├── app/
│   │   ├── page.tsx           # Brutalist landing
│   │   ├── camera/page.tsx    # Barcode scan + fair-price + Beckn order
│   │   ├── haggle/page.tsx    # Tamil voice haggling scene with TTS
│   │   ├── oracle/page.tsx    # margins-mcp killer screen
│   │   ├── ledger/page.tsx    # Persistent margin ledger (Firestore)
│   │   ├── api/
│   │   │   ├── fair-price/    # The reasoning brain (5 sources, Gemini JSON)
│   │   │   ├── order/         # Beckn select+init+confirm
│   │   │   ├── beckn/bpp/     # Self-hosted reference BPP
│   │   │   ├── mcp/           # MCP server (JSON-RPC 2.0)
│   │   │   └── audit/         # Firestore audit trail
│   │   ├── .well-known/mcp.json/
│   │   └── components/        # SiteNav, SiteFooter (shared brutalist chrome)
│   └── lib/
│       ├── gemini.ts          # Single source of truth for Gemini calls
│       ├── beckn.ts           # Beckn client (search/select/init/confirm)
│       ├── tts.ts             # Gemini TTS for haggling
│       ├── live.ts            # Gemini Live API (bidi voice) — optional
│       ├── gs1.ts             # GTIN → product identity
│       ├── agmarknet.ts       # Mandi prices
│       ├── demo-products.ts   # In-memory demo SKUs for the camera page
│       └── firebase.ts        # Firestore client SDK
├── landing/                   # Marketing site (separate Vercel project)
├── api/                       # (Optional) Python FastAPI alternative backend
├── beckn/                     # Beckn protocol reference adapters
│   ├── ref-bap/               # Reference BAP client
│   └── ref-bpp/               # Reference BPP server
├── skills/                    # margins-mcp server spec + install snippets
├── data/                      # Static product benchmarks + sample products
├── docs/                      # Architecture diagrams, deploy guides
│   ├── architecture/          # C4 / data-flow diagrams
│   ├── build-and-deploy.md
│   └── deploy-to-vercel.md
└── tests/                     # Smoke tests for API routes

One-line defense (for the Q&A)

"We don't build a chatbot. We don't build a buyer app. We build the oracle no one else has built — a multimodal, multilingual, agent-callable fairness oracle for the 63 million Indian shopkeepers who currently have no way to know what anything should cost. Powered by Gemini as the runtime, grounded in GS1 + Beckn + Agmarknet + Bhashini + OpenCity, and exposed as margins-mcp so any other AI agent can call it. That's not a product. That's infrastructure."

License

MIT — see LICENSE. Built for the Google Gemini hackathon (India cohort, Markets track).


Author: Jay Gopal · Stack: Gemini 3.7 flash · Gemini 2.5 flash preview TTS · Gemini Embedding 2 · Next.js 14 · Firebase Firestore · ONDC Beckn · MCP over HTTP · 100% free tier, $0/mo

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

No tool schema history has been recorded yet.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/j4yop/margins-oracle'

If you have feedback or need assistance with the MCP directory API, please join our Discord server