-
Notifications
You must be signed in to change notification settings - Fork 40
feat: directions_tool renders as a live GL JS map (MCP Apps + MCP-UI) #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
1e72d21
Add server-level icons with light and dark theme support
mattpodwysocki c205821
Update @modelcontextprotocol/sdk to 1.25.2
mattpodwysocki ca757a9
Merge branch 'main' of github.com:mapbox/mcp-server
mattpodwysocki dc3e501
Merge branch 'main' of github.com:mapbox/mcp-server
mattpodwysocki 8f325eb
Merge branch 'main' of github.com:mapbox/mcp-server
mattpodwysocki 5c160cc
Merge branch 'main' of github.com:mapbox/mcp-server
mattpodwysocki 04a1930
Merge branch 'main' of github.com:mapbox/mcp-server
mattpodwysocki 79ef57e
Merge branch 'main' of github.com:mapbox/mcp-server
mattpodwysocki 9bde92c
Merge branch 'main' of github.com:mapbox/mcp-server
mattpodwysocki 08f374d
Merge branch 'main' of github.com:mapbox/mcp-server
mattpodwysocki efd96fa
Merge branch 'main' of github.com:mapbox/mcp-server
mattpodwysocki 2aba9b7
Merge branch 'main' of github.com:mapbox/mcp-server
mattpodwysocki cd1d797
Merge branch 'main' of github.com:mapbox/mcp-server
mattpodwysocki a9c8261
Merge branch 'main' of github.com:mapbox/mcp-server
mattpodwysocki 188f51a
chore: add CVE-2026-4926 entry to CHANGELOG
mattpodwysocki a9653e2
Merge branch 'main' of github.com:mapbox/mcp-server
mattpodwysocki 814f635
Merge branch 'main' of github.com:mapbox/mcp-server
mattpodwysocki 42acbeb
Merge branch 'main' of github.com:mapbox/mcp-server
mattpodwysocki 80a5750
Merge branch 'main' of github.com:mapbox/mcp-server
mattpodwysocki 8490ef9
Merge branch 'main' of github.com:mapbox/mcp-server
mattpodwysocki c554cc9
feat: add directions_app_tool — interactive GLJS map as MCP App
mattpodwysocki a137f78
feat: directions_app_tool resolves public token via Tokens API
mattpodwysocki ae44881
refactor: directions_app_tool uses MCP Apps resource pattern
mattpodwysocki fb12b89
fix(directions_app): tighten camera padding so the route fills the vi…
mattpodwysocki f653375
fix(directions_app): defer fitBounds until after iframe resize
mattpodwysocki 277d267
refactor: fold MCP App support into directions_tool (drops directions…
mattpodwysocki 9fc4467
fix(directions_app): decode polyline geometries in the iframe
mattpodwysocki b8fffa2
fix(directions_app): read temp resource when geometry is offloaded
mattpodwysocki e8602f3
fix(directions_app): review feedback from PR #189
mattpodwysocki 8681d0b
Merge branch 'main' into feat/directions-app-tool
mattpodwysocki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| // Copyright (c) Mapbox, Inc. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js'; | ||
| import type { | ||
| ReadResourceResult, | ||
| ServerNotification, | ||
| ServerRequest | ||
| } from '@modelcontextprotocol/sdk/types.js'; | ||
| import { RESOURCE_MIME_TYPE } from '@modelcontextprotocol/ext-apps/server'; | ||
| import { BaseResource } from '../BaseResource.js'; | ||
| import type { HttpRequest } from '../../utils/types.js'; | ||
| import { resolveMapboxPublicToken } from '../../utils/mapboxPublicToken.js'; | ||
| import { renderDirectionsAppHtml } from './directionsAppHtml.js'; | ||
|
|
||
| /** | ||
| * MCP Apps resource for `directions_tool` — serves the HTML at | ||
| * `ui://mapbox/directions-app/index.html`. The iframe waits for the host to | ||
| * deliver the tool result via the `ui/notifications/tool-result` postMessage | ||
| * event and renders the route from `structuredContent.routes[0]`. | ||
| * | ||
| * The legacy MCP-UI pathway (inline `rawHtml` on the tool result) uses the | ||
| * same HTML template via `renderDirectionsAppHtml` with geometry baked in at | ||
| * tool-execute time. | ||
| */ | ||
| export class DirectionsAppUIResource extends BaseResource { | ||
| readonly name = 'Directions App UI'; | ||
| readonly uri = 'ui://mapbox/directions-app/index.html'; | ||
| readonly description = | ||
| 'Interactive UI for visualizing a Mapbox directions route with Mapbox GL JS (MCP Apps)'; | ||
| readonly mimeType = RESOURCE_MIME_TYPE; | ||
|
|
||
| private readonly httpRequest: HttpRequest; | ||
| private readonly apiEndpoint: () => string; | ||
|
|
||
| constructor(params: { | ||
| httpRequest: HttpRequest; | ||
| apiEndpoint?: () => string; | ||
| }) { | ||
| super(); | ||
| this.httpRequest = params.httpRequest; | ||
| this.apiEndpoint = | ||
| params.apiEndpoint ?? | ||
| (() => process.env.MAPBOX_API_ENDPOINT || 'https://api.mapbox.com/'); | ||
| } | ||
|
|
||
| async read( | ||
| _uri: string, | ||
| extra?: RequestHandlerExtra<ServerRequest, ServerNotification> | ||
| ): Promise<ReadResourceResult> { | ||
| const accessToken = | ||
| (extra?.authInfo?.token as string | undefined) || | ||
| process.env.MAPBOX_ACCESS_TOKEN || | ||
| ''; | ||
|
|
||
| const publicToken = await resolveMapboxPublicToken({ | ||
| accessToken, | ||
| apiEndpoint: this.apiEndpoint(), | ||
| httpRequest: this.httpRequest | ||
| }); | ||
|
|
||
| const html = renderDirectionsAppHtml({ | ||
| publicToken: publicToken ?? '' | ||
| }); | ||
|
|
||
| return { | ||
| contents: [ | ||
| { | ||
| uri: this.uri, | ||
| mimeType: RESOURCE_MIME_TYPE, | ||
| text: html, | ||
| _meta: { | ||
| ui: { | ||
| csp: { | ||
| connectDomains: [ | ||
| 'https://*.mapbox.com', | ||
| 'https://events.mapbox.com' | ||
| ], | ||
| resourceDomains: ['https://api.mapbox.com'], | ||
| workerDomains: ['blob:'] | ||
| }, | ||
| preferredSize: { width: 1000, height: 600 } | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-read the PR description and saw you reference
hosted-mcp-server'sGeojsonPreviewUIResourceas precedent — two questions:I checked
@modelcontextprotocol/ext-apps@1.7.2(latest) andworkerDomainsisn't in theMcpUiResourceCspinterface — onlyconnectDomains,resourceDomains,frameDomains,baseUriDomainsare declared. Is the Mapbox host honoringworkerDomainsas a private extension, or is it being recognized some other way?The 'verify rendered map loads in Claude Desktop' manual check in your test plan is still unchecked. The unit test (
DirectionsAppUIResource.test.ts:72) only asserts the field is present in the returned metadata, not that any host applies it. Since Mapbox GL JS won't initialize withoutworker-src blob:, would be good to confirm end-to-end before merge — if the spec doesn't haveworkerDomains, the map may be working in your test host for an unrelated reason (e.g. permissive default CSP).