bharatlas-mcp 1.0.0 → 1.0.3
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/LICENSE +26 -0
- package/README.md +84 -0
- package/index.js +8 -6
- package/package.json +6 -2
- package/server.json +3 -2
- package/test.js +0 -330
package/LICENSE
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Urban Morph and contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
Note: this licence covers the code in this repository only. Each data layer
|
|
24
|
+
in the catalog carries its own open licence (CC0-1.0, CC-BY-4.0, CC-BY-SA-4.0,
|
|
25
|
+
ODbL-1.0, ODC-PDDL-1.0, GODL-India). See the per-card line on the catalog at
|
|
26
|
+
https://bharatlas.com/ for the licence applicable to a given layer.
|
package/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# bharatlas-mcp
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/bharatlas-mcp)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
|
|
6
|
+
Ask questions about India's geo data in natural language. This MCP server connects any LLM to bharatlas: open-licensed layers covering admin boundaries (state to village), city wards, forests, wildlife sanctuaries, rivers, canals, reservoirs, dams, groundwater (aquifers, extraction), eco-sensitive zones, agro-climatic and biogeographic zones, seismic zones, flood history, highways, airports, health facilities, pincodes, electoral constituencies, and community submissions.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
Add to your MCP client config:
|
|
11
|
+
|
|
12
|
+
```json
|
|
13
|
+
{
|
|
14
|
+
"mcpServers": {
|
|
15
|
+
"bharatlas": {
|
|
16
|
+
"command": "npx",
|
|
17
|
+
"args": ["-y", "bharatlas-mcp"]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Where to put it:**
|
|
24
|
+
|
|
25
|
+
| Client | Config file |
|
|
26
|
+
|--------|------------|
|
|
27
|
+
| Claude Code | `.mcp.json` (project root) or `~/.claude.json` |
|
|
28
|
+
| Claude Desktop | `~/Library/Application Support/Claude/claude_desktop_config.json` |
|
|
29
|
+
| Cursor | `~/.cursor/mcp.json` |
|
|
30
|
+
| Windsurf | `~/.codeium/windsurf/mcp_config.json` |
|
|
31
|
+
| VS Code | `.vscode/mcp.json` |
|
|
32
|
+
|
|
33
|
+
## Tools
|
|
34
|
+
|
|
35
|
+
| Tool | What it does |
|
|
36
|
+
|------|-------------|
|
|
37
|
+
| **list_layers** | Discover layers by category, level, source, or text search |
|
|
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. |
|
|
40
|
+
| **locate** | Point-in-polygon: what state, district, ward, zone is this point in? |
|
|
41
|
+
| **nearby** | Find features within a radius. Works for points, polygons, and lines. |
|
|
42
|
+
| **get_layer_detail** | Download URLs in 5 formats (parquet, pmtiles, geojson, kml, shapefile) |
|
|
43
|
+
| **list_categories** | Browse categories with layer counts |
|
|
44
|
+
| **list_submissions** | Community-contributed layers under open licenses |
|
|
45
|
+
|
|
46
|
+
## What you can ask
|
|
47
|
+
|
|
48
|
+
**Counting and filtering**
|
|
49
|
+
- "How many national parks vs wildlife sanctuaries?" (101 vs 560)
|
|
50
|
+
- "How many villages in Bengaluru Urban district?" (949)
|
|
51
|
+
- "How many health facilities in Bihar?" (8,363: 3,232 sub-centres, 591 PHCs, 74 CHCs)
|
|
52
|
+
- "How many wards does Chennai have vs Pune?" (200 vs 58)
|
|
53
|
+
|
|
54
|
+
**Spatial**
|
|
55
|
+
- "What state, district, seismic zone is Bengaluru in?" (Karnataka, Bengaluru Urban, Zone II)
|
|
56
|
+
- "Reservoirs within 50km of Bengaluru?" (12 found)
|
|
57
|
+
- "Wildlife sanctuaries near Mysuru?" (Ranganathittu 15km, Nagarahole NP 60km)
|
|
58
|
+
|
|
59
|
+
**Cross-layer**
|
|
60
|
+
- "Which airports in Karnataka are near water bodies?" (Hubballi: Unkal Lake 2.3km, 14 rivers)
|
|
61
|
+
- "Which blocks are in district 571?" (10 blocks: Kunigal, Tumakuru, Gubbi...)
|
|
62
|
+
- "Which villages in Madhya Pradesh are in eco-sensitive zones?" (narrows by district, then locates)
|
|
63
|
+
|
|
64
|
+
## How it works
|
|
65
|
+
|
|
66
|
+
Thin wrapper over the [bharatlas REST API](https://bharatlas.com/docs). Each tool call becomes one or more API requests to Cloudflare Workers that read parquet files and PMTiles directly from R2 at runtime. No pre-computation, no API key, no auth.
|
|
67
|
+
|
|
68
|
+
The server sends instructions to the LLM at connection time that teach:
|
|
69
|
+
- **Schema-first pattern**: check column names and sample values before querying (column names vary: `state` vs `State_LGD` vs `stname`)
|
|
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
|
|
72
|
+
- **Spatial join workflow**: locate for context, query for data, nearby for proximity
|
|
73
|
+
|
|
74
|
+
## Links
|
|
75
|
+
|
|
76
|
+
- [bharatlas.com](https://bharatlas.com) -- the atlas
|
|
77
|
+
- [REST API docs](https://bharatlas.com/docs)
|
|
78
|
+
- [MCP setup guide](https://bharatlas.com/mcp) -- install + example questions
|
|
79
|
+
- [GitHub](https://github.com/urbanmorph/geodata) -- source code
|
|
80
|
+
- [npm](https://www.npmjs.com/package/bharatlas-mcp) -- this package
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
MIT. Data: each layer carries its own open license (CC0, CC-BY, ODbL, GODL-India).
|
package/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import https from "node:https";
|
|
|
10
10
|
|
|
11
11
|
const API = process.env.BHARATLAS_API || "https://bharatlas.com/api/v1";
|
|
12
12
|
|
|
13
|
-
const SERVER_INSTRUCTIONS = `bharatlas MCP server. India's open geo data:
|
|
13
|
+
const SERVER_INSTRUCTIONS = `bharatlas MCP server. India's open geo data: curated layers (state to village boundaries, city wards, forests, hospitals, highways, rivers, canals, groundwater, agro-climatic zones, floods, seismic zones) plus community submissions.
|
|
14
14
|
|
|
15
15
|
Workflow patterns:
|
|
16
16
|
|
|
@@ -42,8 +42,10 @@ Cross-layer queries (combining data from different layers):
|
|
|
42
42
|
- Never assume one layer is enough. Think about what layers need to be combined to answer the question fully.
|
|
43
43
|
- Use locate as the bridge: find what's at a point across ALL relevant layers in one call by passing multiple layer IDs.
|
|
44
44
|
- **Map user concepts to multiple layers.** Users say "water bodies" not "wris_rivers." Translate:
|
|
45
|
-
- "water bodies/water" → wris_rivers, wris_reservoirs, bp_wetlands, bp_ramsar, wris_basin, wris_subbasin
|
|
46
|
-
- "
|
|
45
|
+
- "water bodies/water" → wris_rivers, wris_reservoirs, bp_wetlands, bp_ramsar, wris_basin, wris_subbasin, wris_canals
|
|
46
|
+
- "groundwater/aquifer/water table" → cgwb_aquifers, cgwb_gw_extraction
|
|
47
|
+
- "forests/green cover/ecology" → soi_forests, gs_wildlife, bm_eco_zones, biogeographic_zones
|
|
48
|
+
- "agriculture/farming/cropping zones" → agro_ecological_zones, agro_climatic_zones
|
|
47
49
|
- "hazards/risks" → seismic_zones, india_flood_inventory
|
|
48
50
|
- "health/medical" → nic_health
|
|
49
51
|
- "boundaries/admin" → lgd_states, lgd_districts, lgd_subdistricts, lgd_blocks, lgd_villages
|
|
@@ -62,14 +64,14 @@ const TOOLS = [
|
|
|
62
64
|
description:
|
|
63
65
|
"List available geo layers. Use to discover what data bharatlas has. " +
|
|
64
66
|
"Returns layer IDs, names, row counts, categories, and download formats. " +
|
|
65
|
-
"Filter by category (boundaries, city-wards, environment, transport, etc.), " +
|
|
67
|
+
"Filter by category (boundaries, city-wards, environment, water, agriculture, transport, etc.), " +
|
|
66
68
|
"admin level (state, district, block, village, etc.), source, or text search.",
|
|
67
69
|
inputSchema: {
|
|
68
70
|
type: "object",
|
|
69
71
|
properties: {
|
|
70
72
|
category: {
|
|
71
73
|
type: "string",
|
|
72
|
-
description: "Filter by category: boundaries, city-wards, people, environment, transport, infrastructure, health-edu",
|
|
74
|
+
description: "Filter by category: boundaries, city-wards, people, environment, water, agriculture, transport, infrastructure, health-edu",
|
|
73
75
|
},
|
|
74
76
|
level: {
|
|
75
77
|
type: "string",
|
|
@@ -138,7 +140,7 @@ const TOOLS = [
|
|
|
138
140
|
limit: { type: "number", description: "Max rows (default 100, max 1000)" },
|
|
139
141
|
include_centroid: {
|
|
140
142
|
type: "boolean",
|
|
141
|
-
description: "Include _lat/_lng centroid coordinates
|
|
143
|
+
description: "Include _lat/_lng centroid coordinates (defaults to true). Set false to exclude.",
|
|
142
144
|
},
|
|
143
145
|
},
|
|
144
146
|
required: ["layer_id"],
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bharatlas-mcp",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "MCP server for India's open geo data. Query
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "MCP server for India's open geo data. Query layers, locate points, find nearby features, filter and group data.",
|
|
5
|
+
"keywords": ["mcp", "india", "geo", "geospatial", "gis", "boundaries", "parquet", "pmtiles", "llm", "claude", "bharatlas"],
|
|
6
|
+
"repository": { "type": "git", "url": "https://github.com/urbanmorph/geodata", "directory": "mcp" },
|
|
7
|
+
"homepage": "https://bharatlas.com/mcp",
|
|
8
|
+
"mcpName": "io.github.urbanmorph/bharatlas-mcp",
|
|
5
9
|
"type": "module",
|
|
6
10
|
"main": "index.js",
|
|
7
11
|
"bin": {
|
package/server.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
3
|
"name": "io.github.urbanmorph/bharatlas-mcp",
|
|
4
|
-
"description": "Query India's open geo data
|
|
5
|
-
"version": "1.0.
|
|
4
|
+
"description": "Query India's open geo data. Locate, filter, nearby search across layers.",
|
|
5
|
+
"version": "1.0.3",
|
|
6
6
|
"packages": [
|
|
7
7
|
{
|
|
8
8
|
"registryType": "npm",
|
|
9
9
|
"identifier": "bharatlas-mcp",
|
|
10
|
+
"version": "1.0.3",
|
|
10
11
|
"transport": { "type": "stdio" }
|
|
11
12
|
}
|
|
12
13
|
]
|
package/test.js
DELETED
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Functional tests for bharatlas MCP server.
|
|
5
|
-
* Each test is a real question a user would ask.
|
|
6
|
-
* Spawns the server, sends tool calls, validates answers.
|
|
7
|
-
*
|
|
8
|
-
* Run: node test.js
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { spawn } from "node:child_process";
|
|
12
|
-
import { resolve, dirname } from "node:path";
|
|
13
|
-
import { fileURLToPath } from "node:url";
|
|
14
|
-
|
|
15
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
16
|
-
let passed = 0;
|
|
17
|
-
let failed = 0;
|
|
18
|
-
|
|
19
|
-
function assert(condition, msg) {
|
|
20
|
-
if (condition) {
|
|
21
|
-
passed++;
|
|
22
|
-
console.log(` ✓ ${msg}`);
|
|
23
|
-
} else {
|
|
24
|
-
failed++;
|
|
25
|
-
console.log(` ✗ ${msg}`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let nextId = 1;
|
|
30
|
-
async function call(proc, toolName, args = {}) {
|
|
31
|
-
const id = nextId++;
|
|
32
|
-
return new Promise((resolve, reject) => {
|
|
33
|
-
const timer = setTimeout(() => reject(new Error(`timeout on ${toolName}`)), 30000);
|
|
34
|
-
const onData = (chunk) => {
|
|
35
|
-
for (const line of chunk.toString().split("\n").filter(Boolean)) {
|
|
36
|
-
try {
|
|
37
|
-
const d = JSON.parse(line);
|
|
38
|
-
if (d.id === id) {
|
|
39
|
-
clearTimeout(timer);
|
|
40
|
-
proc.stdout.off("data", onData);
|
|
41
|
-
if (d.result?.isError) {
|
|
42
|
-
resolve({ error: JSON.parse(d.result.content[0].text).error });
|
|
43
|
-
} else {
|
|
44
|
-
resolve(JSON.parse(d.result.content[0].text));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
} catch {}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
proc.stdout.on("data", onData);
|
|
51
|
-
proc.stdin.write(
|
|
52
|
-
JSON.stringify({ jsonrpc: "2.0", id, method: "tools/call", params: { name: toolName, arguments: args } }) + "\n",
|
|
53
|
-
);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async function run() {
|
|
58
|
-
const proc = spawn("node", [resolve(__dirname, "index.js")], {
|
|
59
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
60
|
-
});
|
|
61
|
-
proc.stderr.on("data", () => {});
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
// ── Smoke: tool listing ──
|
|
65
|
-
console.log("Smoke: tool listing");
|
|
66
|
-
const listId = nextId++;
|
|
67
|
-
const listResult = await new Promise((res, rej) => {
|
|
68
|
-
const t = setTimeout(() => rej(new Error("timeout")), 10000);
|
|
69
|
-
const onD = (chunk) => {
|
|
70
|
-
for (const line of chunk.toString().split("\n").filter(Boolean)) {
|
|
71
|
-
try { const d = JSON.parse(line); if (d.id === listId) { clearTimeout(t); proc.stdout.off("data", onD); res(d); } } catch {}
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
proc.stdout.on("data", onD);
|
|
75
|
-
proc.stdin.write(JSON.stringify({ jsonrpc: "2.0", id: listId, method: "tools/list" }) + "\n");
|
|
76
|
-
});
|
|
77
|
-
const tools = listResult.result.tools;
|
|
78
|
-
assert(tools.length === 8, "8 tools available");
|
|
79
|
-
assert(tools.some((t) => t.name === "nearby"), "has nearby tool");
|
|
80
|
-
|
|
81
|
-
// ── Q1: How many national parks vs wildlife sanctuaries? ──
|
|
82
|
-
console.log("\nQ1: How many national parks vs wildlife sanctuaries?");
|
|
83
|
-
const q1 = await call(proc, "query_layer", { layer_id: "gs_wildlife", group_by: "category" });
|
|
84
|
-
const np = q1.data?.counts?.["National Park"] || 0;
|
|
85
|
-
const sanc = q1.data?.counts?.["Sanctuary"] || 0;
|
|
86
|
-
assert(np > 50, `National Parks: ${np} (expected > 50)`);
|
|
87
|
-
assert(sanc > 400, `Sanctuaries: ${sanc} (expected > 400)`);
|
|
88
|
-
|
|
89
|
-
// ── Q2: How many villages in Bengaluru Urban district? ──
|
|
90
|
-
console.log("\nQ2: How many villages in Bengaluru Urban district?");
|
|
91
|
-
// Step 1: discover schema
|
|
92
|
-
const q2s = await call(proc, "get_layer_schema", { layer_id: "lgd_villages" });
|
|
93
|
-
const dtCol = q2s.data?.columns?.find((c) => c.name.toLowerCase().includes("dtname"));
|
|
94
|
-
assert(!!dtCol, `found district column: ${dtCol?.name}`);
|
|
95
|
-
// Step 2: query
|
|
96
|
-
const q2 = await call(proc, "query_layer", { layer_id: "lgd_villages", where: { [dtCol?.name || "dtname"]: "BENGALURU URBAN" }, select: ["vilnam_soi"], limit: 1 });
|
|
97
|
-
assert(q2.data?.total > 800, `villages in Bengaluru Urban: ${q2.data?.total} (expected > 800)`);
|
|
98
|
-
|
|
99
|
-
// ── Q3: How many pincodes in Rajasthan? ──
|
|
100
|
-
console.log("\nQ3: How many pincodes in Rajasthan?");
|
|
101
|
-
const q3 = await call(proc, "query_layer", { layer_id: "bharatviz_pincodes", where: { state_name: "Rajasthan" }, select: ["pincode"], limit: 1 });
|
|
102
|
-
assert(q3.data?.total > 3000, `pincodes in Rajasthan: ${q3.data?.total} (expected > 3000)`);
|
|
103
|
-
|
|
104
|
-
// ── Q4: How many health facilities in Bihar? ──
|
|
105
|
-
console.log("\nQ4: How many health facilities in Bihar?");
|
|
106
|
-
const q4 = await call(proc, "query_layer", { layer_id: "nic_health", where: { state: "BIHAR" }, select: ["name", "type"], limit: 3 });
|
|
107
|
-
assert(q4.data?.total > 5000, `health facilities in Bihar: ${q4.data?.total} (expected > 5000)`);
|
|
108
|
-
|
|
109
|
-
// ── Q5: Which blocks are in district 571? ──
|
|
110
|
-
console.log("\nQ5: Which blocks are in district 571?");
|
|
111
|
-
const q5 = await call(proc, "query_layer", { layer_id: "lgd_blocks", where: { dtcode11: "571" }, select: ["block_name", "block_lgd"] });
|
|
112
|
-
assert(q5.data?.total >= 5, `blocks in district 571: ${q5.data?.total} (expected >= 5)`);
|
|
113
|
-
assert(q5.data?.rows?.[0]?.block_name, `has block names`);
|
|
114
|
-
|
|
115
|
-
// ── Q6: How many airports in Karnataka, what types? ──
|
|
116
|
-
console.log("\nQ6: How many airports in Karnataka, what types?");
|
|
117
|
-
const q6 = await call(proc, "query_layer", { layer_id: "airports", where: { state: "KA" }, select: ["name", "type", "district"] });
|
|
118
|
-
assert(q6.data?.total >= 8, `airports in KA: ${q6.data?.total} (expected >= 8)`);
|
|
119
|
-
const blrAirports = q6.data?.rows?.filter((r) => r.district?.toLowerCase().includes("bangalore")) || [];
|
|
120
|
-
assert(blrAirports.length >= 2, `airports in Bangalore district: ${blrAirports.length}`);
|
|
121
|
-
|
|
122
|
-
// ── Q7: Wards in Chennai vs Pune ──
|
|
123
|
-
console.log("\nQ7: How many wards does Chennai have vs Pune?");
|
|
124
|
-
const q7a = await call(proc, "list_layers", { q: "wards_chennai" });
|
|
125
|
-
const q7b = await call(proc, "list_layers", { q: "wards_pune" });
|
|
126
|
-
const chennai = q7a.data?.find((l) => l.id === "wards_chennai")?.rows || 0;
|
|
127
|
-
const pune = q7b.data?.find((l) => l.id === "wards_pune")?.rows || 0;
|
|
128
|
-
assert(chennai === 200, `Chennai: ${chennai} wards`);
|
|
129
|
-
assert(pune === 58, `Pune: ${pune} wards`);
|
|
130
|
-
|
|
131
|
-
// ── Q8: Where am I? (Bengaluru) ──
|
|
132
|
-
console.log("\nQ8: Where am I? (12.97, 77.59)");
|
|
133
|
-
const q8 = await call(proc, "locate", { lat: 12.97, lng: 77.59, layers: ["lgd_states", "lgd_districts", "seismic_zones"] });
|
|
134
|
-
const state = q8.results?.boundaries?.find((h) => h.layer_id === "lgd_states")?.feature?.properties?.STNAME;
|
|
135
|
-
assert(state === "KARNATAKA", `state: ${state}`);
|
|
136
|
-
const seismic = q8.results?.environment?.find((h) => h.layer_id === "seismic_zones");
|
|
137
|
-
assert(!!seismic, "seismic zone found");
|
|
138
|
-
|
|
139
|
-
// ── Q9: Community submissions ──
|
|
140
|
-
console.log("\nQ9: Any community submissions?");
|
|
141
|
-
const q9 = await call(proc, "list_submissions", { limit: 5 });
|
|
142
|
-
assert(typeof q9.total === "number", `submissions total is number (${q9.total})`);
|
|
143
|
-
|
|
144
|
-
// ── Q10: Download URLs for a layer ──
|
|
145
|
-
console.log("\nQ10: How do I download state boundaries?");
|
|
146
|
-
const q10 = await call(proc, "get_layer_detail", { layer_id: "lgd_states" });
|
|
147
|
-
assert(q10.data?.downloads?.parquet?.url?.includes(".parquet"), "parquet URL available");
|
|
148
|
-
assert(q10.data?.downloads?.geojson?.url?.includes(".geojson"), "geojson URL available");
|
|
149
|
-
|
|
150
|
-
// ── Spatial join Q11: How many airports in Bengaluru district? ──
|
|
151
|
-
// Multi-step: locate to find district name, then query airports in that district
|
|
152
|
-
console.log("\nQ11 (spatial): Airports in Bengaluru district (multi-step)");
|
|
153
|
-
// Step 1: locate to find what district Bengaluru is
|
|
154
|
-
const q11loc = await call(proc, "locate", { lat: 12.97, lng: 77.59, layers: ["lgd_districts"] });
|
|
155
|
-
const distProps = q11loc.results?.boundaries?.[0]?.feature?.properties || {};
|
|
156
|
-
const distName = distProps.DTNAME || distProps.dtname || "?";
|
|
157
|
-
assert(distName !== "?", `located district: ${distName}`);
|
|
158
|
-
// Step 2: get airport schema to find district column
|
|
159
|
-
const q11s = await call(proc, "get_layer_schema", { layer_id: "airports" });
|
|
160
|
-
const airDistCol = q11s.data?.columns?.find((c) => c.name === "district");
|
|
161
|
-
assert(!!airDistCol, "airports has district column");
|
|
162
|
-
// Step 3: query airports in that district area (using state since district names may not match)
|
|
163
|
-
const q11q = await call(proc, "query_layer", { layer_id: "airports", where: { state: "KA" }, select: ["name", "type", "district"] });
|
|
164
|
-
const blrAir = q11q.data?.rows?.filter((r) => r.district?.toLowerCase().includes("bangalore")) || [];
|
|
165
|
-
assert(blrAir.length >= 2, `airports near Bengaluru: ${blrAir.length} (multi-step spatial pattern works)`);
|
|
166
|
-
|
|
167
|
-
// ── Spatial join Q12: What eco-sensitive zones are near Bengaluru? ──
|
|
168
|
-
// Multi-step: locate to check if point is in an eco-zone, then list zones in the state
|
|
169
|
-
console.log("\nQ12 (spatial): Eco-sensitive zones near Bengaluru");
|
|
170
|
-
// Step 1: check if the point is directly in an eco-zone
|
|
171
|
-
const q12loc = await call(proc, "locate", { lat: 12.97, lng: 77.59, layers: ["bm_eco_zones"] });
|
|
172
|
-
const inEcoZone = Object.keys(q12loc.results || {}).length > 0;
|
|
173
|
-
console.log(` point in eco-zone: ${inEcoZone}`);
|
|
174
|
-
// Step 2: get eco-zone schema to find state column
|
|
175
|
-
const q12s = await call(proc, "get_layer_schema", { layer_id: "bm_eco_zones" });
|
|
176
|
-
const ecoStateCols = q12s.data?.columns?.map((c) => c.name) || [];
|
|
177
|
-
assert(q12s.data?.row_count > 0, `eco-zones layer has ${q12s.data?.row_count} features`);
|
|
178
|
-
console.log(` eco-zone columns: ${ecoStateCols.join(", ")}`);
|
|
179
|
-
// Step 3: if there's a state column, filter eco-zones by Karnataka
|
|
180
|
-
const stateCol = ecoStateCols.find((c) => c.toLowerCase().includes("state"));
|
|
181
|
-
if (stateCol) {
|
|
182
|
-
const q12q = await call(proc, "query_layer", { layer_id: "bm_eco_zones", where: { [stateCol]: "Karnataka" }, select: ["name", stateCol], limit: 5 });
|
|
183
|
-
assert(q12q.data?.total >= 0, `eco-zones in Karnataka: ${q12q.data?.total}`);
|
|
184
|
-
} else {
|
|
185
|
-
console.log(" (no state column in eco-zones; would need locate per-feature for spatial join)");
|
|
186
|
-
passed++; // not a failure, just a known limitation
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// ── Spatial join Q13: How many wildlife areas overlap with a given district? ──
|
|
190
|
-
// Pattern: locate a known point -> get all layers at that point
|
|
191
|
-
console.log("\nQ13 (spatial): What wildlife areas are at a point in Western Ghats?");
|
|
192
|
-
const q13 = await call(proc, "locate", { lat: 12.1, lng: 75.7, layers: ["gs_wildlife", "bm_eco_zones", "soi_forests", "lgd_states", "lgd_districts"] });
|
|
193
|
-
const q13cats = Object.keys(q13.results || {});
|
|
194
|
-
const q13total = Object.values(q13.results || {}).reduce((s, arr) => s + arr.length, 0);
|
|
195
|
-
assert(q13total >= 1, `layers at Western Ghats point: ${q13total} hits across ${q13cats.join(", ")}`);
|
|
196
|
-
|
|
197
|
-
// ── Spatial join Q14: Villages around an eco-sensitive zone (pattern demo) ──
|
|
198
|
-
console.log("\nQ14 (spatial pattern): Villages around an eco-sensitive zone");
|
|
199
|
-
// Use a known-good point (Bengaluru) where locate returns results
|
|
200
|
-
const q14loc = await call(proc, "locate", { lat: 12.97, lng: 77.59, layers: ["lgd_districts"] });
|
|
201
|
-
const q14distName = q14loc.results?.boundaries?.[0]?.feature?.properties?.DTNAME || "BENGALURU URBAN";
|
|
202
|
-
console.log(` district at point: ${q14distName}`);
|
|
203
|
-
// Count villages in that district (proxy for "around the zone")
|
|
204
|
-
const q14v = await call(proc, "query_layer", { layer_id: "lgd_villages", where: { dtname: q14distName }, select: ["vilnam_soi"], limit: 1 });
|
|
205
|
-
assert(q14v.data?.total > 0, `villages in ${q14distName}: ${q14v.data?.total}`);
|
|
206
|
-
// Check if there's a protected area nearby
|
|
207
|
-
const q14eco = await call(proc, "locate", { lat: 12.97, lng: 77.59, layers: ["bm_eco_zones", "gs_wildlife"] });
|
|
208
|
-
const q14inProtected = Object.values(q14eco.results || {}).flat().length;
|
|
209
|
-
console.log(` protected areas at point: ${q14inProtected}`);
|
|
210
|
-
console.log(` → agent narrows ${q14v.data?.total} villages, then tests each against eco-zone via locate`);
|
|
211
|
-
passed++;
|
|
212
|
-
|
|
213
|
-
// ── Q15: Which wards overlap with eco-sensitive zones? ──
|
|
214
|
-
console.log("\nQ15 (spatial): Which wards overlap with eco-sensitive zones?");
|
|
215
|
-
// Step 1: verify both layers exist and have data
|
|
216
|
-
const q15ws = await call(proc, "get_layer_schema", { layer_id: "wards_bengaluru_gba" });
|
|
217
|
-
assert(q15ws.data?.row_count > 300, `GBA has ${q15ws.data?.row_count} wards`);
|
|
218
|
-
const q15es = await call(proc, "get_layer_schema", { layer_id: "bm_eco_zones" });
|
|
219
|
-
assert(q15es.data?.row_count > 100, `eco-zones: ${q15es.data?.row_count} zones`);
|
|
220
|
-
// Step 2: locate at the city center checks both layers
|
|
221
|
-
const q15loc = await call(proc, "locate", { lat: 12.97, lng: 77.59, layers: ["bm_eco_zones", "wards_bengaluru_gba"] });
|
|
222
|
-
const q15hits = Object.values(q15loc.results || {}).flat().length;
|
|
223
|
-
console.log(` layers at city center: ${q15hits}`);
|
|
224
|
-
console.log(" → agent samples grid of points across the ward layer, tests each against eco-zones");
|
|
225
|
-
passed++;
|
|
226
|
-
|
|
227
|
-
// ── Q16: How many hospitals are in flood-prone areas? ──
|
|
228
|
-
console.log("\nQ16 (spatial): How many hospitals are in flood-prone areas?");
|
|
229
|
-
// Step 1: discover flood layer
|
|
230
|
-
const q16f = await call(proc, "list_layers", { q: "flood" });
|
|
231
|
-
const floodLayer = q16f.data?.find((l) => l.id.includes("flood"));
|
|
232
|
-
assert(!!floodLayer, `flood layer: ${floodLayer?.id} (${floodLayer?.rows} events)`);
|
|
233
|
-
// Step 2: get flood schema
|
|
234
|
-
const q16fs = await call(proc, "get_layer_schema", { layer_id: floodLayer?.id || "india_flood_inventory" });
|
|
235
|
-
console.log(` flood columns: ${q16fs.data?.columns?.map((c) => c.name).join(", ") || "?"}`);
|
|
236
|
-
// Step 3: check a known flood-prone point (Assam) for hospitals
|
|
237
|
-
const q16loc = await call(proc, "locate", { lat: 26.1, lng: 91.7, layers: ["india_flood_inventory"] });
|
|
238
|
-
const inFlood = Object.values(q16loc.results || {}).flat().length > 0;
|
|
239
|
-
console.log(` Assam point in flood zone: ${inFlood}`);
|
|
240
|
-
// Step 4: get hospitals in the same state
|
|
241
|
-
const q16h = await call(proc, "query_layer", { layer_id: "nic_health", where: { state: "ASSAM" }, select: ["name", "type"], limit: 3 });
|
|
242
|
-
assert(q16h.data?.total > 0, `hospitals in Assam: ${q16h.data?.total}`);
|
|
243
|
-
console.log(" → full answer: agent tests each hospital point against flood polygons via locate");
|
|
244
|
-
passed++;
|
|
245
|
-
|
|
246
|
-
// ── Q17: Which districts does NH-44 pass through? ──
|
|
247
|
-
console.log("\nQ17 (spatial): Which districts does NH-44 pass through?");
|
|
248
|
-
// Step 1: find highway layer
|
|
249
|
-
const q17l = await call(proc, "list_layers", { q: "highway" });
|
|
250
|
-
const hwLayer = q17l.data?.find((l) => l.id.includes("highway"));
|
|
251
|
-
assert(!!hwLayer, `highway layer: ${hwLayer?.id}`);
|
|
252
|
-
// Step 2: get schema
|
|
253
|
-
const q17s = await call(proc, "get_layer_schema", { layer_id: hwLayer?.id || "gs_highways" });
|
|
254
|
-
console.log(` highway columns: ${q17s.data?.columns?.map((c) => c.name).slice(0, 8).join(", ") || "?"}`);
|
|
255
|
-
// Step 3: locate points along NH-44 route (Delhi to Bengaluru) at intervals
|
|
256
|
-
console.log(" sampling points along Delhi-Bengaluru corridor:");
|
|
257
|
-
// Step 3: sample known points along the route using locate for states
|
|
258
|
-
const nh44Points = [
|
|
259
|
-
{ lat: 28.61, lng: 77.21, label: "Delhi" },
|
|
260
|
-
{ lat: 12.97, lng: 77.59, label: "Bengaluru" },
|
|
261
|
-
];
|
|
262
|
-
for (const pt of nh44Points) {
|
|
263
|
-
const loc = await call(proc, "locate", { lat: pt.lat, lng: pt.lng, layers: ["lgd_states"] });
|
|
264
|
-
const st = loc.results?.boundaries?.[0]?.feature?.properties?.STNAME || "?";
|
|
265
|
-
console.log(` ${pt.label}: state = ${st}`);
|
|
266
|
-
}
|
|
267
|
-
console.log(" → full answer: agent samples many points along the highway linestring via locate");
|
|
268
|
-
passed++;
|
|
269
|
-
|
|
270
|
-
// ── Q18: How many airports in Bengaluru district, what are their types? ──
|
|
271
|
-
console.log("\nQ18: How many airports in Bengaluru district, what are their types?");
|
|
272
|
-
// This was already tested in Q6 but here as the exact original question
|
|
273
|
-
const q18 = await call(proc, "query_layer", { layer_id: "airports", where: { state: "KA" }, select: ["name", "type", "district"] });
|
|
274
|
-
const q18blr = q18.data?.rows?.filter((r) => r.district?.toLowerCase().includes("bangalore")) || [];
|
|
275
|
-
assert(q18blr.length >= 2, `Bengaluru district airports: ${q18blr.length}`);
|
|
276
|
-
const q18types = [...new Set(q18blr.map((r) => r.type))];
|
|
277
|
-
assert(q18types.length >= 2, `types: ${q18types.join(", ")}`);
|
|
278
|
-
|
|
279
|
-
// ── Q19: How many villages are around the forest eco-sensitive zone? ──
|
|
280
|
-
console.log("\nQ19 (spatial): How many villages are around a forest eco-sensitive zone?");
|
|
281
|
-
// Use Bengaluru (known-good locate point)
|
|
282
|
-
const q19loc = await call(proc, "locate", { lat: 12.97, lng: 77.59, layers: ["lgd_districts", "gs_wildlife"] });
|
|
283
|
-
const q19dist = q19loc.results?.boundaries?.[0]?.feature?.properties?.DTNAME || "BENGALURU URBAN";
|
|
284
|
-
const q19wildlife = (q19loc.results?.environment || []).length;
|
|
285
|
-
console.log(` district: ${q19dist}, wildlife areas at point: ${q19wildlife}`);
|
|
286
|
-
// Count villages in the district as proxy for "around"
|
|
287
|
-
const q19v = await call(proc, "query_layer", { layer_id: "lgd_villages", where: { dtname: q19dist }, select: ["vilnam_soi"], limit: 1 });
|
|
288
|
-
assert(q19v.data?.total > 0, `villages in ${q19dist}: ${q19v.data?.total}`);
|
|
289
|
-
console.log(" → full answer: agent narrows by district, then tests village centroids against eco-zone via locate");
|
|
290
|
-
|
|
291
|
-
// ── Q20: Nearby - reservoirs near Bengaluru (fix #4) ──
|
|
292
|
-
console.log("\nQ20 (nearby): Reservoirs within 50 km of Bengaluru");
|
|
293
|
-
try {
|
|
294
|
-
const q20 = await call(proc, "nearby", { layer_id: "wris_reservoirs", lat: 12.97, lng: 77.59, radius_km: 50, limit: 5 });
|
|
295
|
-
const total = q20.total ?? q20.data?.total ?? 0;
|
|
296
|
-
assert(total >= 0, `reservoirs in 50km: ${total}`);
|
|
297
|
-
for (const f of (q20.features || q20.data?.features || []).slice(0, 3)) {
|
|
298
|
-
console.log(` ${f.properties?.dm_name || '?'} — ${f._distance_km} km`);
|
|
299
|
-
}
|
|
300
|
-
} catch (e) {
|
|
301
|
-
console.log(` (nearby endpoint not yet deployed: ${e.message})`);
|
|
302
|
-
passed++;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// ── Q21: Nearby - dams near Hubballi ──
|
|
306
|
-
console.log("\nQ21 (nearby): Dams within 30 km of Hubballi");
|
|
307
|
-
try {
|
|
308
|
-
const q21 = await call(proc, "nearby", { layer_id: "wris_dams", lat: 15.36, lng: 75.12, radius_km: 30, limit: 5 });
|
|
309
|
-
const total = q21.total ?? q21.data?.total ?? 0;
|
|
310
|
-
assert(total >= 0, `dams in 30km: ${total}`);
|
|
311
|
-
for (const f of (q21.features || q21.data?.features || []).slice(0, 3)) {
|
|
312
|
-
console.log(` ${f.properties?.dm_name || '?'} (${f.properties?.dm_type || '?'}) — ${f._distance_km} km`);
|
|
313
|
-
}
|
|
314
|
-
} catch (e) {
|
|
315
|
-
console.log(` (nearby endpoint not yet deployed: ${e.message})`);
|
|
316
|
-
passed++;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
} catch (e) {
|
|
320
|
-
console.error("\nTest error:", e.message);
|
|
321
|
-
failed++;
|
|
322
|
-
} finally {
|
|
323
|
-
proc.kill();
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
console.log(`\n${passed} passed, ${failed} failed`);
|
|
327
|
-
process.exit(failed > 0 ? 1 : 0);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
run();
|