divar-mcp
This server provides a read-only MCP interface to divar.ir (Iran's classifieds): search, inspect, price, appraise, watch, and export listings without an account or API key.
Search live listings (
divar_search) with Persian query, city, category, Toman price range, photo-only, district IDs, brand/model, sorting, pagination, and client-side recency/term filters.Read a full post (
divar_get_post) for description, structured attributes, images, Jalali/ISO dates, city/district, and category breadcrumb.Get comparable listings (
divar_similar_posts) for an existing post.Price analysis (
divar_price_analysis) for suggested asking range, median/percentiles, price bands, freshness, and per-district medians.Appraise a listing (
divar_appraise_post) as below/fair/above market, with percentile, confidence, and cheaper alternatives.Find deals (
divar_find_deals) ranking underpriced listings with explainable deal scores.Watch searches (
divar_watch_create,divar_watch_check,divar_watch_list,divar_watch_delete) to track new listings over time.Price trends (
divar_price_trend) via local day-by-day history.Export bulk rows (
divar_export) to CSV or JSONL on disk.Market breakdown (
divar_market_breakdown) for per-district medians and price bands.City/category lookup (
divar_list_cities,divar_list_categories) with fuzzy Persian/English matching.Inspect filter schema (
divar_post_filters) exposed by Divar for a city/category.Build human-openable search URLs (
divar_search_url) with verified city slugs.Self-diagnosis and help (
divar_status,divar_help) plus read-only resources and workflow prompts.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@divar-mcp What's the market price for iPhone 13 in Tehran?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
divar-mcp
An agent-grade MCP server for divar.ir, Iran's largest classifieds marketplace (دیوار). Search live listings, read a post in full, price an item, appraise someone else's listing, hunt underpriced stock, watch a search over time, and export bulk rows, all from any MCP client.
Read-only, no account, no API key, no dependencies. Works from inside Iran and from anywhere else divar.ir's API is reachable.
19 tools | find, read, value, appraise, hunt, watch, export, plus self-diagnosis and a capability map |
5 resources | cities, categories, verified slugs, status, help as readable MCP resources |
4 prompts | price-an-item, appraise-listing, find-deals, watch-market |
structured output | every tool declares an |
self-repairing errors | a wrong city or category comes back with the closest real values and a hint |
conservative by design | read-only, no contact details, polite rate limits, no fabricated links |
یک MCP سرور کامل برای کار با آگهیهای دیوار: جستوجو، خواندن آگهی، قیمتگذاری، ارزیابی آگهی دیگران، پیدا کردن زیرقیمتها، دیدهبانی جستوجو و خروجی CSV. فقط خواندنی، بدون کلید API، بدون وابستگی.
Why this exists
Divar has no public MCP server. The divar-ir/* GitHub org is Divar's own internal code-search tooling, not marketplace access. The official API (Kenar / کنار دیوار) needs an approved app, an API key and OAuth, which is a partner programme, not a read path. Everything else out there is Playwright page-scraping with no MCP surface, no filters and no pagination.
This server talks to the same JSON endpoints divar.ir's own web app uses, and wraps them in the shape an agent actually needs.
Related MCP server: Divar Intelligence MCP
Install
# run straight from git, no install
uvx --from git+https://github.com/shojaee76-cmyk/divar-mcp divar-mcp
# or install it
pip install git+https://github.com/shojaee76-cmyk/divar-mcpRequires Python 3.10+. There are no third-party dependencies.
Connect a client
Claude Desktop / Claude Code (claude_desktop_config.json):
{
"mcpServers": {
"divar": {
"command": "uvx",
"args": ["--from", "git+https://github.com/shojaee76-cmyk/divar-mcp", "divar-mcp"]
}
}
}Cursor / Cline / Windsurf — same shape, command + args.
Hermes Agent (~/.hermes/config.yaml):
mcp_servers:
divar:
command: uvx
args: ["--from", "git+https://github.com/shojaee76-cmyk/divar-mcp", "divar-mcp"]Tools
Find and read
Tool | What it gives an agent |
| Live listings: |
| One listing in full: description, structured attributes (brand/model, year, mileage...), image URLs, Jalali text and ISO 8601 dates, city/district, district id, category breadcrumb. |
| Comparables for an existing listing: same category, brand/model and city, excluding itself. |
| A |
Value and decide
Tool | What it gives an agent |
| Price distribution of live comparables: min, p25, p40, median, p75, max, mean, suggested ask range, price bands, freshness split, and a per-district median table. The "what should I ask?" tool. |
| Judges one listing: |
| Ranks listings below the live market with an explainable |
| Where the stock sits: median price per district (busiest first), price bands, freshness. |
Watch and export
Tool | What it gives an agent |
| Save a named search; today's listings become the quiet baseline. |
| Returns only listings a watch has never reported before. Cron-friendly "anything new?" |
| Manage saved watches. |
| Local day-by-day price history for an exact filter. Every search records a price point, so the series grows with use. Says |
| Walks pages and writes CSV (utf-8-sig, Excel-safe Persian) or JSONL to disk, returning the absolute path. Bulk work stays out of the model's context. |
Meta
Tool | What it gives an agent |
| Is divar.ir reachable right now (latency, or a clear hint when it is not), dataset sizes, store size, cache counters. First call when something looks broken. |
| Capability map: tool index, units, dataset sizes and recipes for the common jobs. No network call. |
| Cities by Persian name, ASCII slug or id; a miss returns the closest names. |
| Category slugs by Persian or English text with breadcrumb parents; a miss returns the closest slugs. |
| Which filter widgets Divar currently exposes for a city/category. |
All prices are Toman (Divar displays Toman; its internal schema.org price is Rial, 10x larger). Dates come back as both the Jalali text and ISO 8601 with +03:30.
Resources and prompts
MCP clients that support them get read-only resources instead of tool calls:
divar://cities city id, Persian name and ASCII slug for every harvested city
divar://categories category slugs with Persian names and parents
divar://cities/slugs the validated city page slug map
divar://status dataset + store + cache stats, no network probe
divar://help the capability mapAnd four prompts that encode the workflows: price-an-item, appraise-listing, find-deals, watch-market.
Built for agents, not just for humans
Every tool declares an
outputSchemaand returnsstructuredContent, so a client can parse results instead of regexing prose.Errors repair themselves. A wrong category returns
suggestionswith the closest real slugs and ahint; a wrong city returns the closest real names. Unknown tools return the list of valid ones. Nothing fails with a bare 400.Inputs are forgiving. Cities accept an id (
1), a Persian name (تهران), or an ASCII slug (tehran), case-insensitively. Categories accept a slug or a Persian name.ROOTis understood as "everything".Every result carries
meta: requests made, cached responses, elapsed seconds, rate-limit and cache settings, so an agent can tell a free call from an expensive one.Annotations on every tool (
readOnlyHint,idempotentHint,openWorldHint) so a client can gate the two tools that write local files or local state.Brief by default. Search returns 10 compact fields per row;
brief: falsereturns everything.
Example agent use
"My iPhone 13 is in good shape. What should I ask in Tehran right now?"
The agent calls divar_list_categories("موبایل") → mobile-phones, then divar_price_analysis(query="آیفون ۱۳", category="mobile-phones", city="تهران", pages=2), and answers with the median, the active band, the district table, and fresh comparables with links.
"Is this listing overpriced? https://divar.ir/v/gaxi5lYL"
divar_appraise_post → verdict, percentile, confidence, cheaper alternatives.
"Find a Peugeot 206 under 700 million in Karaj or Tehran, photo-only, posted this week."
divar_search(query="پژو ۲۰۶", cities=["کرج","تهران"], price_max=700000000, has_photo=true, max_age_hours=168).
"Tell me whenever a cheap 206 shows up."
divar_watch_create(name="206-karaj", query="پژو ۲۰۶", city="کرج"), then divar_watch_check("206-karaj") on a schedule.
CLI (same engine, for humans and cron)
divar search "پژو ۲۰۶" --city tehran --price-max 900000000 --has-photo --sort price_asc
divar price "آیفون ۱۳" --category موبایل --pages 3 # printed as a readable summary
divar deals "پژو ۲۰۶" --category light --min-discount 0.1
divar appraise https://divar.ir/v/gaxi5lYL
divar breakdown "پژو" --city تهران # median price per district
divar trend "آیفون ۱۳" --days 60
divar watch create --name 206 --query "پژو ۲۰۶" --city کرج
divar watch check --name 206
divar export "لپتاپ" --pages 5 --format csv
divar status
divar helpdivar-mcp --list-tools prints the raw tool schemas, --resources and --prompts list those, and divar-mcp --call divar_search --args '{"query":"پژو","city":"1"}' runs one tool without a client.
Performance
Latency to divar.ir is dominated by two things: a TCP+TLS handshake per request, and the polite delay between requests. Both are handled:
Keep-alive sockets. The client holds one HTTP connection per thread, so a multi-request tool pays for the handshake once instead of once per page. Idle sockets that Divar has closed are detected and reconnected transparently.
A shared client. The MCP server is long lived, so the same client (and its sockets and cache) is reused across tool calls instead of rebuilt per call.
A response cache. Identical requests inside
DIVAR_CACHE_TTL(default 180 seconds) are served locally. SetDIVAR_CACHE_TTL=0to disable it entirely.Batched local writes. The SQLite store runs in WAL mode with relaxed fsync and one commit per page of listings instead of one per row.
Every result's meta block reports connections_reused, requests_made and
elapsed_seconds, so the effect is visible from a client:
python tools/bench.py --mode before # fresh client + urllib + no cache
python tools/bench.py --mode transport # keep-alive, cache off
python tools/bench.py --mode warm # keep-alive + cacheMeasured against the real API from an Iranian line (--repeat 3, medians, cache
disabled so only the transport is compared):
Tool | before | keep-alive | speedup | repeat call |
| 1.59s | 1.11s | 1.43x | 0.00s |
| 2.78s | 1.40s | 1.99x | 0.00s |
| 2.46s | 1.72s | 1.43x | 0.00s |
| 3.92s | 2.59s | 1.51x | 0.00s |
| 4.07s | 2.44s | 1.67x | 0.00s |
| 1.23s | 0.75s | 1.64x | 0.00s |
total | 16.05s | 10.01s | 1.60x | 0.00s |
Tools that make several requests gain most (a handshake saved per request); a repeated identical call inside the cache TTL costs nothing. Numbers vary with the line: treat them as a median of the hour they were taken, not a promise.
Tuning knobs, all optional environment variables:
Variable | Default | Meaning |
|
| seconds a response stays cached; |
|
|
|
| unset |
|
|
| minimum seconds between requests (be polite) |
|
| per-request timeout in seconds |
| platform data dir | path to the local SQLite store |
| unset |
|
How it works
The server talks to the same JSON endpoints the divar.ir web app uses (discovered from Divar's own JS bundles and verified against the live API):
Endpoint | Use |
| listing search, filters, cursor pagination |
| filter schema for a city/category |
| single post view |
Things worth knowing if you fork this:
Filters are protobuf-
Anyencoded.categoryis{"str": {"value": "<slug>"}},priceis{"number_range": {"minimum": n, "maximum": n}},districtsis{"repeated_string": {"value": ["208"]}}(numeric district ids),has-photois{"boolean": {}}(presence = true),brand_modelis a repeating string.pageis ignored by the API. Real pagination is a cursor: echo backpagination.data(last_post_date,pelle_max_score,filters_hash,cumulative_widgets_count,page,layer_page) withpage/layer_pageincremented. This server does that for you (pages=3).Divar's own recency filter (
recent_ads) does not filter. Verified:3hand7dreturn identical result sets, so recency filtering is done client-side from the parsed Persian relative time (max_age_hours).District filtering needs numeric ids, which only appear inside a post's TAGS payload.
divar_get_postexposes it asdistrict_id.Jalali dates are converted (
۳۱ شهریور ۱۴۰۵→2026-09-22T00:06:00+03:30) so an agent can reason about age without a Hijri library.Category slugs come from Divar's own SEO breadcrumbs (
mobile-phones→mobile-tablet→electronic-devices), so the vocabulary and Persian names are real, not guessed.Web links need a real slug. A Persian city name in the path is wrong, and divar.ir answers with the same SPA shell for any slug, so a slug is published only when it came from Divar's payload and its
city_idmatched the query.tools/harvest_city_slugs.pygrows that verified map.Divar's own SEO headline is off by one ("صفحه ۲" on the first page). Harmless, but do not read it as a page number.
Local state (listing observations, price history, watches) lives in SQLite outside the package: %LOCALAPPDATA%\divar-mcp\store.db on Windows, ~/.divar-mcp/store.db elsewhere, overridable with DIVAR_STORE. Set DIVAR_STORE_DISABLE=1 for a fully stateless run.
One-click launcher
launchers/DIVAR search.bat (double-click, or the Desktop shortcut) asks for a phrase, a city and an optional budget, prints live listings with prices, and offers to open the matching divar.ir page in Chrome.
Politeness and legality
Read-only for Divar. This server never creates, edits, deletes, reports or messages anything there. The only writes are local files (
divar_export, the SQLite store, watch definitions).No phone numbers or contact data. Divar does not expose seller contact details to logged-out clients and this server never tries to obtain them (no auth bypass, no
GetContactWeb, no PII harvesting).Rate limited. Default one request per 0.8s with an LRU response cache, well under Divar's ~30 requests/minute throttle. Tune with
DIVAR_MIN_INTERVAL,DIVAR_TIMEOUT,DIVAR_CACHE_TTL.Unofficial. Not affiliated with or endorsed by Divar (Hezardastan / Cafe Bazaar). It reads public listings the way a browser does. Respect Divar's terms and local law; if you need write access or official data, use Kenar.
Development
git clone https://github.com/shojaee76-cmyk/divar-mcp && cd divar-mcp
uv venv && uv pip install -e ".[dev]"
pytest # offline: parsers, store, analytics, MCP protocol, SDK interop
DIVAR_LIVE=1 pytest tests/test_live.py -v # hits the real API (needs an Iran-reachable line)
python tools/smoke.py # CLI -> MCP end to end, no network
python tools/verify_publish.py # repo blobs vs this working treeThe offline suite runs entirely on captured fixtures (tests/fixtures/*.json, real payloads from a live search and two live post views) plus temp-file stores, so parsers, analytics and watch logic are all tested without a network. The protocol suite boots the real server process and, when the official mcp SDK is installed, drives it with mcp.client.stdio to prove interop.
tools/ holds the reverse-engineering and harvesting scripts (probe*.py, harvest_cities.py, harvest_categories.py, harvest_city_slugs.py, build_data.py). Run python tools/build_data.py after re-harvesting to refresh the bundled data.
Roadmap
Optional
kenarbackend for authenticated workflows (your own listings) when the user supplies a keyDistrict-level price history once the store has a few weeks of observations
Saved-search diffing pushed by a scheduler (the watch tools are the storage side of this)
License
MIT. See LICENSE.
Available Tools
8 toolsdivar_get_postA
Full public detail for one divar.ir post: title, description, price in Toman, structured attributes (brand/model, year, mileage, ...), image URLs, Jalali and ISO posted/updated dates, city/district, category breadcrumb and its district id (usable as a divar_search filter).
Inputs: token (required).
divar_list_categoriesA
Look up divar.ir category slugs by Persian or English text, with their breadcrumb parents. Use the slug in divar_search/divar_price_analysis.
Inputs: query.
divar_list_citiesA
Look up divar.ir city ids by Persian name (or list them all).
Inputs: query.
divar_post_filtersB
Show which filters divar.ir exposes for a city/category (price range, districts, photo-only).
Inputs: city, category.
divar_price_analysisA
Price distribution of comparable live listings for an item, to decide what to ask before posting an ad (median, p25/p75, suggested ask range, price bands, freshness, cheapest and priciest samples). Prices in Toman.
Inputs: city, pages, query, category, +2 more.
divar_searchA
Search live divar.ir listings (Iran's largest classifieds). Read-only, no account needed. Supports text query, city, category, Toman price range, photo-only, district ids and brand/model, with cursor pagination. Returns normalized rows (token, title, price in Toman, city, district, relative time, image, url).
Inputs: city, sort, limit, pages, +9 more.
divar_search_urlA
Build a divar.ir web URL for a search, so a human can open it in a browser.
Inputs: city, query, category, price_max, +1 more.
divar_similar_postsA
Comparable listings for an existing post: same category, brand/model and city, excluding the post itself. Useful for a seller checking competition or a buyer checking the price.
Inputs: token (required), city, limit.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 8 tools
Each tool targets a distinct concern: searching, fetching details, analyzing prices, finding similar posts, and listing metadata (cities, categories, filters). Even the two analysis tools (price_analysis vs similar_posts) are clearly differentiated by their purpose—one focuses on price distribution, the other on comparable listings. No real ambiguity exists.
All tools share the 'divar_' prefix, which provides a clear namespace. The pattern is mostly verb_noun (search, get_post, list_cities) but some are noun phrases (price_analysis, similar_posts, post_filters). The style is consistent (snake_case) and readable, though not perfectly uniform in verb usage.
Eight tools is ideal for a read-only classifieds analysis server. Each tool serves a distinct role in the workflow—discovering, inspecting, analyzing, and building URLs—without unnecessary overlap or bloat. The count is well-scoped for the stated purpose.
The server covers the core read-only lifecycle: search, get detail, price analysis, similar items, and lookups for cities, categories, and filters. It lacks a method to post or manage listings, but that's outside its declared read-only scope. Minor gaps like district-level listing or user info are non-essential for the intended use case.
Related MCP Connectors
Car-listing search and used-car market analysis as agent tools.
Search and browse global classifieds across 80 markets. No auth required for read-only access.
Scrape, crawl and search the web for AI agents via MCP.
AI-agent-first offers directory: search and publish listings via MCP.
Related MCP Servers
- AlicenseAqualityBmaintenanceEnables AI agents to search and read Divar classified ads across Iranian cities, covering homes, cars, phones and more, with price statistics, deal finding, fair-price appraisal, ad comparison and map browsing. It is read-only, needs no account or API key, and returns compact JSON with prices in Toman.31471 PyPI1PolyForm Noncommercial 1.0.0
- AlicenseCqualityCmaintenanceEnables Persian-language search, comparison, price assessment, market snapshots/history, and monitoring of property, vehicle, and goods listings with evidence, freshness, and coverage limitations. It also supports official Kenar API integration, local/offline fixture modes, MCP resources and prompts, and watch notifications.31MIT
- AlicenseAqualityBmaintenanceEnables AI agents to read public Iranian car-marketplace data, including filtered used-car ads, full ad details, new-car prices and history, spec comparisons, and magazine articles, without an API key.15142 PyPI2PolyForm Noncommercial 1.0.0
- AlicenseAqualityBmaintenanceThis server enables AI agents to search, analyze, and retrieve detailed information from classified advertisements across Iran. It facilitates comprehensive market research by summarizing asking prices and providing metadata for various categories and filters.11287 PyPI2PolyForm Noncommercial 1.0.0