bharatlas-mcp 1.0.2 → 1.1.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/LICENSE +26 -0
- package/README.md +2 -2
- package/index.js +280 -8
- package/package.json +4 -4
- package/server.json +3 -3
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
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/bharatlas-mcp)
|
|
4
4
|
[](./LICENSE)
|
|
5
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, reservoirs, dams, eco-sensitive zones, seismic zones, flood history, highways, airports, health facilities, pincodes, electoral constituencies, and community submissions.
|
|
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
7
|
|
|
8
8
|
## Install
|
|
9
9
|
|
|
@@ -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 + reservoirs + wetlands + ramsar sites + dams
|
|
71
|
+
- **Concept-to-layer mapping**: "water bodies" = rivers + canals + reservoirs + wetlands + ramsar sites + dams; "groundwater" = aquifers + extraction stage
|
|
72
72
|
- **Spatial join workflow**: locate for context, query for data, nearby for proximity
|
|
73
73
|
|
|
74
74
|
## Links
|
package/index.js
CHANGED
|
@@ -7,10 +7,21 @@ import {
|
|
|
7
7
|
ListToolsRequestSchema,
|
|
8
8
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
9
9
|
import https from "node:https";
|
|
10
|
+
import { readFileSync, writeFileSync, existsSync } from "node:fs";
|
|
11
|
+
import { homedir } from "node:os";
|
|
12
|
+
import { join } from "node:path";
|
|
10
13
|
|
|
11
14
|
const API = process.env.BHARATLAS_API || "https://bharatlas.com/api/v1";
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
// collect (write side): authoring over the collect REST API. The read tools
|
|
17
|
+
// need no auth; the collect tools act only on maps whose share link the user
|
|
18
|
+
// has registered (register_map) — the link's token scope IS the permission, so
|
|
19
|
+
// this server can never touch a map the user does not hold a link to.
|
|
20
|
+
const COLLECT_API = process.env.COLLECT_API || "https://collect.bharatlas.com/api/collect/v1";
|
|
21
|
+
const COLLECT_API_KEY = process.env.COLLECT_API_KEY || ""; // optional: only for headless create_map
|
|
22
|
+
const COLLECT_STORE = process.env.COLLECT_MCP_STORE || join(homedir(), ".bharatlas-mcp.json");
|
|
23
|
+
|
|
24
|
+
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. It also drives collect.bharatlas.com for authoring your own maps (see "Collect" below).
|
|
14
25
|
|
|
15
26
|
Workflow patterns:
|
|
16
27
|
|
|
@@ -42,8 +53,10 @@ Cross-layer queries (combining data from different layers):
|
|
|
42
53
|
- Never assume one layer is enough. Think about what layers need to be combined to answer the question fully.
|
|
43
54
|
- Use locate as the bridge: find what's at a point across ALL relevant layers in one call by passing multiple layer IDs.
|
|
44
55
|
- **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
|
-
- "
|
|
56
|
+
- "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
|
|
58
|
+
- "forests/green cover/ecology" → soi_forests, gs_wildlife, bm_eco_zones, biogeographic_zones
|
|
59
|
+
- "agriculture/farming/cropping zones" → agro_ecological_zones, agro_climatic_zones
|
|
47
60
|
- "hazards/risks" → seismic_zones, india_flood_inventory
|
|
48
61
|
- "health/medical" → nic_health
|
|
49
62
|
- "boundaries/admin" → lgd_states, lgd_districts, lgd_subdistricts, lgd_blocks, lgd_villages
|
|
@@ -54,7 +67,16 @@ Column naming conventions (vary by source):
|
|
|
54
67
|
- State: State_LGD (number), STNAME, stname, state, state_name
|
|
55
68
|
- District: Dist_LGD (number), DTNAME, dtname, district, dtcode11
|
|
56
69
|
- Block: Block_LGD, BNAME, block_name, blkcode11
|
|
57
|
-
- Names are often UPPERCASE in LGD layers, mixed case in other sources
|
|
70
|
+
- Names are often UPPERCASE in LGD layers, mixed case in other sources
|
|
71
|
+
|
|
72
|
+
Collect (author your own map): this server also drives collect.bharatlas.com, the crowd map-capture tool in the bharatlas suite.
|
|
73
|
+
- Create maps ONLINE at collect.bharatlas.com — the browser handles the anti-abuse check, so no account and no API key are needed. Point the user there to make one. They get three share links, each with a token in the URL #fragment: admin (full control), collect (add points), view (read published points).
|
|
74
|
+
- register_map: paste any collect share link to manage that map here. The link's scope decides what you can do:
|
|
75
|
+
- view link -> get_map, get_records: read / query / export that map's published points (analyse or back up what has been collected).
|
|
76
|
+
- collect link -> the above; field capture itself is done in the browser on a phone via the collect link.
|
|
77
|
+
- 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.
|
|
79
|
+
- 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.`;
|
|
58
80
|
|
|
59
81
|
const TOOLS = [
|
|
60
82
|
{
|
|
@@ -62,14 +84,14 @@ const TOOLS = [
|
|
|
62
84
|
description:
|
|
63
85
|
"List available geo layers. Use to discover what data bharatlas has. " +
|
|
64
86
|
"Returns layer IDs, names, row counts, categories, and download formats. " +
|
|
65
|
-
"Filter by category (boundaries, city-wards, environment, transport, etc.), " +
|
|
87
|
+
"Filter by category (boundaries, city-wards, environment, water, agriculture, transport, etc.), " +
|
|
66
88
|
"admin level (state, district, block, village, etc.), source, or text search.",
|
|
67
89
|
inputSchema: {
|
|
68
90
|
type: "object",
|
|
69
91
|
properties: {
|
|
70
92
|
category: {
|
|
71
93
|
type: "string",
|
|
72
|
-
description: "Filter by category: boundaries, city-wards, people, environment, transport, infrastructure, health-edu",
|
|
94
|
+
description: "Filter by category: boundaries, city-wards, people, environment, water, agriculture, transport, infrastructure, health-edu",
|
|
73
95
|
},
|
|
74
96
|
level: {
|
|
75
97
|
type: "string",
|
|
@@ -138,7 +160,7 @@ const TOOLS = [
|
|
|
138
160
|
limit: { type: "number", description: "Max rows (default 100, max 1000)" },
|
|
139
161
|
include_centroid: {
|
|
140
162
|
type: "boolean",
|
|
141
|
-
description: "Include _lat/_lng centroid coordinates
|
|
163
|
+
description: "Include _lat/_lng centroid coordinates (defaults to true). Set false to exclude.",
|
|
142
164
|
},
|
|
143
165
|
},
|
|
144
166
|
required: ["layer_id"],
|
|
@@ -237,6 +259,116 @@ const TOOLS = [
|
|
|
237
259
|
},
|
|
238
260
|
},
|
|
239
261
|
},
|
|
262
|
+
|
|
263
|
+
// --- collect (authoring): act only on maps whose share link you registered ---
|
|
264
|
+
{
|
|
265
|
+
name: "register_map",
|
|
266
|
+
description:
|
|
267
|
+
"Register a collect map so this server can act on it. Paste the whole share link " +
|
|
268
|
+
"(e.g. https://collect.bharatlas.com/c/<id>/admin#<token>). The token in the #fragment sets your scope: " +
|
|
269
|
+
"admin = full control, collect = add points, view = read published. New maps are created online at " +
|
|
270
|
+
"collect.bharatlas.com first (no account or key needed); this registers one you already made.",
|
|
271
|
+
inputSchema: {
|
|
272
|
+
type: "object",
|
|
273
|
+
properties: { link: { type: "string", description: "a collect.bharatlas.com share link with the token in the #fragment" } },
|
|
274
|
+
required: ["link"],
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
name: "list_my_maps",
|
|
279
|
+
description: "List the collect maps you have registered here (local store), each with its scope.",
|
|
280
|
+
inputSchema: { type: "object", properties: {} },
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
name: "get_map",
|
|
284
|
+
description: "A collect map's metadata + record counts, plus a link to open it in collect. Any registered scope.",
|
|
285
|
+
inputSchema: { type: "object", properties: { id: { type: "string", description: "the map (collection) id" } }, required: ["id"] },
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
name: "get_records",
|
|
289
|
+
description:
|
|
290
|
+
"A collect map's records as a GeoJSON FeatureCollection — for reading, analysis, or backup/export. " +
|
|
291
|
+
"view and collect scope return published points; admin can also read pending/rejected via status.",
|
|
292
|
+
inputSchema: {
|
|
293
|
+
type: "object",
|
|
294
|
+
properties: { id: { type: "string" }, status: { type: "string", description: "admin only: pending | published | rejected" } },
|
|
295
|
+
required: ["id"],
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
name: "moderate_record",
|
|
300
|
+
description: "Approve or reject one pending point (needs the admin link). Pass the map id it belongs to.",
|
|
301
|
+
inputSchema: {
|
|
302
|
+
type: "object",
|
|
303
|
+
properties: {
|
|
304
|
+
id: { type: "string", description: "the map (collection) id" },
|
|
305
|
+
record_id: { type: "string" },
|
|
306
|
+
status: { enum: ["published", "rejected", "pending"] },
|
|
307
|
+
reason: { type: "string" },
|
|
308
|
+
},
|
|
309
|
+
required: ["id", "record_id", "status"],
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
name: "import_points",
|
|
314
|
+
description:
|
|
315
|
+
"Bulk-import points you already hold into a collect map (needs the admin link). NOT for synthetic data. " +
|
|
316
|
+
"Requires a named source + rights confirmation; each row lands with that source as its provenance.",
|
|
317
|
+
inputSchema: {
|
|
318
|
+
type: "object",
|
|
319
|
+
properties: {
|
|
320
|
+
id: { type: "string" },
|
|
321
|
+
records: { type: "array", items: { type: "object" }, description: "GeoJSON-like {geometry, properties}" },
|
|
322
|
+
source: { type: "string" },
|
|
323
|
+
rights_confirmed: { type: "boolean", description: "you have the right to publish this under the map's licence" },
|
|
324
|
+
},
|
|
325
|
+
required: ["id", "records", "source", "rights_confirmed"],
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
name: "edit_map",
|
|
330
|
+
description:
|
|
331
|
+
"Edit a collect map's settings: name/description/purpose/category/data_year/basemap (needs the admin link). " +
|
|
332
|
+
"Licence can only change while the map has no records.",
|
|
333
|
+
inputSchema: {
|
|
334
|
+
type: "object",
|
|
335
|
+
properties: {
|
|
336
|
+
id: { type: "string" }, name: { type: "string" }, description: { type: "string" }, purpose: { type: "string" },
|
|
337
|
+
category: { type: "string" }, data_year: { type: ["integer", "null"] }, basemap: { type: "string" }, license: { type: "string" },
|
|
338
|
+
},
|
|
339
|
+
required: ["id"],
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
name: "publish",
|
|
344
|
+
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.",
|
|
347
|
+
inputSchema: { type: "object", properties: { id: { type: "string" } }, required: ["id"] },
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
name: "create_map",
|
|
351
|
+
description:
|
|
352
|
+
"Optional: create a collect map programmatically. Most maps are made online at collect.bharatlas.com (no key needed) — " +
|
|
353
|
+
"prefer that and register_map the link. This path needs COLLECT_API_KEY (the request-only anti-abuse gate) and " +
|
|
354
|
+
"auto-registers the new admin link.",
|
|
355
|
+
inputSchema: {
|
|
356
|
+
type: "object",
|
|
357
|
+
properties: {
|
|
358
|
+
name: { type: "string", description: "3-120 chars" },
|
|
359
|
+
purpose: { type: "string", description: "shown to contributors" },
|
|
360
|
+
description: { type: "string" },
|
|
361
|
+
geometry: { type: "array", items: { enum: ["point", "line", "polygon"] }, description: "what contributors may add" },
|
|
362
|
+
fields: { type: "array", items: { type: "object" }, description: "the form for each record (see collect.bharatlas.com/schema/v1.json)" },
|
|
363
|
+
license: { type: "string", description: "open licence id; default CC-BY-4.0" },
|
|
364
|
+
category: { type: "string" },
|
|
365
|
+
data_year: { type: "integer" },
|
|
366
|
+
moderation: { type: "boolean", description: "default true — points wait for approval" },
|
|
367
|
+
basemap: { enum: ["positron", "satellite", "topo"] },
|
|
368
|
+
},
|
|
369
|
+
required: ["name", "purpose", "geometry", "fields"],
|
|
370
|
+
},
|
|
371
|
+
},
|
|
240
372
|
];
|
|
241
373
|
|
|
242
374
|
function httpGet(url) {
|
|
@@ -264,6 +396,71 @@ async function callApi(path, params = {}) {
|
|
|
264
396
|
return httpGet(url.toString());
|
|
265
397
|
}
|
|
266
398
|
|
|
399
|
+
// ---- collect: local credential store + scoped auth --------------------------
|
|
400
|
+
const SCOPE_BY_PREFIX = { adm: "admin", edt: "edit", viw: "view" };
|
|
401
|
+
const SCOPE_RANK = { view: 0, edit: 1, admin: 2 };
|
|
402
|
+
const scopeOfToken = (t) => SCOPE_BY_PREFIX[String(t || "").slice(0, 3)] || null;
|
|
403
|
+
const atLeastScope = (have, need) => (SCOPE_RANK[have] ?? -1) >= SCOPE_RANK[need];
|
|
404
|
+
|
|
405
|
+
function loadStore() {
|
|
406
|
+
try { return existsSync(COLLECT_STORE) ? JSON.parse(readFileSync(COLLECT_STORE, "utf8")) : { maps: {} }; }
|
|
407
|
+
catch { return { maps: {} }; }
|
|
408
|
+
}
|
|
409
|
+
function saveStore(s) { try { writeFileSync(COLLECT_STORE, JSON.stringify(s, null, 2)); } catch { /* best effort */ } }
|
|
410
|
+
function rememberMap(id, entry) { const s = loadStore(); s.maps[id] = { ...s.maps[id], ...entry }; saveStore(s); }
|
|
411
|
+
function mapEntry(id) {
|
|
412
|
+
const m = loadStore().maps[id];
|
|
413
|
+
if (!m) throw new Error(`map ${id} is not registered. Create it online at collect.bharatlas.com, then register_map with its share link.`);
|
|
414
|
+
return m;
|
|
415
|
+
}
|
|
416
|
+
function tokenFor(id, need) {
|
|
417
|
+
const m = mapEntry(id);
|
|
418
|
+
if (need && !atLeastScope(m.scope, need)) {
|
|
419
|
+
throw new Error(`this needs the ${need} link for map ${id}; you registered the ${m.scope} link. Register the ${need} link to do this.`);
|
|
420
|
+
}
|
|
421
|
+
return m.token;
|
|
422
|
+
}
|
|
423
|
+
function parseShareLink(link) {
|
|
424
|
+
let u;
|
|
425
|
+
try { u = new URL(String(link).trim()); } catch { throw new Error("not a valid URL — paste the whole collect share link"); }
|
|
426
|
+
const token = (u.hash || "").replace(/^#/, "");
|
|
427
|
+
const scope = scopeOfToken(token);
|
|
428
|
+
if (!scope) throw new Error("no token found in the link #fragment (expected #adm_… / #edt_… / #viw_…)");
|
|
429
|
+
const parts = u.pathname.split("/").filter(Boolean); // ["c", "<id>", "admin"?]
|
|
430
|
+
const ci = parts.indexOf("c");
|
|
431
|
+
const id = ci >= 0 ? parts[ci + 1] : null;
|
|
432
|
+
if (!id) throw new Error("could not find the map id in the link path (expected /c/<id>…)");
|
|
433
|
+
return { id, token, scope, link: u.toString() };
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// ---- collect: HTTP (GET/POST/PATCH with auth headers) -----------------------
|
|
437
|
+
function httpReq(method, urlStr, { headers = {}, body } = {}) {
|
|
438
|
+
return new Promise((resolve, reject) => {
|
|
439
|
+
const data = body !== undefined ? JSON.stringify(body) : undefined;
|
|
440
|
+
const opts = { method, headers: { ...headers } };
|
|
441
|
+
if (data) opts.headers["content-type"] = "application/json";
|
|
442
|
+
const req = https.request(new URL(urlStr), opts, (res) => {
|
|
443
|
+
let buf = "";
|
|
444
|
+
res.on("data", (c) => (buf += c));
|
|
445
|
+
res.on("end", () => {
|
|
446
|
+
let parsed;
|
|
447
|
+
try { parsed = buf ? JSON.parse(buf) : {}; } catch { parsed = { raw: buf }; }
|
|
448
|
+
if (res.statusCode >= 400) reject(new Error(parsed.error || `HTTP ${res.statusCode}: ${buf.slice(0, 200)}`));
|
|
449
|
+
else resolve(parsed);
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
req.on("error", reject);
|
|
453
|
+
if (data) req.write(data);
|
|
454
|
+
req.end();
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
function collectApi(method, path, { token, apiKey, body } = {}) {
|
|
458
|
+
const headers = {};
|
|
459
|
+
if (token) headers.authorization = `Bearer ${token}`;
|
|
460
|
+
if (apiKey) headers["x-api-key"] = apiKey;
|
|
461
|
+
return httpReq(method, COLLECT_API + path, { headers, body });
|
|
462
|
+
}
|
|
463
|
+
|
|
267
464
|
async function handleTool(name, args) {
|
|
268
465
|
switch (name) {
|
|
269
466
|
case "list_layers": {
|
|
@@ -319,13 +516,88 @@ async function handleTool(name, args) {
|
|
|
319
516
|
return callApi("/submissions", { q, category, sort, limit, offset });
|
|
320
517
|
}
|
|
321
518
|
|
|
519
|
+
// --- collect (authoring) ---
|
|
520
|
+
case "register_map": {
|
|
521
|
+
const { id, token, scope, link } = parseShareLink(args.link);
|
|
522
|
+
let name;
|
|
523
|
+
try {
|
|
524
|
+
const meta = await collectApi("GET", `/collections/${id}`, { token });
|
|
525
|
+
name = meta.name || meta.data?.name;
|
|
526
|
+
} catch { /* metadata is best-effort; still register */ }
|
|
527
|
+
rememberMap(id, { token, scope, link, name, at: new Date().toISOString() });
|
|
528
|
+
const can = scope === "admin"
|
|
529
|
+
? "moderate, edit, import and publish"
|
|
530
|
+
: scope === "edit"
|
|
531
|
+
? "read and export (add points in the browser via the collect link)"
|
|
532
|
+
: "read and export published points";
|
|
533
|
+
return { id, scope, name, note: `Registered the ${scope} link for "${name || id}". You can now ${can}.` };
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
case "list_my_maps":
|
|
537
|
+
return Object.entries(loadStore().maps).map(([id, m]) => ({ id, name: m.name, scope: m.scope, at: m.at }));
|
|
538
|
+
|
|
539
|
+
case "get_map": {
|
|
540
|
+
const m = mapEntry(args.id);
|
|
541
|
+
const meta = await collectApi("GET", `/collections/${args.id}`, { token: m.token });
|
|
542
|
+
return { ...meta, open_in_collect: m.link };
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
case "get_records": {
|
|
546
|
+
const m = mapEntry(args.id);
|
|
547
|
+
const qs = args.status ? `?status=${encodeURIComponent(args.status)}` : "";
|
|
548
|
+
return collectApi("GET", `/collections/${args.id}/records${qs}`, { token: m.token });
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
case "moderate_record":
|
|
552
|
+
return collectApi("POST", `/records/${args.record_id}/moderate`, {
|
|
553
|
+
token: tokenFor(args.id, "admin"),
|
|
554
|
+
body: { status: args.status, reason: args.reason },
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
case "import_points":
|
|
558
|
+
return collectApi("POST", `/collections/${args.id}/import`, {
|
|
559
|
+
token: tokenFor(args.id, "admin"),
|
|
560
|
+
body: { records: args.records, source: args.source, rights_confirmed: !!args.rights_confirmed },
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
case "edit_map": {
|
|
564
|
+
const { id, ...patch } = args;
|
|
565
|
+
return collectApi("PATCH", `/collections/${id}`, { token: tokenFor(id, "admin"), body: patch });
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
case "publish":
|
|
569
|
+
return collectApi("POST", `/collections/${args.id}/publish`, { token: tokenFor(args.id, "admin") });
|
|
570
|
+
|
|
571
|
+
case "create_map": {
|
|
572
|
+
if (!COLLECT_API_KEY) {
|
|
573
|
+
throw new Error("create_map needs COLLECT_API_KEY (request-only). Most maps are created online at collect.bharatlas.com — do that, then register_map with the share link.");
|
|
574
|
+
}
|
|
575
|
+
const schema_doc = { version: 1, geometry: args.geometry, fields: args.fields };
|
|
576
|
+
if (args.category) schema_doc.category = args.category;
|
|
577
|
+
if (args.basemap) schema_doc.basemap = args.basemap;
|
|
578
|
+
const body = {
|
|
579
|
+
name: args.name, purpose: args.purpose, description: args.description,
|
|
580
|
+
license: args.license || "CC-BY-4.0", data_year: args.data_year,
|
|
581
|
+
moderation: args.moderation === false ? 0 : 1, schema_doc,
|
|
582
|
+
};
|
|
583
|
+
const r = await collectApi("POST", "/collections", { apiKey: COLLECT_API_KEY, body });
|
|
584
|
+
const adminLink = r.links?.admin;
|
|
585
|
+
if (adminLink) {
|
|
586
|
+
try {
|
|
587
|
+
const p = parseShareLink(adminLink);
|
|
588
|
+
rememberMap(p.id, { token: p.token, scope: p.scope, link: p.link, name: args.name, at: new Date().toISOString() });
|
|
589
|
+
} catch { /* ignore */ }
|
|
590
|
+
}
|
|
591
|
+
return { id: r.id, links: r.links, note: "Share links.collect with contributors. Admin link registered locally." };
|
|
592
|
+
}
|
|
593
|
+
|
|
322
594
|
default:
|
|
323
595
|
throw new Error(`Unknown tool: ${name}`);
|
|
324
596
|
}
|
|
325
597
|
}
|
|
326
598
|
|
|
327
599
|
const server = new Server(
|
|
328
|
-
{ name: "bharatlas-mcp", version: "1.
|
|
600
|
+
{ name: "bharatlas-mcp", version: "1.1.0" },
|
|
329
601
|
{ capabilities: { tools: {} }, instructions: SERVER_INSTRUCTIONS },
|
|
330
602
|
);
|
|
331
603
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bharatlas-mcp",
|
|
3
|
-
"version": "1.0
|
|
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" },
|
|
3
|
+
"version": "1.1.0",
|
|
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
|
+
"keywords": ["mcp", "india", "geo", "geospatial", "gis", "boundaries", "parquet", "pmtiles", "llm", "claude", "bharatlas", "collect"],
|
|
6
|
+
"repository": { "type": "git", "url": "git+https://github.com/urbanmorph/geodata.git", "directory": "mcp" },
|
|
7
7
|
"homepage": "https://bharatlas.com/mcp",
|
|
8
8
|
"mcpName": "io.github.urbanmorph/bharatlas-mcp",
|
|
9
9
|
"type": "module",
|
package/server.json
CHANGED
|
@@ -1,13 +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), and author collect maps: register a share link, moderate contributions, and publish to the catalog.",
|
|
5
|
+
"version": "1.1.0",
|
|
6
6
|
"packages": [
|
|
7
7
|
{
|
|
8
8
|
"registryType": "npm",
|
|
9
9
|
"identifier": "bharatlas-mcp",
|
|
10
|
-
"version": "1.0
|
|
10
|
+
"version": "1.1.0",
|
|
11
11
|
"transport": { "type": "stdio" }
|
|
12
12
|
}
|
|
13
13
|
]
|