nextbillion-mcp 0.1.3 → 0.1.5
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/dist/tools/maps/polyline.d.ts +16 -0
- package/dist/tools/maps/polyline.js +117 -0
- package/dist/tools/maps/polyline.js.map +1 -0
- package/dist/tools/maps/static-route-map.js +38 -10
- package/dist/tools/maps/static-route-map.js.map +1 -1
- package/dist/tools/types.d.ts +8 -1
- package/dist/tools/types.js +11 -1
- package/dist/tools/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Coordinate } from '../shared/geo.js';
|
|
2
|
+
export declare function decodePolyline(encoded: string): Coordinate[];
|
|
3
|
+
export declare function encodePolyline(points: Coordinate[]): string;
|
|
4
|
+
/** Douglas-Peucker simplification with the tolerance in approximate meters. */
|
|
5
|
+
export declare function simplifyPoints(points: Coordinate[], toleranceMeters: number): Coordinate[];
|
|
6
|
+
export interface FittedGeometry {
|
|
7
|
+
encoded: string;
|
|
8
|
+
originalPointCount: number;
|
|
9
|
+
pointCount: number;
|
|
10
|
+
simplified: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Return an encoded polyline whose length is at most `maxEncodedChars`, simplifying
|
|
14
|
+
* with progressively coarser tolerances until it fits (or only endpoints remain).
|
|
15
|
+
*/
|
|
16
|
+
export declare function fitPolylineToBudget(points: Coordinate[], maxEncodedChars: number): FittedGeometry;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google encoded polyline codec (precision 5) plus Douglas-Peucker simplification.
|
|
3
|
+
* Used to shrink long route geometries so the static-image GET URL stays within
|
|
4
|
+
* the API's 8192-byte limit: a 600 km route encodes to ~30k characters (~50 kB
|
|
5
|
+
* URL-encoded), far beyond what the endpoint accepts.
|
|
6
|
+
*/
|
|
7
|
+
const PRECISION = 1e5;
|
|
8
|
+
export function decodePolyline(encoded) {
|
|
9
|
+
const points = [];
|
|
10
|
+
let index = 0;
|
|
11
|
+
let lat = 0;
|
|
12
|
+
let lng = 0;
|
|
13
|
+
while (index < encoded.length) {
|
|
14
|
+
lat += readVarint();
|
|
15
|
+
lng += readVarint();
|
|
16
|
+
points.push({ latitude: lat / PRECISION, longitude: lng / PRECISION });
|
|
17
|
+
}
|
|
18
|
+
return points;
|
|
19
|
+
function readVarint() {
|
|
20
|
+
let result = 0;
|
|
21
|
+
let shift = 0;
|
|
22
|
+
let byte;
|
|
23
|
+
do {
|
|
24
|
+
byte = encoded.charCodeAt(index++) - 63;
|
|
25
|
+
result |= (byte & 0x1f) << shift;
|
|
26
|
+
shift += 5;
|
|
27
|
+
} while (byte >= 0x20);
|
|
28
|
+
return result & 1 ? ~(result >> 1) : result >> 1;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function encodePolyline(points) {
|
|
32
|
+
let output = '';
|
|
33
|
+
let prevLat = 0;
|
|
34
|
+
let prevLng = 0;
|
|
35
|
+
for (const point of points) {
|
|
36
|
+
const lat = Math.round(point.latitude * PRECISION);
|
|
37
|
+
const lng = Math.round(point.longitude * PRECISION);
|
|
38
|
+
output += encodeValue(lat - prevLat) + encodeValue(lng - prevLng);
|
|
39
|
+
prevLat = lat;
|
|
40
|
+
prevLng = lng;
|
|
41
|
+
}
|
|
42
|
+
return output;
|
|
43
|
+
function encodeValue(value) {
|
|
44
|
+
let v = value < 0 ? ~(value << 1) : value << 1;
|
|
45
|
+
let chunk = '';
|
|
46
|
+
while (v >= 0x20) {
|
|
47
|
+
chunk += String.fromCharCode((0x20 | (v & 0x1f)) + 63);
|
|
48
|
+
v >>= 5;
|
|
49
|
+
}
|
|
50
|
+
return chunk + String.fromCharCode(v + 63);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** Douglas-Peucker simplification with the tolerance in approximate meters. */
|
|
54
|
+
export function simplifyPoints(points, toleranceMeters) {
|
|
55
|
+
if (points.length <= 2 || toleranceMeters <= 0)
|
|
56
|
+
return points;
|
|
57
|
+
const keep = new Array(points.length).fill(false);
|
|
58
|
+
keep[0] = keep[points.length - 1] = true;
|
|
59
|
+
const stack = [[0, points.length - 1]];
|
|
60
|
+
while (stack.length > 0) {
|
|
61
|
+
const [start, end] = stack.pop();
|
|
62
|
+
let maxDistance = 0;
|
|
63
|
+
let maxIndex = -1;
|
|
64
|
+
for (let i = start + 1; i < end; i++) {
|
|
65
|
+
const distance = perpendicularDistanceMeters(points[i], points[start], points[end]);
|
|
66
|
+
if (distance > maxDistance) {
|
|
67
|
+
maxDistance = distance;
|
|
68
|
+
maxIndex = i;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (maxIndex !== -1 && maxDistance > toleranceMeters) {
|
|
72
|
+
keep[maxIndex] = true;
|
|
73
|
+
stack.push([start, maxIndex], [maxIndex, end]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return points.filter((_, i) => keep[i]);
|
|
77
|
+
}
|
|
78
|
+
/** Planar approximation (equirectangular) — accurate enough for display-level simplification. */
|
|
79
|
+
function perpendicularDistanceMeters(p, a, b) {
|
|
80
|
+
const metersPerDegLat = 111_320;
|
|
81
|
+
const cosLat = Math.cos((a.latitude * Math.PI) / 180);
|
|
82
|
+
const toXY = (c) => ({
|
|
83
|
+
x: c.longitude * metersPerDegLat * cosLat,
|
|
84
|
+
y: c.latitude * metersPerDegLat,
|
|
85
|
+
});
|
|
86
|
+
const P = toXY(p);
|
|
87
|
+
const A = toXY(a);
|
|
88
|
+
const B = toXY(b);
|
|
89
|
+
const dx = B.x - A.x;
|
|
90
|
+
const dy = B.y - A.y;
|
|
91
|
+
const lengthSquared = dx * dx + dy * dy;
|
|
92
|
+
if (lengthSquared === 0)
|
|
93
|
+
return Math.hypot(P.x - A.x, P.y - A.y);
|
|
94
|
+
const t = Math.max(0, Math.min(1, ((P.x - A.x) * dx + (P.y - A.y) * dy) / lengthSquared));
|
|
95
|
+
return Math.hypot(P.x - (A.x + t * dx), P.y - (A.y + t * dy));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Return an encoded polyline whose length is at most `maxEncodedChars`, simplifying
|
|
99
|
+
* with progressively coarser tolerances until it fits (or only endpoints remain).
|
|
100
|
+
*/
|
|
101
|
+
export function fitPolylineToBudget(points, maxEncodedChars) {
|
|
102
|
+
let current = points;
|
|
103
|
+
let encoded = encodePolyline(current);
|
|
104
|
+
let tolerance = 5; // meters
|
|
105
|
+
while (encoded.length > maxEncodedChars && current.length > 2) {
|
|
106
|
+
current = simplifyPoints(points, tolerance);
|
|
107
|
+
encoded = encodePolyline(current);
|
|
108
|
+
tolerance *= 2;
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
encoded,
|
|
112
|
+
originalPointCount: points.length,
|
|
113
|
+
pointCount: current.length,
|
|
114
|
+
simplified: current.length < points.length,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=polyline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyline.js","sourceRoot":"","sources":["../../../src/tools/maps/polyline.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,MAAM,MAAM,GAAiB,EAAE,CAAC;IAChC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,OAAO,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QAC9B,GAAG,IAAI,UAAU,EAAE,CAAC;QACpB,GAAG,IAAI,UAAU,EAAE,CAAC;QACpB,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,GAAG,GAAG,SAAS,EAAE,SAAS,EAAE,GAAG,GAAG,SAAS,EAAE,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,MAAM,CAAC;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QACL,OAAO;QACP,kBAAkB,EAAE,MAAM,CAAC,MAAM;QACjC,UAAU,EAAE,OAAO,CAAC,MAAM;QAC1B,UAAU,EAAE,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM;KAC3C,CAAC;AACJ,CAAC"}
|
|
@@ -2,6 +2,7 @@ import * as z from 'zod/v4';
|
|
|
2
2
|
import { CoordinateSchema } from '../shared/geo.js';
|
|
3
3
|
import { READ_ONLY, ToolInputError } from '../types.js';
|
|
4
4
|
import { fetchImageResult, markerParam, StaticImageShape, staticImagePath, } from './static-shared.js';
|
|
5
|
+
import { decodePolyline, fitPolylineToBudget } from './polyline.js';
|
|
5
6
|
const Schema = z.object({
|
|
6
7
|
encoded_polyline: z
|
|
7
8
|
.string()
|
|
@@ -36,6 +37,10 @@ const Schema = z.object({
|
|
|
36
37
|
.describe('Margin around the route as a fraction of image size (default 0.1)'),
|
|
37
38
|
...StaticImageShape,
|
|
38
39
|
});
|
|
40
|
+
/** Stay comfortably under the API's documented 8192-byte URL limit. */
|
|
41
|
+
const URL_BYTE_BUDGET = 8000;
|
|
42
|
+
/** Progressively tighter encoded-polyline budgets tried when the URL is too long. */
|
|
43
|
+
const ENCODED_CHAR_BUDGETS = [4000, 3000, 2000, 1200, 600, 200];
|
|
39
44
|
export const staticRouteMap = {
|
|
40
45
|
name: 'static_route_map',
|
|
41
46
|
title: 'Static Route Map',
|
|
@@ -56,18 +61,41 @@ export const staticRouteMap = {
|
|
|
56
61
|
`width:${args.stroke_width ?? 4}`,
|
|
57
62
|
'fill:none',
|
|
58
63
|
];
|
|
59
|
-
|
|
60
|
-
const
|
|
64
|
+
const markers = args.markers?.length ? markerParam(args.markers, 'lat-first') : undefined;
|
|
65
|
+
const padding = args.padding !== undefined ? String(args.padding) : undefined;
|
|
66
|
+
const path = staticImagePath('auto', args);
|
|
67
|
+
const buildQuery = (geometry) => ({
|
|
68
|
+
path: `${styleSegments.join('|')}|${geometry}`,
|
|
69
|
+
markers,
|
|
70
|
+
padding,
|
|
71
|
+
});
|
|
72
|
+
// First try the geometry exactly as given. Path coordinates are `lat,lng`;
|
|
73
|
+
// `enc:` consumes the rest of the parameter value.
|
|
74
|
+
let geometry = args.encoded_polyline
|
|
61
75
|
? `enc:${args.encoded_polyline}`
|
|
62
76
|
: args.route_points.map((p) => `${p.latitude},${p.longitude}`).join('|');
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
77
|
+
let simplificationNote = '';
|
|
78
|
+
// The Static Images API is GET-only with an 8192-byte URL limit; a long route's
|
|
79
|
+
// full-resolution polyline blows past it (~50 kB for 600 km). When that happens,
|
|
80
|
+
// simplify the *display* geometry progressively until the URL fits — the route's
|
|
81
|
+
// distance/duration come from the directions tool and are unaffected.
|
|
82
|
+
if (nb.buildUrl(path, buildQuery(geometry)).length > URL_BYTE_BUDGET) {
|
|
83
|
+
const points = args.encoded_polyline
|
|
84
|
+
? decodePolyline(args.encoded_polyline)
|
|
85
|
+
: args.route_points;
|
|
86
|
+
for (const budget of ENCODED_CHAR_BUDGETS) {
|
|
87
|
+
const fitted = fitPolylineToBudget(points, budget);
|
|
88
|
+
geometry = `enc:${fitted.encoded}`;
|
|
89
|
+
if (nb.buildUrl(path, buildQuery(geometry)).length <= URL_BYTE_BUDGET) {
|
|
90
|
+
simplificationNote =
|
|
91
|
+
` Display geometry simplified from ${fitted.originalPointCount} to ` +
|
|
92
|
+
`${fitted.pointCount} points to fit the map URL limit; distances are unaffected.`;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return fetchImageResult(nb, path, buildQuery(geometry), `Route map rendered${args.markers?.length ? ` with ${args.markers.length} marker(s)` : ''}.` +
|
|
98
|
+
simplificationNote, args);
|
|
71
99
|
},
|
|
72
100
|
};
|
|
73
101
|
//# sourceMappingURL=static-route-map.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"static-route-map.js","sourceRoot":"","sources":["../../../src/tools/maps/static-route-map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAe,MAAM,aAAa,CAAC;AACrE,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,eAAe,GAChB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"static-route-map.js","sourceRoot":"","sources":["../../../src/tools/maps/static-route-map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAe,MAAM,aAAa,CAAC;AACrE,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpE,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACtB,gBAAgB,EAAE,CAAC;SAChB,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CACP,0FAA0F;QACxF,gDAAgD,CACnD;IACH,YAAY,EAAE,CAAC;SACZ,KAAK,CAAC,gBAAgB,CAAC;SACvB,GAAG,CAAC,CAAC,CAAC;SACN,QAAQ,EAAE;SACV,QAAQ,CAAC,8EAA8E,CAAC;IAC3F,OAAO,EAAE,CAAC;SACP,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;SAChE,QAAQ,EAAE;SACV,QAAQ,CAAC,iEAAiE,CAAC;IA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,CAAC,IAAI,CAAC,YAAa,CAAC;YACvB,KAAK,MAAM,MAAM,IAAI,oBAAoB,EAAE,CAAC;gBAC1C,MAAM,MAAM,GAAG,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBACnD,QAAQ,GAAG,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC;gBACnC,IAAI,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,IAAI,eAAe,EAAE,CAAC;oBACtE,kBAAkB;wBAChB,qCAAqC,MAAM,CAAC,kBAAkB,MAAM;4BACpE,GAAG,MAAM,CAAC,UAAU,6DAA6D,CAAC;oBACpF,MAAM;gBACR,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,gBAAgB,CACrB,EAAE,EACF,IAAI,EACJ,UAAU,CAAC,QAAQ,CAAC,EACpB,qBAAqB,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,MAAM,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG;YAC1F,kBAAkB,EACpB,IAAI,CACL,CAAC;IACJ,CAAC;CACF,CAAC"}
|
package/dist/tools/types.d.ts
CHANGED
|
@@ -36,4 +36,11 @@ export interface NbTool<Schema extends z.ZodType = z.ZodType> {
|
|
|
36
36
|
export declare const READ_ONLY: ToolAnnotations;
|
|
37
37
|
export declare class ToolInputError extends Error {
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Build a tool result whose text block carries BOTH a human-readable summary and the
|
|
41
|
+
* complete response as JSON. The MCP spec recommends mirroring structured content
|
|
42
|
+
* into the text block: some hosts (e.g. Claude Desktop) surface only the text to the
|
|
43
|
+
* model, so a summary-only text block made fields such as `access` invisible even
|
|
44
|
+
* though they were present in `structuredContent`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function textResult(summary: string, structuredContent?: Record<string, unknown>): ToolResult;
|
package/dist/tools/types.js
CHANGED
|
@@ -7,7 +7,17 @@ export const READ_ONLY = {
|
|
|
7
7
|
};
|
|
8
8
|
export class ToolInputError extends Error {
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Build a tool result whose text block carries BOTH a human-readable summary and the
|
|
12
|
+
* complete response as JSON. The MCP spec recommends mirroring structured content
|
|
13
|
+
* into the text block: some hosts (e.g. Claude Desktop) surface only the text to the
|
|
14
|
+
* model, so a summary-only text block made fields such as `access` invisible even
|
|
15
|
+
* though they were present in `structuredContent`.
|
|
16
|
+
*/
|
|
17
|
+
export function textResult(summary, structuredContent) {
|
|
18
|
+
const text = structuredContent === undefined
|
|
19
|
+
? summary
|
|
20
|
+
: `${summary}\n\nFull response (JSON):\n${JSON.stringify(structuredContent)}`;
|
|
11
21
|
return { content: [{ type: 'text', text }], structuredContent };
|
|
12
22
|
}
|
|
13
23
|
//# sourceMappingURL=types.js.map
|
package/dist/tools/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAiCA,kFAAkF;AAClF,MAAM,CAAC,MAAM,SAAS,GAAoB;IACxC,YAAY,EAAE,IAAI;IAClB,eAAe,EAAE,KAAK;IACtB,cAAc,EAAE,IAAI;IACpB,aAAa,EAAE,IAAI;CACpB,CAAC;AAEF,MAAM,OAAO,cAAe,SAAQ,KAAK;CAAG;AAE5C,MAAM,UAAU,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAiCA,kFAAkF;AAClF,MAAM,CAAC,MAAM,SAAS,GAAoB;IACxC,YAAY,EAAE,IAAI;IAClB,eAAe,EAAE,KAAK;IACtB,cAAc,EAAE,IAAI;IACpB,aAAa,EAAE,IAAI;CACpB,CAAC;AAEF,MAAM,OAAO,cAAe,SAAQ,KAAK;CAAG;AAE5C;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CACxB,OAAe,EACf,iBAA2C;IAE3C,MAAM,IAAI,GACR,iBAAiB,KAAK,SAAS;QAC7B,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,GAAG,OAAO,8BAA8B,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,EAAE,CAAC;IAClF,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC;AAClE,CAAC"}
|
package/package.json
CHANGED