Kerala’s spice trade spans regulated markets, auction centres, commission agents, exporters, and local wholesale networks. Prices for pepper, cardamom, turmeric, ginger, chillies, cloves, and other commodities can change by market, grade, moisture, origin, arrival volume, and trading session. For an AI agent, simply browsing a mandi website is not enough: it needs structured tools, trustworthy sources, clear units, timestamps, and safeguards against stale or misleading prices.
A WebMCP—short for Web Model Context Protocol in this article—can provide that controlled interface. It exposes web-based data and actions to an AI agent through typed tools such as search_mandi_prices, compare_markets, and create_price_alert. This guide explains how to create a WebMCP for agents to monitor wholesale prices of spices in Kerala mandis, from data architecture and tool design to validation, deployment, and India-specific compliance considerations.
What a WebMCP does for mandi-price monitoring
A WebMCP sits between an AI agent and the websites, APIs, spreadsheets, or databases that contain market information. Instead of allowing an agent to scrape arbitrary pages, the protocol exposes narrow, auditable capabilities.
A typical flow is:
1. A buyer asks: “Show today’s wholesale black pepper prices in Kerala.”
2. The agent calls a WebMCP tool with commodity, location, grade, date, and unit parameters.
3. The server retrieves data from approved sources.
4. The server normalizes prices and returns structured results with source URLs and timestamps.
5. The agent compares markets, explains uncertainty, and optionally triggers an alert.
This separation is important because language models are good at interpreting requests but should not be trusted to invent prices, infer units, or silently substitute one grade for another.
Define the monitoring use case precisely
Before writing code, create a market-data specification. “Spice price” is too broad for reliable automation. Define:
- Commodities: black pepper, green cardamom, dry ginger, turmeric, chilli, nutmeg, mace, clove, cinnamon, and commodity-specific variants.
- Market locations: Kerala mandis, auction centres, wholesale yards, and named markets such as those around Idukki, Wayanad, Kozhikode, Kochi, or other verified trading locations.
- Price type: modal, minimum, maximum, auction-clearing, wholesale quote, or indicative price.
- Grade and quality: bold pepper, FAQ grade, garbled pepper, dried ginger grade, moisture band, size, origin, and certification where available.
- Unit: ₹/kg, ₹/quintal, ₹/tonne, or ₹/lot. Store the original unit and a normalized base unit.
- Time window: current session, today, previous trading day, seven-day average, or historical range.
- Freshness requirement: for example, data no older than 30 minutes for alerts or 24 hours for daily reports.
A strong specification prevents a common failure: comparing a cardamom auction price per kilogram with a broad wholesale quotation per quintal as though they were equivalent.
Recommended WebMCP architecture
Use a layered architecture so that source changes do not break agent-facing tools.
1. Source connectors
Connectors fetch data from approved sources, such as:
- Official market or auction APIs
- Government agricultural price portals
- Kerala market notices and downloadable files
- Licensed data providers
- Structured feeds supplied by mandis, cooperatives, or commission agents
- Carefully governed website extraction where terms and robots directives permit it
Do not assume that a public webpage grants permission to scrape, republish, or commercially redistribute its data. Review terms of use, access limits, attribution requirements, and licensing.
2. Raw data store
Store every retrieved record without modification. Include:
- Source identifier and URL
- Retrieval timestamp in UTC and Asia/Kolkata time
- Original text and numeric values
- HTTP status or API response metadata
- Parser version
- Hash of the source response
Raw retention makes corrections and disputes auditable.
3. Normalization pipeline
Transform source records into a canonical schema. Keep both the original and normalized values so a user can understand how a conversion occurred.
4. Market database
PostgreSQL works well for structured prices, while object storage can hold raw files and page snapshots. Useful indexes include commodity, market, grade, observed timestamp, and source.
5. WebMCP server
The server exposes typed tools and resources to the agent. It handles authorization, validation, rate limiting, caching, source selection, and response formatting.
6. Agent and user interface
The agent interprets natural-language requests, calls tools, explains results, and asks clarifying questions when a commodity, grade, market, or date is ambiguous.
Design a canonical spice-price schema
A practical record might contain the following fields:
{
"commodity": "black_pepper",
"market": "Idukki",
"market_type": "wholesale_market",
"grade": "unspecified",
"price_type": "modal",
"price": 642.50,
"currency": "INR",
"unit_original": "quintal",
"price_inr_per_kg": 64.25,
"observed_at": "2026-09-03T09:30:00+05:30",
"source": {
"name": "approved_market_feed",
"url": "https://example.org/feed",
"retrieved_at": "2026-09-03T09:35:00+05:30"
},
"confidence": "medium"
}In production, do not infer missing grades or price types. Use null or unspecified, and tell the agent why a comparison may be limited.
Unit conversion rules
Store conversions as explicit functions rather than prompt instructions. Examples:
- ₹/quintal ÷ 100 = ₹/kg
- ₹/tonne ÷ 1,000 = ₹/kg
- ₹/kg × 100 = ₹/quintal
Validate that the source uses a metric quintal and not a lot-specific or auction-specific unit. Lot prices require a known lot weight before conversion.
Define agent-facing WebMCP tools
Keep tools narrow and predictable. A useful initial tool set includes:
search_mandi_prices
Parameters:
{
"commodity": "black_pepper",
"markets": ["Idukki", "Kozhikode"],
"grade": "optional",
"from": "2026-09-03T00:00:00+05:30",
"to": "2026-09-03T23:59:59+05:30",
"normalized_unit": "INR_per_kg"
}Return records, source metadata, freshness, and any caveats. Reject unknown commodities rather than searching broadly and guessing.
compare_mandi_prices
This tool should compare like-for-like records only. It should group by commodity, grade, price type, and observation window. If grades differ, return separate groups or mark the result as non-comparable.
get_price_history
Support daily or session-level history with a maximum range. Return observations, median, minimum, maximum, percentage change, and the number of valid records—not just a model-generated summary.
detect_price_anomaly
Use a transparent method such as a rolling median and median absolute deviation. A simple percentage threshold can be useful, but it should be commodity- and market-specific. Flag anomalies for review rather than declaring fraud or a guaranteed price movement.
create_price_alert
Allow alerts such as:
- Black pepper exceeds ₹X/kg in a selected market
- Cardamom falls below a threshold
- Price changes by more than Y% from the previous valid observation
- No fresh data has arrived within the expected interval
Require authentication and confirmation before creating alerts. Never let an agent subscribe a user to notifications based only on an ambiguous conversation.
Tool response format and provenance
Every response should make provenance first-class. Include:
data_as_ofretrieved_atsource_namesource_urlsource_license_or_attributionrecord_countfreshness_statusnormalization_noteswarnings
Example:
{
"status": "ok",
"data_as_of": "2026-09-03T09:30:00+05:30",
"records": [],
"warnings": [
"Idukki records are modal wholesale prices; Kozhikode has only an indicative quote.",
"No grade was supplied, so results are not quality-equivalent."
]
}This enables the agent to say, “The latest comparable modal quote is ₹X/kg as of 9:30 AM IST,” instead of presenting an unsupported number.
Build the data ingestion pipeline
A robust pipeline should be idempotent: retrieving the same source twice must not create duplicate market observations. Use a deterministic key based on source, commodity, market, grade, price type, observation time, and source record ID where available.
Recommended stages:
1. Fetch: use timeouts, retries with exponential backoff, and source-specific rate limits.
2. Parse: validate JSON, CSV, HTML, or PDF extraction output.
3. Map: map local names and spelling variants to canonical market and commodity IDs.
4. Validate: check numeric ranges, units, timestamps, and required fields.
5. Normalize: convert units and timestamps, preserving originals.
6. Deduplicate: merge exact duplicates while retaining source evidence.
7. Publish: expose only records that pass quality checks.
For Indian data, handle IST correctly. Store timestamps in UTC internally and render them in Asia/Kolkata for users. Also account for Sundays, public holidays, auction schedules, and market-specific closures; a missing observation is not automatically a zero or a price drop.
Quality controls that prevent dangerous answers
Price-monitoring agents need stronger controls than ordinary search assistants.
- Reject negative prices and implausible values.
- Require a valid currency and unit.
- Detect sudden unit changes from a source.
- Mark stale records after a configurable TTL.
- Separate indicative, retail, wholesale, and auction prices.
- Preserve commodity aliases but do not merge distinct products automatically.
- Require two-source confirmation for high-impact alerts when feasible.
- Return “insufficient data” when a comparison lacks compatible records.
- Log every tool request, source response, transformation, and final result.
Use a confidence score based on freshness, source authority, completeness, and cross-source agreement. A confidence label is not a substitute for evidence, but it helps agents communicate uncertainty.
Security and governance for a WebMCP
Treat the WebMCP as an API exposed to automated clients. Apply:
- API keys or OAuth for private tools
- Per-user and per-agent rate limits
- Input validation with allowlisted commodities and markets
- Output-size limits to prevent data exfiltration
- Secret storage outside source code
- TLS for all connections
- Audit logs with sensitive values redacted
- Separate read-only price tools from write actions such as alerts
If you collect phone numbers, email addresses, buyer preferences, or trading activity, define retention and deletion policies. For Indian operations, review the Digital Personal Data Protection Act, 2023 and obtain appropriate legal advice for consent, notice, purpose limitation, and processor relationships. Also clarify whether your source licences permit storage and redistribution.
Testing with realistic agent scenarios
Test both the protocol and the agent’s interpretation. Include prompts such as:
- “What is today’s black pepper price in Idukki?”
- “Compare cardamom prices across two Kerala markets for the last seven days.”
- “Alert me if dry ginger rises by 5%.”
- “Show the cheapest mandi for turmeric.”
- “Is today’s price a good time to sell?”
The final request is especially important: the system may provide data and historical context, but it should not present financial or trading advice as certainty. Test ambiguity too: “pepper price” may refer to a different grade, unit, market, or price type.
Measure:
- Tool-call validity rate
- Percentage of answers with citations and timestamps
- Unit-conversion accuracy
- Freshness compliance
- False anomaly rate
- Duplicate-record rate
- Latency and source failure recovery
- Human review agreement
Deployment blueprint
A practical initial stack could include Python or Node.js for connectors and the WebMCP server, PostgreSQL for normalized records, Redis for short-lived caching, and object storage for raw source documents. Schedule ingestion with a job runner, containerize services, and monitor:
- Connector success and failure rates
- Data freshness by market
- Parser error counts
- Tool latency
- Authentication failures
- Alert delivery failures
Cache repeated read queries, but include the cache timestamp in every response. Never cache an alert decision beyond the data freshness policy.
Start with a narrow pilot: one or two commodities, a small set of Kerala markets, one verified source, and read-only tools. Expand only after you can demonstrate correct units, provenance, and stale-data behavior.
Common mistakes to avoid
- Building a generic scraper before defining commodity and grade taxonomy
- Treating all Kerala markets as interchangeable
- Mixing auction prices with mandi modal prices
- Hiding stale data behind the word “latest”
- Letting the language model perform arithmetic without server-side validation
- Returning a single price when multiple grades or sessions exist
- Ignoring source licensing and website access rules
- Adding buy/sell automation before data quality is proven
- Failing silently when a connector breaks
FAQ
What is the best data source for Kerala spice prices?
Use the most authoritative source available for the specific commodity and market, preferably an official feed, auction operator, government portal, or licensed provider. Cross-check coverage, update frequency, definitions, and redistribution rights before relying on it.
Can an AI agent scrape mandi websites directly?
It can technically browse pages, but a governed WebMCP is safer. The server can enforce permissions, normalize units, preserve provenance, and prevent the agent from treating unverified page text as a reliable price.
Should prices be stored in ₹/kg or ₹/quintal?
Store the original unit and a normalized ₹/kg value when conversion is valid. Display the source unit alongside the normalized value so traders can audit the result.
How frequently should the system update?
Match the schedule to market activity. Daily ingestion may be sufficient for end-of-day analysis, while active auction monitoring may require session-level updates. Always expose the exact observation and retrieval timestamps.
Can this WebMCP automatically place orders?
It should begin as a read-only monitoring system. Any ordering, payment, or trading action requires separate authentication, user confirmation, risk controls, contractual review, and a higher standard of data validation.
Apply for AI Grants India
Building a reliable WebMCP for agricultural intelligence, commodity monitoring, or AI-enabled market access? Apply to AI Grants India for support and opportunities designed for Indian AI founders.