@mapbox/mcp-server 0.12.6 → 0.12.7-dev
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/commonjs/resources/ui-apps/DirectionsAppUIResource.d.ts +3 -2
- package/dist/commonjs/resources/ui-apps/DirectionsAppUIResource.d.ts.map +1 -1
- package/dist/commonjs/resources/ui-apps/DirectionsAppUIResource.js +5 -3
- package/dist/commonjs/resources/ui-apps/DirectionsAppUIResource.js.map +1 -1
- package/dist/commonjs/resources/ui-apps/directionsAppHtml.d.ts +20 -8
- package/dist/commonjs/resources/ui-apps/directionsAppHtml.d.ts.map +1 -1
- package/dist/commonjs/resources/ui-apps/directionsAppHtml.js +136 -17
- package/dist/commonjs/resources/ui-apps/directionsAppHtml.js.map +1 -1
- package/dist/commonjs/tools/directions-tool/DirectionsTool.d.ts.map +1 -1
- package/dist/commonjs/tools/directions-tool/DirectionsTool.input.schema.d.ts.map +1 -1
- package/dist/commonjs/tools/directions-tool/DirectionsTool.input.schema.js +6 -2
- package/dist/commonjs/tools/directions-tool/DirectionsTool.input.schema.js.map +1 -1
- package/dist/commonjs/tools/directions-tool/DirectionsTool.js +52 -109
- package/dist/commonjs/tools/directions-tool/DirectionsTool.js.map +1 -1
- package/dist/commonjs/tools/directions-tool/buildDirectionsRequestUrl.d.ts +29 -0
- package/dist/commonjs/tools/directions-tool/buildDirectionsRequestUrl.d.ts.map +1 -0
- package/dist/commonjs/tools/directions-tool/buildDirectionsRequestUrl.js +63 -0
- package/dist/commonjs/tools/directions-tool/buildDirectionsRequestUrl.js.map +1 -0
- package/dist/commonjs/version.json +3 -3
- package/dist/esm/resources/ui-apps/DirectionsAppUIResource.d.ts +3 -2
- package/dist/esm/resources/ui-apps/DirectionsAppUIResource.d.ts.map +1 -1
- package/dist/esm/resources/ui-apps/DirectionsAppUIResource.js +5 -3
- package/dist/esm/resources/ui-apps/DirectionsAppUIResource.js.map +1 -1
- package/dist/esm/resources/ui-apps/directionsAppHtml.d.ts +20 -8
- package/dist/esm/resources/ui-apps/directionsAppHtml.d.ts.map +1 -1
- package/dist/esm/resources/ui-apps/directionsAppHtml.js +136 -17
- package/dist/esm/resources/ui-apps/directionsAppHtml.js.map +1 -1
- package/dist/esm/tools/directions-tool/DirectionsTool.d.ts.map +1 -1
- package/dist/esm/tools/directions-tool/DirectionsTool.input.schema.d.ts.map +1 -1
- package/dist/esm/tools/directions-tool/DirectionsTool.input.schema.js +6 -2
- package/dist/esm/tools/directions-tool/DirectionsTool.input.schema.js.map +1 -1
- package/dist/esm/tools/directions-tool/DirectionsTool.js +52 -109
- package/dist/esm/tools/directions-tool/DirectionsTool.js.map +1 -1
- package/dist/esm/tools/directions-tool/buildDirectionsRequestUrl.d.ts +29 -0
- package/dist/esm/tools/directions-tool/buildDirectionsRequestUrl.d.ts.map +1 -0
- package/dist/esm/tools/directions-tool/buildDirectionsRequestUrl.js +60 -0
- package/dist/esm/tools/directions-tool/buildDirectionsRequestUrl.js.map +1 -0
- package/dist/esm/version.json +3 -3
- package/package.json +1 -1
|
@@ -9,8 +9,9 @@ import type { HttpRequest } from '../../utils/types.js';
|
|
|
9
9
|
* event and renders the route from `structuredContent.routes[0]`.
|
|
10
10
|
*
|
|
11
11
|
* The legacy MCP-UI pathway (inline `rawHtml` on the tool result) uses the
|
|
12
|
-
* same HTML template via `renderDirectionsAppHtml` with
|
|
13
|
-
* tool-execute time
|
|
12
|
+
* same HTML template via `renderDirectionsAppHtml` with the call's input
|
|
13
|
+
* params baked in at tool-execute time; the iframe self-fetches the route
|
|
14
|
+
* from the Directions API using those params.
|
|
14
15
|
*/
|
|
15
16
|
export declare class DirectionsAppUIResource extends BaseResource {
|
|
16
17
|
readonly name = "Directions App UI";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DirectionsAppUIResource.d.ts","sourceRoot":"","sources":["../../../../src/resources/ui-apps/DirectionsAppUIResource.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACd,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAIxD
|
|
1
|
+
{"version":3,"file":"DirectionsAppUIResource.d.ts","sourceRoot":"","sources":["../../../../src/resources/ui-apps/DirectionsAppUIResource.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACd,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAIxD;;;;;;;;;;GAUG;AACH,qBAAa,uBAAwB,SAAQ,YAAY;IACvD,QAAQ,CAAC,IAAI,uBAAuB;IACpC,QAAQ,CAAC,GAAG,2CAA2C;IACvD,QAAQ,CAAC,WAAW,2FACsE;IAC1F,QAAQ,CAAC,QAAQ,+BAAsB;IAEvC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAe;gBAE/B,MAAM,EAAE;QAClB,WAAW,EAAE,WAAW,CAAC;QACzB,WAAW,CAAC,EAAE,MAAM,MAAM,CAAC;KAC5B;IAQK,IAAI,CACR,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,mBAAmB,CAAC,aAAa,EAAE,kBAAkB,CAAC,GAC7D,OAAO,CAAC,kBAAkB,CAAC;CAwC/B"}
|
|
@@ -14,8 +14,9 @@ const directionsAppHtml_js_1 = require("./directionsAppHtml.js");
|
|
|
14
14
|
* event and renders the route from `structuredContent.routes[0]`.
|
|
15
15
|
*
|
|
16
16
|
* The legacy MCP-UI pathway (inline `rawHtml` on the tool result) uses the
|
|
17
|
-
* same HTML template via `renderDirectionsAppHtml` with
|
|
18
|
-
* tool-execute time
|
|
17
|
+
* same HTML template via `renderDirectionsAppHtml` with the call's input
|
|
18
|
+
* params baked in at tool-execute time; the iframe self-fetches the route
|
|
19
|
+
* from the Directions API using those params.
|
|
19
20
|
*/
|
|
20
21
|
class DirectionsAppUIResource extends BaseResource_js_1.BaseResource {
|
|
21
22
|
name = 'Directions App UI';
|
|
@@ -41,7 +42,8 @@ class DirectionsAppUIResource extends BaseResource_js_1.BaseResource {
|
|
|
41
42
|
httpRequest: this.httpRequest
|
|
42
43
|
});
|
|
43
44
|
const html = (0, directionsAppHtml_js_1.renderDirectionsAppHtml)({
|
|
44
|
-
publicToken: publicToken ?? ''
|
|
45
|
+
publicToken: publicToken ?? '',
|
|
46
|
+
apiEndpoint: this.apiEndpoint()
|
|
45
47
|
});
|
|
46
48
|
return {
|
|
47
49
|
contents: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DirectionsAppUIResource.js","sourceRoot":"","sources":["../../../../src/resources/ui-apps/DirectionsAppUIResource.ts"],"names":[],"mappings":";AAAA,6BAA6B;AAC7B,kCAAkC;;;AAQlC,kEAA2E;AAC3E,wDAAkD;AAElD,2EAA4E;AAC5E,iEAAiE;AAEjE
|
|
1
|
+
{"version":3,"file":"DirectionsAppUIResource.js","sourceRoot":"","sources":["../../../../src/resources/ui-apps/DirectionsAppUIResource.ts"],"names":[],"mappings":";AAAA,6BAA6B;AAC7B,kCAAkC;;;AAQlC,kEAA2E;AAC3E,wDAAkD;AAElD,2EAA4E;AAC5E,iEAAiE;AAEjE;;;;;;;;;;GAUG;AACH,MAAa,uBAAwB,SAAQ,8BAAY;IAC9C,IAAI,GAAG,mBAAmB,CAAC;IAC3B,GAAG,GAAG,uCAAuC,CAAC;IAC9C,WAAW,GAClB,uFAAuF,CAAC;IACjF,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C"}
|
|
@@ -11,22 +11,34 @@
|
|
|
11
11
|
*
|
|
12
12
|
* 2. **Legacy MCP-UI spec** — `directions_tool` inlines a `rawHtml`
|
|
13
13
|
* UIResource into its content array (gated by `isMcpUiEnabled()`). The
|
|
14
|
-
* HTML is generated at tool-execute time with the
|
|
15
|
-
* baked in as an `initialData` script block
|
|
16
|
-
*
|
|
14
|
+
* HTML is generated at tool-execute time with the call's input params
|
|
15
|
+
* baked in as an `initialData` script block; the iframe uses those params
|
|
16
|
+
* to self-fetch the route from the Directions API, so it never depends on
|
|
17
|
+
* the host delivering the tool result.
|
|
17
18
|
*
|
|
18
19
|
* One source of truth for the rendering logic; two slim entry conditions.
|
|
19
20
|
*/
|
|
20
21
|
export declare const MAPBOX_GL_VERSION = "3.12.0";
|
|
22
|
+
export interface DirectionsAppInitialParams {
|
|
23
|
+
coordinates: {
|
|
24
|
+
longitude: number;
|
|
25
|
+
latitude: number;
|
|
26
|
+
}[];
|
|
27
|
+
routing_profile?: string;
|
|
28
|
+
alternatives?: boolean;
|
|
29
|
+
exclude?: string;
|
|
30
|
+
depart_at?: string;
|
|
31
|
+
arrive_by?: string;
|
|
32
|
+
max_height?: number;
|
|
33
|
+
max_width?: number;
|
|
34
|
+
max_weight?: number;
|
|
35
|
+
}
|
|
21
36
|
export interface DirectionsAppInitialData {
|
|
22
|
-
|
|
23
|
-
type: string;
|
|
24
|
-
coordinates: [number, number][];
|
|
25
|
-
};
|
|
26
|
-
summary?: string;
|
|
37
|
+
params: DirectionsAppInitialParams;
|
|
27
38
|
}
|
|
28
39
|
export declare function renderDirectionsAppHtml(params: {
|
|
29
40
|
publicToken: string;
|
|
41
|
+
apiEndpoint: string;
|
|
30
42
|
glVersion?: string;
|
|
31
43
|
initialData?: DirectionsAppInitialData;
|
|
32
44
|
}): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"directionsAppHtml.d.ts","sourceRoot":"","sources":["../../../../src/resources/ui-apps/directionsAppHtml.ts"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"directionsAppHtml.d.ts","sourceRoot":"","sources":["../../../../src/resources/ui-apps/directionsAppHtml.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,eAAO,MAAM,iBAAiB,WAAW,CAAC;AAE1C,MAAM,WAAW,0BAA0B;IACzC,WAAW,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACvD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,0BAA0B,CAAC;CACpC;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE;IAC9C,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,wBAAwB,CAAC;CACxC,GAAG,MAAM,CAsiBT"}
|
|
@@ -17,15 +17,16 @@ exports.renderDirectionsAppHtml = renderDirectionsAppHtml;
|
|
|
17
17
|
*
|
|
18
18
|
* 2. **Legacy MCP-UI spec** — `directions_tool` inlines a `rawHtml`
|
|
19
19
|
* UIResource into its content array (gated by `isMcpUiEnabled()`). The
|
|
20
|
-
* HTML is generated at tool-execute time with the
|
|
21
|
-
* baked in as an `initialData` script block
|
|
22
|
-
*
|
|
20
|
+
* HTML is generated at tool-execute time with the call's input params
|
|
21
|
+
* baked in as an `initialData` script block; the iframe uses those params
|
|
22
|
+
* to self-fetch the route from the Directions API, so it never depends on
|
|
23
|
+
* the host delivering the tool result.
|
|
23
24
|
*
|
|
24
25
|
* One source of truth for the rendering logic; two slim entry conditions.
|
|
25
26
|
*/
|
|
26
27
|
exports.MAPBOX_GL_VERSION = '3.12.0';
|
|
27
28
|
function renderDirectionsAppHtml(params) {
|
|
28
|
-
const { publicToken, initialData } = params;
|
|
29
|
+
const { publicToken, apiEndpoint, initialData } = params;
|
|
29
30
|
const glVersion = params.glVersion ?? exports.MAPBOX_GL_VERSION;
|
|
30
31
|
const initialDataScript = initialData
|
|
31
32
|
? `<script id="initial-data" type="application/json">${escapeForScript(JSON.stringify(initialData))}</script>`
|
|
@@ -72,6 +73,7 @@ ${initialDataScript}
|
|
|
72
73
|
<script>
|
|
73
74
|
(function() {
|
|
74
75
|
var TOKEN = ${JSON.stringify(publicToken)};
|
|
76
|
+
var API_ENDPOINT = ${JSON.stringify(apiEndpoint)};
|
|
75
77
|
|
|
76
78
|
var loadingEl = document.getElementById('loading');
|
|
77
79
|
var errorEl = document.getElementById('error');
|
|
@@ -84,6 +86,117 @@ ${initialDataScript}
|
|
|
84
86
|
// Track markers across re-renders so we can remove them before drawing the
|
|
85
87
|
// next route — otherwise a second tool-result delivery stacks pins.
|
|
86
88
|
var routeMarkers = [];
|
|
89
|
+
var routeRendered = false;
|
|
90
|
+
var selfFetchStarted = false;
|
|
91
|
+
|
|
92
|
+
// -------------------------------------------------------------------------
|
|
93
|
+
// Self-fetch: build a Directions API request directly from the tool call's
|
|
94
|
+
// input parameters and fetch the route ourselves, so this map never
|
|
95
|
+
// depends on the tool response carrying geometries="geojson".
|
|
96
|
+
//
|
|
97
|
+
// Mirrors src/tools/directions-tool/buildDirectionsRequestUrl.ts — kept in
|
|
98
|
+
// sync by the parity test in
|
|
99
|
+
// test/tools/directions-tool/directionsUrlParity.test.ts. Always forces
|
|
100
|
+
// geometries=geojson regardless of what the tool call itself requested.
|
|
101
|
+
// -------------------------------------------------------------------------
|
|
102
|
+
function formatIsoDateTimeClient(dateTime) {
|
|
103
|
+
var noTzWithSeconds = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$/;
|
|
104
|
+
if (noTzWithSeconds.test(dateTime)) {
|
|
105
|
+
return dateTime.substring(0, dateTime.lastIndexOf(':'));
|
|
106
|
+
}
|
|
107
|
+
return dateTime;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function encodeExcludeClient(value) {
|
|
111
|
+
return value
|
|
112
|
+
.replace(/,/g, '%2C')
|
|
113
|
+
.replace(/\\(/g, '%28')
|
|
114
|
+
.replace(/\\)/g, '%29')
|
|
115
|
+
.replace(/ /g, '%20');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function buildDirectionsApiUrl(params, publicToken, apiEndpoint) {
|
|
119
|
+
var coords = params.coordinates
|
|
120
|
+
.map(function(c) { return c.longitude + ',' + c.latitude; })
|
|
121
|
+
.join(';');
|
|
122
|
+
var encodedCoords = encodeURIComponent(coords);
|
|
123
|
+
var profile = params.routing_profile || 'mapbox/driving-traffic';
|
|
124
|
+
|
|
125
|
+
var qp = new URLSearchParams();
|
|
126
|
+
qp.append('access_token', publicToken);
|
|
127
|
+
qp.append('geometries', 'geojson');
|
|
128
|
+
qp.append('alternatives', params.alternatives ? 'true' : 'false');
|
|
129
|
+
qp.append(
|
|
130
|
+
'annotations',
|
|
131
|
+
profile === 'mapbox/driving-traffic'
|
|
132
|
+
? 'distance,congestion,speed'
|
|
133
|
+
: 'distance,speed'
|
|
134
|
+
);
|
|
135
|
+
qp.append('overview', 'full');
|
|
136
|
+
|
|
137
|
+
if (params.depart_at) {
|
|
138
|
+
qp.append('depart_at', formatIsoDateTimeClient(params.depart_at));
|
|
139
|
+
} else if (params.arrive_by) {
|
|
140
|
+
qp.append('arrive_by', formatIsoDateTimeClient(params.arrive_by));
|
|
141
|
+
}
|
|
142
|
+
if (params.max_height !== undefined && params.max_height !== null) {
|
|
143
|
+
qp.append('max_height', String(params.max_height));
|
|
144
|
+
}
|
|
145
|
+
if (params.max_width !== undefined && params.max_width !== null) {
|
|
146
|
+
qp.append('max_width', String(params.max_width));
|
|
147
|
+
}
|
|
148
|
+
if (params.max_weight !== undefined && params.max_weight !== null) {
|
|
149
|
+
qp.append('max_weight', String(params.max_weight));
|
|
150
|
+
}
|
|
151
|
+
qp.append('steps', 'true');
|
|
152
|
+
|
|
153
|
+
var queryString = qp.toString();
|
|
154
|
+
if (params.exclude) {
|
|
155
|
+
queryString += '&exclude=' + encodeExcludeClient(params.exclude);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return apiEndpoint + 'directions/v5/' + profile + '/' + encodedCoords + '?' + queryString;
|
|
159
|
+
}
|
|
160
|
+
// Exposed so the parity test (Node vm sandbox) can call this in isolation.
|
|
161
|
+
window.__buildDirectionsApiUrl = buildDirectionsApiUrl;
|
|
162
|
+
|
|
163
|
+
function fetchRouteFromDirectionsApi(params) {
|
|
164
|
+
if (!TOKEN || !params || !params.coordinates) return;
|
|
165
|
+
selfFetchStarted = true;
|
|
166
|
+
var url = buildDirectionsApiUrl(params, TOKEN, API_ENDPOINT);
|
|
167
|
+
fetch(url)
|
|
168
|
+
.then(function(res) {
|
|
169
|
+
if (!res.ok) {
|
|
170
|
+
return res
|
|
171
|
+
.json()
|
|
172
|
+
.catch(function() { return null; })
|
|
173
|
+
.then(function(body) {
|
|
174
|
+
var msg =
|
|
175
|
+
body && body.message
|
|
176
|
+
? body.message
|
|
177
|
+
: 'Directions API error (' + res.status + ')';
|
|
178
|
+
throw new Error(msg);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return res.json();
|
|
182
|
+
})
|
|
183
|
+
.then(function(data) {
|
|
184
|
+
if (routeRendered) return;
|
|
185
|
+
var route = data && data.routes && data.routes[0];
|
|
186
|
+
var picked = route ? pickRouteGeometry(route) : null;
|
|
187
|
+
if (picked) {
|
|
188
|
+
renderRoute(picked);
|
|
189
|
+
} else {
|
|
190
|
+
showError('Directions API returned no route.');
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
.catch(function(err) {
|
|
194
|
+
if (routeRendered) return;
|
|
195
|
+
showError(
|
|
196
|
+
'Could not fetch route: ' + (err && err.message ? err.message : err)
|
|
197
|
+
);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
87
200
|
|
|
88
201
|
// -------------------------------------------------------------------------
|
|
89
202
|
// MCP App postMessage protocol (skipped silently in MCP-UI rawHtml mode)
|
|
@@ -117,6 +230,9 @@ ${initialDataScript}
|
|
|
117
230
|
else handlers.resolve(message.result);
|
|
118
231
|
return;
|
|
119
232
|
}
|
|
233
|
+
if (message.method === 'ui/notifications/tool-input' && message.params) {
|
|
234
|
+
fetchRouteFromDirectionsApi(message.params.arguments);
|
|
235
|
+
}
|
|
120
236
|
if (message.method === 'ui/notifications/tool-result' && message.params) {
|
|
121
237
|
handleToolResult(message.params);
|
|
122
238
|
}
|
|
@@ -180,29 +296,22 @@ ${initialDataScript}
|
|
|
180
296
|
initMap();
|
|
181
297
|
|
|
182
298
|
// -------------------------------------------------------------------------
|
|
183
|
-
// Initial data path (MCP-UI rawHtml):
|
|
184
|
-
//
|
|
299
|
+
// Initial data path (MCP-UI rawHtml): the tool call's input params were
|
|
300
|
+
// baked in server-side. Self-fetch the route from the Directions API
|
|
301
|
+
// rather than relying on baked-in geometry from the tool response.
|
|
185
302
|
// -------------------------------------------------------------------------
|
|
186
303
|
function consumeInitialData() {
|
|
187
304
|
var el = document.getElementById('initial-data');
|
|
188
305
|
if (!el || !el.textContent) return;
|
|
189
306
|
try {
|
|
190
307
|
var data = JSON.parse(el.textContent);
|
|
191
|
-
if (!data || !data.
|
|
192
|
-
|
|
193
|
-
var route = pickRouteGeometry({
|
|
194
|
-
geometry: data.geometry,
|
|
195
|
-
distance: data.distance,
|
|
196
|
-
duration: data.duration
|
|
197
|
-
});
|
|
198
|
-
if (route) {
|
|
199
|
-
if (data.summary) route.summary = data.summary;
|
|
200
|
-
drawRoute(route);
|
|
201
|
-
}
|
|
308
|
+
if (!data || !data.params) return;
|
|
309
|
+
fetchRouteFromDirectionsApi(data.params);
|
|
202
310
|
} catch (_) { /* ignore */ }
|
|
203
311
|
}
|
|
204
312
|
|
|
205
313
|
function handleToolResult(result) {
|
|
314
|
+
if (routeRendered) return;
|
|
206
315
|
var route = extractRoute(result);
|
|
207
316
|
if (route) {
|
|
208
317
|
renderRoute(route);
|
|
@@ -218,6 +327,7 @@ ${initialDataScript}
|
|
|
218
327
|
loadingEl.textContent = 'Fetching full route…';
|
|
219
328
|
sendRequest('resources/read', { uri: tempUri }).then(
|
|
220
329
|
function(rr) {
|
|
330
|
+
if (routeRendered) return;
|
|
221
331
|
var fetched = readResourceJson(rr);
|
|
222
332
|
var fetchedRoute = fetched ? extractRoute({ structuredContent: fetched }) : null;
|
|
223
333
|
if (fetchedRoute) {
|
|
@@ -227,16 +337,23 @@ ${initialDataScript}
|
|
|
227
337
|
}
|
|
228
338
|
},
|
|
229
339
|
function(err) {
|
|
340
|
+
if (routeRendered) return;
|
|
230
341
|
showError('Could not read temporary resource: ' + (err && err.message ? err.message : err));
|
|
231
342
|
}
|
|
232
343
|
);
|
|
233
344
|
return;
|
|
234
345
|
}
|
|
235
346
|
|
|
347
|
+
// Self-fetch (kicked off by the earlier tool-input notification) is
|
|
348
|
+
// either still in flight or already reported its own error via its
|
|
349
|
+
// .catch() handler — either way, this isn't the right error to show.
|
|
350
|
+
if (selfFetchStarted) return;
|
|
351
|
+
|
|
236
352
|
showError('Could not find route data in tool result.');
|
|
237
353
|
}
|
|
238
354
|
|
|
239
355
|
function renderRoute(route) {
|
|
356
|
+
routeRendered = true;
|
|
240
357
|
if (route.summary) {
|
|
241
358
|
summaryEl.textContent = route.summary;
|
|
242
359
|
summaryEl.style.display = 'block';
|
|
@@ -392,6 +509,8 @@ ${initialDataScript}
|
|
|
392
509
|
return;
|
|
393
510
|
}
|
|
394
511
|
|
|
512
|
+
errorEl.style.display = 'none';
|
|
513
|
+
|
|
395
514
|
if (route.summary && summaryEl.style.display === 'none') {
|
|
396
515
|
summaryEl.textContent = route.summary;
|
|
397
516
|
summaryEl.style.display = 'block';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"directionsAppHtml.js","sourceRoot":"","sources":["../../../../src/resources/ui-apps/directionsAppHtml.ts"],"names":[],"mappings":";AAAA,6BAA6B;AAC7B,kCAAkC;;;
|
|
1
|
+
{"version":3,"file":"directionsAppHtml.js","sourceRoot":"","sources":["../../../../src/resources/ui-apps/directionsAppHtml.ts"],"names":[],"mappings":";AAAA,6BAA6B;AAC7B,kCAAkC;;;AAyClC,0DA2iBC;AAllBD;;;;;;;;;;;;;;;;;;;GAmBG;AAEU,QAAA,iBAAiB,GAAG,QAAQ,CAAC;AAkB1C,SAAgB,uBAAuB,CAAC,MAKvC;IACC,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IACzD,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,yBAAiB,CAAC;IAExD,MAAM,iBAAiB,GAAG,WAAW;QACnC,CAAC,CAAC,qDAAqD,eAAe,CAClE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAC5B,WAAW;QACd,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO;;;;;;mDAM0C,SAAS;oDACR,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8B3D,iBAAiB;;;;gBAIH,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC;uBACpB,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAif1C,CAAC;AACT,CAAC;AAED,SAAS,eAAe,CAAC,CAAS;IAChC,qEAAqE;IACrE,OAAO,CAAC,CAAC,OAAO,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DirectionsTool.d.ts","sourceRoot":"","sources":["../../../../src/tools/directions-tool/DirectionsTool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DirectionsTool.d.ts","sourceRoot":"","sources":["../../../../src/tools/directions-tool/DirectionsTool.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAGzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EACL,wBAAwB,EAEzB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AASzD,qBAAa,cAAe,SAAQ,kBAAkB,CACpD,OAAO,qBAAqB,EAC5B,OAAO,wBAAwB,CAChC;IACC,IAAI,SAAqB;IACzB,WAAW,SAM+B;IAC1C,WAAW;;;;;;MAMT;IACF,QAAQ,CAAC,IAAI;;;;;;;;MAQX;gBAEU,MAAM,EAAE;QAAE,WAAW,EAAE,WAAW,CAAA;KAAE;cAOhC,OAAO,CACrB,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,EAC5C,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,cAAc,CAAC;CAyQ3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DirectionsTool.input.schema.d.ts","sourceRoot":"","sources":["../../../../src/tools/directions-tool/DirectionsTool.input.schema.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAoHxB,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"DirectionsTool.input.schema.d.ts","sourceRoot":"","sources":["../../../../src/tools/directions-tool/DirectionsTool.input.schema.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAoHxB,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;iBAsKhC,CAAC"}
|
|
@@ -122,8 +122,12 @@ exports.DirectionsInputSchema = zod_1.z.object({
|
|
|
122
122
|
.optional()
|
|
123
123
|
.default('none')
|
|
124
124
|
.describe('The format of the returned geometry. Options: \n' +
|
|
125
|
-
'- none (default): no geometry object is returned
|
|
126
|
-
'
|
|
125
|
+
'- none (default): no geometry object is returned in the response. The map preview UI ' +
|
|
126
|
+
'still renders the route on its own; use this whenever you do not need the raw ' +
|
|
127
|
+
'coordinates yourself.\n' +
|
|
128
|
+
'- geojson: as GeoJSON LineString (might be very long as there could be a lot of ' +
|
|
129
|
+
'points). Only needed when you (the caller) require the coordinates directly — not ' +
|
|
130
|
+
'required for the map preview to work.'),
|
|
127
131
|
max_height: zod_1.z
|
|
128
132
|
.number()
|
|
129
133
|
.min(0, 'Vehicle height must be between 0 and 10 meters')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DirectionsTool.input.schema.js","sourceRoot":"","sources":["../../../../src/tools/directions-tool/DirectionsTool.input.schema.ts"],"names":[],"mappings":";AAAA,6BAA6B;AAC7B,kCAAkC;;;AAElC,6BAAwB;AACxB,uDAA0E;AAE1E;;;GAGG;AACH,MAAM,mBAAmB,GAAG,CAC1B,GAAuB,EACvB,GAAoB,EACd,EAAE;IACR,IAAI,CAAC,GAAG;QAAE,OAAO,CAAC,6BAA6B;IAE/C,sEAAsE;IACtE,qDAAqD;IACrD,4DAA4D;IAC5D,gDAAgD;IAChD,wFAAwF;IACxF,MAAM,cAAc,GAClB,wKAAwK,CAAC;IAE3K,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9B,GAAG,CAAC,QAAQ,CAAC;YACX,IAAI,EAAE,OAAC,CAAC,YAAY,CAAC,MAAM;YAC3B,OAAO,EACL,gJAAgJ;YAClJ,IAAI,EAAE,EAAE;SACT,CAAC,CAAC;QACH,OAAO,CAAC,+CAA+C;IACzD,CAAC;IAED,oDAAoD;IACpD,IAAI,CAAC;QACH,mCAAmC;QACnC,IAAI,kBAA4B,CAAC;QAEjC,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACtB,iCAAiC;YACjC,kBAAkB,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACrE,CAAC;aAAM,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC;YACtD,sDAAsD;YACtD,qCAAqC;YACrC,MAAM,sBAAsB,GAAG,IAAI,CAAC,GAAG,CACrC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,EACpB,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CACrB,CAAC;YACF,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,OAAO,EAAE,uCAAuC,KAAK,EAAE;YACvD,IAAI,EAAE,EAAE;SACT,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC;AAEW,QAAA,qBAAqB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC5C,WAAW,EAAE,OAAC;SACX,KAAK,CAAC,4BAAgB,CAAC;SACvB,GAAG,CAAC,CAAC,EAAE,6CAA6C,CAAC;SACrD,GAAG,CAAC,EAAE,EAAE,0CAA0C,CAAC;SACnD,QAAQ,CACP,wFAAwF;QACtF,yEAAyE;QACzE,2CAA2C,CAC9C;IACH,eAAe,EAAE,yBAAa;SAC3B,QAAQ,EAAE;SACV,OAAO,CAAC,wBAAwB,CAAC;SACjC,QAAQ,CACP,+DAA+D;QAC7D,kFAAkF;QAClF,yDAAyD;QACzD,uCAAuC;QACvC,2BAA2B,CAC9B;IACH,UAAU,EAAE,OAAC;SACV,IAAI,CAAC,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;SACzB,QAAQ,EAAE;SACV,OAAO,CAAC,MAAM,CAAC;SACf,QAAQ,CACP,kDAAkD;QAChD,
|
|
1
|
+
{"version":3,"file":"DirectionsTool.input.schema.js","sourceRoot":"","sources":["../../../../src/tools/directions-tool/DirectionsTool.input.schema.ts"],"names":[],"mappings":";AAAA,6BAA6B;AAC7B,kCAAkC;;;AAElC,6BAAwB;AACxB,uDAA0E;AAE1E;;;GAGG;AACH,MAAM,mBAAmB,GAAG,CAC1B,GAAuB,EACvB,GAAoB,EACd,EAAE;IACR,IAAI,CAAC,GAAG;QAAE,OAAO,CAAC,6BAA6B;IAE/C,sEAAsE;IACtE,qDAAqD;IACrD,4DAA4D;IAC5D,gDAAgD;IAChD,wFAAwF;IACxF,MAAM,cAAc,GAClB,wKAAwK,CAAC;IAE3K,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9B,GAAG,CAAC,QAAQ,CAAC;YACX,IAAI,EAAE,OAAC,CAAC,YAAY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AAG,GAAG,EAAE,CAAC;oBAC1C,GAAG,CAAC,QAAQ,CAAC;wBACX,IAAI,EAAE,OAAC,CAAC,YAAY,CAAC,MAAM;wBAC3B,OAAO,EAAE,4CAA4C,MAAM,0CAA0C;wBACrG,IAAI,EAAE,EAAE;qBACT,CAAC,CAAC;gBACL,CAAC;gBAED,8BAA8B;gBAC9B,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;gBAC3B,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,EAAE,IAAI,GAAG,GAAG,EAAE,EAAE,CAAC;oBACxC,GAAG,CAAC,QAAQ,CAAC;wBACX,IAAI,EAAE,OAAC,CAAC,YAAY,CAAC,MAAM;wBAC3B,OAAO,EAAE,2CAA2C,MAAM,wCAAwC;wBAClG,IAAI,EAAE,EAAE;qBACT,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YACD,uCAAuC;iBAClC,IACH,CAAC;gBACC,MAAM;gBACN,iBAAiB;gBACjB,UAAU;gBACV,OAAO;gBACP,SAAS;gBACT,QAAQ;gBACR,gBAAgB;gBAChB,cAAc;aACf,CAAC,QAAQ,CAAC,IAAI,CAAC,EAChB,CAAC;gBACD,GAAG,CAAC,QAAQ,CAAC;oBACX,IAAI,EAAE,OAAC,CAAC,YAAY,CAAC,MAAM;oBAC3B,OAAO,EAAE,4BAA4B,IAAI,uHAAuH;oBAChK,IAAI,EAAE,EAAE;iBACT,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC,CAAC;SACD,QAAQ,CACP,2EAA2E;QACzE,8DAA8D;QAC9D,sBAAsB;QACtB,2CAA2C;QAC3C,gIAAgI;QAChI,8HAA8H;QAC9H,kHAAkH,CACrH;CACJ,CAAC,CAAC"}
|
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
// Licensed under the MIT License.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.DirectionsTool = void 0;
|
|
6
|
-
const node_url_1 = require("node:url");
|
|
7
6
|
const node_crypto_1 = require("node:crypto");
|
|
8
7
|
const server_1 = require("@mcp-ui/server");
|
|
9
8
|
const MapboxApiBasedTool_js_1 = require("../MapboxApiBasedTool.js");
|
|
10
9
|
const cleanResponseData_js_1 = require("./cleanResponseData.js");
|
|
11
|
-
const
|
|
10
|
+
const buildDirectionsRequestUrl_js_1 = require("./buildDirectionsRequestUrl.js");
|
|
12
11
|
const DirectionsTool_input_schema_js_1 = require("./DirectionsTool.input.schema.js");
|
|
13
12
|
const DirectionsTool_output_schema_js_1 = require("./DirectionsTool.output.schema.js");
|
|
14
13
|
const temporaryResourceManager_js_1 = require("../../utils/temporaryResourceManager.js");
|
|
@@ -20,9 +19,11 @@ const directionsAppHtml_js_1 = require("../../resources/ui-apps/directionsAppHtm
|
|
|
20
19
|
class DirectionsTool extends MapboxApiBasedTool_js_1.MapboxApiBasedTool {
|
|
21
20
|
name = 'directions_tool';
|
|
22
21
|
description = 'Fetches directions from Mapbox API based on provided coordinates and direction method. ' +
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
'
|
|
22
|
+
'This tool always attaches an interactive map preview UI to its result; the map fetches and ' +
|
|
23
|
+
'renders its own route independently, so it works regardless of the geometries parameter. ' +
|
|
24
|
+
'Use geometries="none" (default) for compact text/data responses (distance, duration, ' +
|
|
25
|
+
'turn-by-turn instructions). Use geometries="geojson" only when you need the raw route ' +
|
|
26
|
+
'coordinates in the response yourself.';
|
|
26
27
|
annotations = {
|
|
27
28
|
title: 'Directions Tool',
|
|
28
29
|
readOnlyHint: true,
|
|
@@ -160,63 +161,11 @@ class DirectionsTool extends MapboxApiBasedTool_js_1.MapboxApiBasedTool {
|
|
|
160
161
|
isError: true
|
|
161
162
|
};
|
|
162
163
|
}
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const queryParams = new node_url_1.URLSearchParams();
|
|
169
|
-
queryParams.append('access_token', accessToken);
|
|
170
|
-
// Only add geometries parameter if not 'none'
|
|
171
|
-
if (input.geometries !== 'none') {
|
|
172
|
-
queryParams.append('geometries', input.geometries);
|
|
173
|
-
}
|
|
174
|
-
queryParams.append('alternatives', input.alternatives.toString());
|
|
175
|
-
// Add annotations parameter
|
|
176
|
-
if (input.routing_profile === 'mapbox/driving-traffic') {
|
|
177
|
-
// congestion is available only when driving
|
|
178
|
-
queryParams.append('annotations', 'distance,congestion,speed');
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
queryParams.append('annotations', 'distance,speed');
|
|
182
|
-
}
|
|
183
|
-
// For annotations to work, overview must be set to 'full'
|
|
184
|
-
queryParams.append('overview', 'full');
|
|
185
|
-
// Add depart_at or arrive_by parameter if provided, converting format if needed
|
|
186
|
-
if (input.depart_at) {
|
|
187
|
-
const formattedDateTime = (0, dateUtils_js_1.formatIsoDateTime)(input.depart_at);
|
|
188
|
-
queryParams.append('depart_at', formattedDateTime);
|
|
189
|
-
}
|
|
190
|
-
else if (input.arrive_by) {
|
|
191
|
-
const formattedDateTime = (0, dateUtils_js_1.formatIsoDateTime)(input.arrive_by);
|
|
192
|
-
queryParams.append('arrive_by', formattedDateTime);
|
|
193
|
-
}
|
|
194
|
-
// Add vehicle dimension parameters if provided
|
|
195
|
-
if (input.max_height !== undefined) {
|
|
196
|
-
queryParams.append('max_height', input.max_height.toString());
|
|
197
|
-
}
|
|
198
|
-
if (input.max_width !== undefined) {
|
|
199
|
-
queryParams.append('max_width', input.max_width.toString());
|
|
200
|
-
}
|
|
201
|
-
if (input.max_weight !== undefined) {
|
|
202
|
-
queryParams.append('max_weight', input.max_weight.toString());
|
|
203
|
-
}
|
|
204
|
-
queryParams.append('steps', 'true');
|
|
205
|
-
let queryString = queryParams.toString();
|
|
206
|
-
// Add exclude parameter if provided (ensuring proper encoding of special characters)
|
|
207
|
-
if (input.exclude) {
|
|
208
|
-
// Custom encoding function to match the expected format in tests
|
|
209
|
-
const customEncodeForExclude = (str) => {
|
|
210
|
-
return str
|
|
211
|
-
.replace(/,/g, '%2C') // Encode comma
|
|
212
|
-
.replace(/\(/g, '%28') // Encode opening parenthesis
|
|
213
|
-
.replace(/\)/g, '%29') // Encode closing parenthesis
|
|
214
|
-
.replace(/ /g, '%20'); // Encode space as %20, not +
|
|
215
|
-
};
|
|
216
|
-
const excludeEncoded = customEncodeForExclude(input.exclude);
|
|
217
|
-
queryString += `&exclude=${excludeEncoded}`;
|
|
218
|
-
}
|
|
219
|
-
const url = `${MapboxApiBasedTool_js_1.MapboxApiBasedTool.mapboxApiEndpoint}directions/v5/${input.routing_profile}/${encodedCoords}?${queryString}`;
|
|
164
|
+
const url = (0, buildDirectionsRequestUrl_js_1.buildDirectionsRequestUrl)({
|
|
165
|
+
input,
|
|
166
|
+
accessToken,
|
|
167
|
+
apiEndpoint: MapboxApiBasedTool_js_1.MapboxApiBasedTool.mapboxApiEndpoint
|
|
168
|
+
});
|
|
220
169
|
const response = await this.httpRequest(url);
|
|
221
170
|
if (!response.ok) {
|
|
222
171
|
const errorMessage = await this.getErrorMessage(response);
|
|
@@ -242,6 +191,20 @@ class DirectionsTool extends MapboxApiBasedTool_js_1.MapboxApiBasedTool {
|
|
|
242
191
|
this.log('warning', `DirectionsTool: Response validation failed: ${error}`);
|
|
243
192
|
validatedData = cleanedData;
|
|
244
193
|
}
|
|
194
|
+
let uiResourceBlock;
|
|
195
|
+
if ((0, toolConfig_js_1.isMcpUiEnabled)()) {
|
|
196
|
+
const inlineHtml = await tryRenderInlineUiHtml(input, accessToken, this.httpRequest);
|
|
197
|
+
if (inlineHtml) {
|
|
198
|
+
uiResourceBlock = (0, server_1.createUIResource)({
|
|
199
|
+
uri: `ui://mapbox/directions/${(0, node_crypto_1.randomUUID)()}`,
|
|
200
|
+
content: { type: 'rawHtml', htmlString: inlineHtml },
|
|
201
|
+
encoding: 'text',
|
|
202
|
+
uiMetadata: {
|
|
203
|
+
'preferred-frame-size': ['100%', '500px']
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
245
208
|
// Check response size and conditionally create temporary resource
|
|
246
209
|
const RESPONSE_SIZE_THRESHOLD = 50 * 1024; // 50KB
|
|
247
210
|
const responseText = JSON.stringify(validatedData, null, 2);
|
|
@@ -290,8 +253,13 @@ ${responseSize > RESPONSE_SIZE_THRESHOLD ? `\n⚠️ Full response (${Math.round
|
|
|
290
253
|
legs: undefined
|
|
291
254
|
}))
|
|
292
255
|
};
|
|
256
|
+
const content = [
|
|
257
|
+
{ type: 'text', text: summaryText }
|
|
258
|
+
];
|
|
259
|
+
if (uiResourceBlock)
|
|
260
|
+
content.push(uiResourceBlock);
|
|
293
261
|
return {
|
|
294
|
-
content
|
|
262
|
+
content,
|
|
295
263
|
structuredContent: summaryStructuredContent,
|
|
296
264
|
isError: false
|
|
297
265
|
};
|
|
@@ -300,22 +268,8 @@ ${responseSize > RESPONSE_SIZE_THRESHOLD ? `\n⚠️ Full response (${Math.round
|
|
|
300
268
|
const content = [
|
|
301
269
|
{ type: 'text', text: responseText }
|
|
302
270
|
];
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
// carries a renderable GeoJSON geometry — i.e. geometries=geojson.
|
|
306
|
-
if ((0, toolConfig_js_1.isMcpUiEnabled)()) {
|
|
307
|
-
const inlineHtml = await tryRenderInlineUiHtml(validatedData, accessToken, this.httpRequest);
|
|
308
|
-
if (inlineHtml) {
|
|
309
|
-
content.push((0, server_1.createUIResource)({
|
|
310
|
-
uri: `ui://mapbox/directions/${(0, node_crypto_1.randomUUID)()}`,
|
|
311
|
-
content: { type: 'rawHtml', htmlString: inlineHtml },
|
|
312
|
-
encoding: 'text',
|
|
313
|
-
uiMetadata: {
|
|
314
|
-
'preferred-frame-size': ['100%', '500px']
|
|
315
|
-
}
|
|
316
|
-
}));
|
|
317
|
-
}
|
|
318
|
-
}
|
|
271
|
+
if (uiResourceBlock)
|
|
272
|
+
content.push(uiResourceBlock);
|
|
319
273
|
return {
|
|
320
274
|
content,
|
|
321
275
|
structuredContent: validatedData,
|
|
@@ -325,25 +279,14 @@ ${responseSize > RESPONSE_SIZE_THRESHOLD ? `\n⚠️ Full response (${Math.round
|
|
|
325
279
|
}
|
|
326
280
|
exports.DirectionsTool = DirectionsTool;
|
|
327
281
|
/**
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
282
|
+
* Render the same DirectionsAppHtml as the MCP Apps resource, but with the
|
|
283
|
+
* call's input parameters baked in so the iframe can self-fetch the route
|
|
284
|
+
* from the Directions API — MCP-UI clients don't fetch external resources,
|
|
285
|
+
* so this is what makes the map work for them too. Attached unconditionally;
|
|
286
|
+
* the only failure mode is no public token being resolvable, in which case
|
|
287
|
+
* the caller falls back to text-only output.
|
|
333
288
|
*/
|
|
334
|
-
async function tryRenderInlineUiHtml(
|
|
335
|
-
const route = data.routes?.[0];
|
|
336
|
-
const geometry = route?.geometry;
|
|
337
|
-
// Accept either a GeoJSON LineString object or a polyline string — the
|
|
338
|
-
// iframe normalizes both shapes before rendering.
|
|
339
|
-
const hasGeojson = geometry &&
|
|
340
|
-
typeof geometry === 'object' &&
|
|
341
|
-
geometry.type === 'LineString' &&
|
|
342
|
-
Array.isArray(geometry.coordinates);
|
|
343
|
-
const hasPolyline = typeof geometry === 'string' && geometry.length > 0;
|
|
344
|
-
if (!hasGeojson && !hasPolyline) {
|
|
345
|
-
return undefined;
|
|
346
|
-
}
|
|
289
|
+
async function tryRenderInlineUiHtml(input, accessToken, httpRequest) {
|
|
347
290
|
const publicToken = await (0, mapboxPublicToken_js_1.resolveMapboxPublicToken)({
|
|
348
291
|
accessToken,
|
|
349
292
|
apiEndpoint: MapboxApiBasedTool_js_1.MapboxApiBasedTool.mapboxApiEndpoint,
|
|
@@ -351,21 +294,21 @@ async function tryRenderInlineUiHtml(data, accessToken, httpRequest) {
|
|
|
351
294
|
});
|
|
352
295
|
if (!publicToken)
|
|
353
296
|
return undefined;
|
|
354
|
-
const summaryParts = [];
|
|
355
|
-
if (typeof route?.distance === 'number') {
|
|
356
|
-
summaryParts.push(`${(route.distance / 1609.34).toFixed(1)} mi`);
|
|
357
|
-
}
|
|
358
|
-
if (typeof route?.duration === 'number') {
|
|
359
|
-
summaryParts.push(`${Math.round(route.duration / 60)} min`);
|
|
360
|
-
}
|
|
361
|
-
const summary = summaryParts.length
|
|
362
|
-
? `Route: ${summaryParts.join(', ')}`
|
|
363
|
-
: 'Route';
|
|
364
297
|
return (0, directionsAppHtml_js_1.renderDirectionsAppHtml)({
|
|
365
298
|
publicToken,
|
|
299
|
+
apiEndpoint: MapboxApiBasedTool_js_1.MapboxApiBasedTool.mapboxApiEndpoint,
|
|
366
300
|
initialData: {
|
|
367
|
-
|
|
368
|
-
|
|
301
|
+
params: {
|
|
302
|
+
coordinates: input.coordinates,
|
|
303
|
+
routing_profile: input.routing_profile,
|
|
304
|
+
alternatives: input.alternatives,
|
|
305
|
+
exclude: input.exclude,
|
|
306
|
+
depart_at: input.depart_at,
|
|
307
|
+
arrive_by: input.arrive_by,
|
|
308
|
+
max_height: input.max_height,
|
|
309
|
+
max_width: input.max_width,
|
|
310
|
+
max_weight: input.max_weight
|
|
311
|
+
}
|
|
369
312
|
}
|
|
370
313
|
});
|
|
371
314
|
}
|