bharatlas-mcp 1.1.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -36,7 +36,7 @@ Add to your MCP client config:
36
36
  |------|-------------|
37
37
  | **list_layers** | Discover layers by category, level, source, or text search |
38
38
  | **get_layer_schema** | Column names, types, distinct values. Call before querying. |
39
- | **query_layer** | Filter, select, group_by on any column. Runtime parquet reads. |
39
+ | **query_layer** | Select any column; filter (exact, case-insensitive) and group_by on flat columns, with per-group sums of numeric columns. Runtime parquet reads. |
40
40
  | **locate** | Point-in-polygon: what state, district, ward, zone is this point in? |
41
41
  | **nearby** | Find features within a radius. Works for points, polygons, and lines. |
42
42
  | **get_layer_detail** | Download URLs in 5 formats (parquet, pmtiles, geojson, kml, shapefile) |
@@ -68,7 +68,7 @@ Thin wrapper over the [bharatlas REST API](https://bharatlas.com/docs). Each too
68
68
  The server sends instructions to the LLM at connection time that teach:
69
69
  - **Schema-first pattern**: check column names and sample values before querying (column names vary: `state` vs `State_LGD` vs `stname`)
70
70
  - **Source preference**: LGD for admin boundaries, with SOI/Bhuvan/geoBoundaries as alternates
71
- - **Concept-to-layer mapping**: "water bodies" = rivers + canals + reservoirs + wetlands + ramsar sites + dams; "groundwater" = aquifers + extraction stage
71
+ - **Concept-to-layer mapping**: "water bodies" = rivers + canals + reservoirs + wetlands + ramsar sites + dams; "groundwater" = aquifers + extraction stage + wells (minor irrigation census); "places/shops/ATMs" = Overture places
72
72
  - **Spatial join workflow**: locate for context, query for data, nearby for proximity
73
73
 
74
74
  ## Links
package/index.js CHANGED
@@ -27,15 +27,18 @@ Workflow patterns:
27
27
 
28
28
  - **Discovery**: start with list_layers or list_categories to find relevant layers. Use the q parameter for text search.
29
29
  - **Schema first**: always call get_layer_schema BEFORE query_layer. Column names vary per layer (e.g. "state" vs "State_LGD" vs "stname"). The schema shows exact names and sample values.
30
- - **Filtering**: query_layer where conditions are case-insensitive. Pass column=value pairs. Check the schema for the right column name and value format.
31
- - **Counting**: use group_by to count features by any column. Example: group_by "type" on wildlife layer returns counts per category.
32
- - **Location queries**: locate returns all admin boundaries + zones at a lat/lng. Use it to answer "what state/district/ward is this point in?"
30
+ - **Filtering**: query_layer where is an exact, case-insensitive match (no partial or substring match). Pass column=value pairs; check the schema for the right column name and value format. Columns the schema marks as type "nested" (structs, lists, maps, e.g. Overture names/addresses) can be selected but not used in where or group_by (the API returns 400 listing the flat columns).
31
+ - **Counting**: use group_by to count features by any column. Example: group_by "category" on the gs_wildlife layer returns national parks vs sanctuaries.
32
+ - **Totals**: add sum (numeric columns) to group_by to total values per group, e.g. group_by "district" + sum ["area_ha"] rolls block-level areas up to districts. Percentages are not additive: sum the underlying amounts and recompute shares.
33
+ - **Location queries**: locate returns all admin boundaries + zones at a lat/lng, and (for the ~30 covered cities) auto-includes the municipal ward layer that contains the point — so "what ward is this?" just works with lat/lng alone. Use it to answer "what state/district/ward is this point in?"
33
34
  - **Spatial joins** (multi-step): to answer "which X are in Y?" when layers don't share a common column:
34
35
  1. Use locate to find the admin context (state, district) of the target area
35
36
  2. Use query_layer with a where filter to narrow the other layer by that admin context
36
37
  3. For precise spatial containment, test individual points via locate against the target layer
37
38
  - **Community layers**: list_submissions returns user-contributed datasets. These work with query_layer and get_layer_schema exactly like curated layers.
38
- - **Downloads**: get_layer_detail returns direct URLs for parquet, pmtiles, geojson, kml, and shapefile formats.
39
+ - **Downloads**: get_layer_detail returns direct URLs for the formats a layer has (parquet and pmtiles always; geojson, kml and shapefile for most).
40
+ - **Large layers**: overture_places_india has 4.4M places. Always narrow it: where on basic_category (e.g. "hospital", "restaurant") or name, group_by, or nearby for places around a point. Whole-table filters and group_by take several seconds; nearby is the fast path for "near me".
41
+ - **Honor the terms**: every layer and community submission carries its own source and open licence. When you use, quote, or publish results from a layer, credit its source and respect that licence; get_layer_detail returns the attribution and licence, and each /view page's Dataset JSON-LD carries a creditText to reproduce.
39
42
 
40
43
  Source preference (multiple layers often cover the same level):
41
44
  - **Admin boundaries** (state, district, subdistrict, block, village): prefer LGD (lgd_*) as the authoritative source. SOI, Bhuvan, and geoBoundaries are cross-reference alternates with slightly different counts/boundaries. Mention alternates if the user asks about discrepancies.
@@ -54,14 +57,17 @@ Cross-layer queries (combining data from different layers):
54
57
  - Use locate as the bridge: find what's at a point across ALL relevant layers in one call by passing multiple layer IDs.
55
58
  - **Map user concepts to multiple layers.** Users say "water bodies" not "wris_rivers." Translate:
56
59
  - "water bodies/water" → wris_rivers, wris_reservoirs, bp_wetlands, bp_ramsar, wris_basin, wris_subbasin, wris_canals
57
- - "groundwater/aquifer/water table" → cgwb_aquifers, cgwb_gw_extraction
60
+ - "groundwater/aquifer/water table" → cgwb_aquifers, cgwb_gw_extraction, mi6_wells_districts
61
+ - "wells/borewells/tubewells/irrigation pumps" → mi6_wells_districts (census counts per district, 2017-18)
58
62
  - "forests/green cover/ecology" → soi_forests, gs_wildlife, bm_eco_zones, biogeographic_zones
59
- - "agriculture/farming/cropping zones" → agro_ecological_zones, agro_climatic_zones
63
+ - "agriculture/farming/cropping zones" → agro_ecological_zones, agro_climatic_zones, corestack_lulc_blocks (land use and cropping intensity by block, modelled)
64
+ - "places/POIs/shops/restaurants/ATMs/schools/hospitals by name" → overture_places_india (filter on name or basic_category; 4.4M rows, always add a where or group_by, or use nearby)
60
65
  - "hazards/risks" → seismic_zones, india_flood_inventory
61
66
  - "health/medical" → nic_health
62
67
  - "boundaries/admin" → lgd_states, lgd_districts, lgd_subdistricts, lgd_blocks, lgd_villages
63
68
  - "roads/transport" → gs_highways, airports
64
69
  When unsure, use list_layers with a broad q search and list_categories to discover what's available. Combine ALL relevant layers, not just the first match.
70
+ - **Sky and air over a place**: once you have a coordinate (from locate, nearby or a layer row), the mugilu MCP (mugilu.live/mcp, tool conditions_at) gives the live air quality, heat, fog and warnings there. bharatlas answers where; mugilu answers what the sky is doing.
65
71
 
66
72
  Column naming conventions (vary by source):
67
73
  - State: State_LGD (number), STNAME, stname, state, state_name
@@ -75,7 +81,7 @@ Collect (author your own map): this server also drives collect.bharatlas.com, th
75
81
  - view link -> get_map, get_records: read / query / export that map's published points (analyse or back up what has been collected).
76
82
  - collect link -> the above; field capture itself is done in the browser on a phone via the collect link.
77
83
  - admin link -> everything: edit_map (settings), moderate_record (approve/reject), import_points (bulk data you already hold, with a source + rights), and publish.
78
- - publish bakes approved points into a bharatlas catalog submission. It is then queryable through the read tools above (list_submissions, query_layer, locate) — the full loop, gather -> moderate -> publish -> query, in one server.
84
+ - publish submits a collect map's approved points to the bharatlas catalog FOR REVIEW — nothing is auto-approved. A bharatlas maintainer approves the submission before it goes live; the response's status is "pending" until then. Once approved it is queryable through the read tools above (list_submissions, query_layer, locate).
79
85
  - No accounts: the link is the credential. A tool that needs more than your link allows will say which link you need. create_map is optional and needs COLLECT_API_KEY (request-only); prefer creating online.`;
80
86
 
81
87
  const TOOLS = [
@@ -131,7 +137,8 @@ const TOOLS = [
131
137
  name: "query_layer",
132
138
  description:
133
139
  "Query a layer's data with filters and grouping. Reads the parquet file at runtime. " +
134
- "Supports: select specific columns, filter by column values, group by a column to get counts. " +
140
+ "Supports: select specific columns, filter by column values, group by a column to get counts, " +
141
+ "and sum numeric columns per group (e.g. roll block areas up to district totals). " +
135
142
  "Use get_layer_schema first to discover column names. " +
136
143
  "Examples: 'airports in Karnataka' -> where: {state: 'KA'}, " +
137
144
  "'forest types' -> group_by: 'type', " +
@@ -151,12 +158,17 @@ const TOOLS = [
151
158
  where: {
152
159
  type: "object",
153
160
  additionalProperties: { type: "string" },
154
- description: "Filter conditions as {column: value} pairs. Case-insensitive matching.",
161
+ description: "Filter conditions as {column: value} pairs. Exact, case-insensitive match on flat columns (not partial). Values may contain commas.",
155
162
  },
156
163
  group_by: {
157
164
  type: "string",
158
165
  description: "Column to group by. Returns {value: count} instead of rows.",
159
166
  },
167
+ sum: {
168
+ type: "array",
169
+ items: { type: "string" },
170
+ description: "Numeric columns to total per group (requires group_by). Adds {sums: {group: {col: total}}}. Use this to roll finer units up, e.g. block-level areas to district totals. Shares/percentages are not additive: sum the area columns and recompute shares.",
171
+ },
160
172
  limit: { type: "number", description: "Max rows (default 100, max 1000)" },
161
173
  include_centroid: {
162
174
  type: "boolean",
@@ -171,7 +183,8 @@ const TOOLS = [
171
183
  description:
172
184
  "Given a latitude/longitude, find which administrative boundaries, zones, and regions " +
173
185
  "contain that point. Returns state, district, subdistrict, block, parliament/assembly " +
174
- "constituency, pincode, seismic zone, high court jurisdiction, and more. " +
186
+ "constituency, pincode, seismic zone, high court jurisdiction, the municipal ward (for " +
187
+ "the ~30 cities with ward data), and more. " +
175
188
  "The 'where am I?' tool. Also accepts specific layer IDs to check.",
176
189
  inputSchema: {
177
190
  type: "object",
@@ -187,7 +200,7 @@ const TOOLS = [
187
200
  layers: {
188
201
  type: "array",
189
202
  items: { type: "string" },
190
- description: "Specific layer IDs to check (default: 12 essential layers covering all admin levels + zones)",
203
+ description: "Specific layer IDs to check. Omit to use the default: 12 essential admin/zone layers PLUS the city ward layer(s) covering the point (for the ~30 cities with ward data). Passing this replaces the default entirely (no ward auto-include).",
191
204
  },
192
205
  },
193
206
  required: ["lat", "lng"],
@@ -196,9 +209,9 @@ const TOOLS = [
196
209
  {
197
210
  name: "nearby",
198
211
  description:
199
- "Find features from a layer that are near a given point. Samples a grid of points around the " +
200
- "center and checks which hit the target layer via locate. Generic: works for any layer type " +
201
- "(polygons, points, lines) without needing coordinate columns. " +
212
+ "Find features from a layer that are near a given point, nearest first, within radius_km. " +
213
+ "Reads the layer's parquet bounding boxes and ranks features by distance to their centres; " +
214
+ "works for points, polygons and lines. Returns the true count within the radius plus the nearest `limit`. " +
202
215
  "Example: 'reservoirs near Bengaluru' -> layer_id: 'wris_reservoirs', lat: 12.97, lng: 77.59, radius_km: 50.",
203
216
  inputSchema: {
204
217
  type: "object",
@@ -342,8 +355,9 @@ const TOOLS = [
342
355
  {
343
356
  name: "publish",
344
357
  description:
345
- "Bake a collect map's approved points into a bharatlas catalog submission (needs the admin link). " +
346
- "Once published it is queryable via list_submissions / query_layer / locate above.",
358
+ "Submit a collect map's approved points to the bharatlas catalog for review (needs the admin link). " +
359
+ "Nothing goes live automatically — a maintainer approves the submission first; the response status is 'pending' until then. " +
360
+ "Once approved it is queryable via list_submissions / query_layer / locate above.",
347
361
  inputSchema: { type: "object", properties: { id: { type: "string" } }, required: ["id"] },
348
362
  },
349
363
  {
@@ -388,6 +402,10 @@ function httpGet(url) {
388
402
  });
389
403
  }
390
404
 
405
+ // Mirrors RESERVED in web/functions/lib/query-params.ts: these names are query
406
+ // options, so a where column with one of them must go inside where=.
407
+ const QUERY_RESERVED = new Set(["select", "group_by", "sum", "limit", "where", "order_by", "include_centroid"]);
408
+
391
409
  async function callApi(path, params = {}) {
392
410
  const url = new URL(API + path);
393
411
  for (const [k, v] of Object.entries(params)) {
@@ -481,13 +499,22 @@ async function handleTool(name, args) {
481
499
  }
482
500
 
483
501
  case "query_layer": {
484
- const { layer_id, select, where, group_by, limit, include_centroid } = args;
502
+ const { layer_id, select, where, group_by, sum, limit, include_centroid } = args;
485
503
  const params = {};
486
504
  if (select?.length) params.select = select.join(",");
487
505
  if (group_by) params.group_by = group_by;
506
+ if (sum?.length) params.sum = sum.join(",");
488
507
  if (limit) params.limit = limit;
489
- if (include_centroid) params.include_centroid = "true";
490
- if (where) params.where = Object.entries(where).map(([k, v]) => `${k}=${v}`).join(",");
508
+ if (include_centroid !== undefined) params.include_centroid = String(include_centroid);
509
+ // Each filter as its own ?col=val param so values may contain commas (the
510
+ // API splits a where= string on commas). Columns named like a reserved
511
+ // param must still travel inside where=.
512
+ const reservedWhere = [];
513
+ for (const [k, v] of Object.entries(where || {})) {
514
+ if (QUERY_RESERVED.has(k)) reservedWhere.push(`${k}=${v}`);
515
+ else params[k] = v;
516
+ }
517
+ if (reservedWhere.length) params.where = reservedWhere.join(",");
491
518
  return callApi(`/layers/${layer_id}/query`, params);
492
519
  }
493
520
 
@@ -597,7 +624,7 @@ async function handleTool(name, args) {
597
624
  }
598
625
 
599
626
  const server = new Server(
600
- { name: "bharatlas-mcp", version: "1.1.1" },
627
+ { name: "bharatlas-mcp", version: "1.3.0" },
601
628
  { capabilities: { tools: {} }, instructions: SERVER_INSTRUCTIONS },
602
629
  );
603
630
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bharatlas-mcp",
3
- "version": "1.1.1",
3
+ "version": "1.3.0",
4
4
  "description": "MCP server for India's open geo data. Query layers, locate points, find nearby features, filter and group data. Also authors collect maps: register a share link, moderate contributions, and publish to the catalog.",
5
5
  "keywords": ["mcp", "india", "geo", "geospatial", "gis", "boundaries", "parquet", "pmtiles", "llm", "claude", "bharatlas", "collect"],
6
6
  "repository": { "type": "git", "url": "git+https://github.com/urbanmorph/geodata.git", "directory": "mcp" },
package/server.json CHANGED
@@ -2,12 +2,12 @@
2
2
  "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
3
  "name": "io.github.sathya-sankaran/bharatlas-mcp",
4
4
  "description": "Query India's open geo data, and author collect maps: register a link, moderate, publish.",
5
- "version": "1.1.1",
5
+ "version": "1.3.0",
6
6
  "packages": [
7
7
  {
8
8
  "registryType": "npm",
9
9
  "identifier": "bharatlas-mcp",
10
- "version": "1.1.1",
10
+ "version": "1.3.0",
11
11
  "transport": { "type": "stdio" }
12
12
  }
13
13
  ]