refactor: render union/intersect/difference tools as live Mapbox GL JS maps#195
Closed
mattpodwysocki wants to merge 6 commits into
Closed
refactor: render union/intersect/difference tools as live Mapbox GL JS maps#195mattpodwysocki wants to merge 6 commits into
mattpodwysocki wants to merge 6 commits into
Conversation
Seventh-through-ninth tools in the MCP Apps series. Three Turf.js-based offline polygon-operation tools share a single PolygonOpsAppUIResource that renders the input polygons in muted blue and overlays the result in an operation-keyed color (green=union, purple=intersect, orange=difference). When intersect/difference produces no overlapping geometry, the tool still succeeds (isError=false) and the UI shows just the inputs with a "no overlapping geometry" summary. Also adds the three new offline tools to the annotations test's offlineTools list so the open-world-hint test continues to pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Final resource in the series. Same pattern: send size-changed first, delay 60ms, then map.resize() + fitBounds so polygons fill the viewport instead of appearing as tiny dots. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 27, 2026
Closed
…p-tools # Conflicts: # CHANGELOG.md # src/tools/index.ts # src/tools/toolRegistry.ts
Polygon ops now render as a live Mapbox GL JS map directly from the existing offline tools instead of via parallel `*_app_tool` siblings. - Extract the rendering pipeline into a shared `renderPolygonOpsAppHtml` module so the MCP Apps resource and the inline MCP-UI rawHtml block use one template and one source of truth. - Slim down `PolygonOpsAppUIResource` to a thin wrapper around the shared render function (only the empty/postMessage variant). - Add `_meta.ui.resourceUri` to `union_tool`, `intersect_tool`, and `difference_tool` pointing to the shared `ui://mapbox/polygon-ops-app/ index.html` resource (MCP Apps path). - Gate inline MCP-UI rawHtml on `isMcpUiEnabled()` and bake both inputs and the result polygon into the iframe with operation-keyed result coloring (green=union, purple=intersect, orange=difference). - Polygon ops are fully offline, so the inline path uses `MAPBOX_PUBLIC_TOKEN` from env directly rather than the tokens API. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This was referenced Jun 3, 2026
Contributor
Author
|
Superseded by #199. This PR (and the rest of the per-tool app stack: #190, #191, #192, #193, #194, #195) declares its own
#199 funnels all rendering through one terminal |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fold MCP App rendering directly into the existing offline polygon-op tools
instead of shipping parallel
*_app_toolsiblings. Same pattern appliedacross #189, #190, #191, #192, #193, #194 — and now the polygon ops finish the stack.
union_tool,intersect_tool, anddifference_toolnow:_meta.ui.resourceUripointing to a single shared MCP Appresource (
ui://mapbox/polygon-ops-app/index.html). One iframe templateserves all three operations — coloring is keyed on
payload.operation.rawHtmlcreateUIResourceblock whenisMcpUiEnabled()is true, with both inputs and the result baked in.renderPolygonOpsAppHtmlmodule so the MCP Apps and MCP-UIpaths render identical output.
Color key
Input polygons render in muted blue underneath; a small bottom-left
legend swaps in the right swatch and label per operation.
Token resolution
Polygon ops are fully offline (no API calls, no per-request access token
plumbed through). The inline UI path therefore uses
MAPBOX_PUBLIC_TOKENfrom env directly rather than calling the Tokens API — if it isn't set,
no inline UI is emitted but the tool still returns its text + structured
content. The MCP Apps resource path goes through the normal
resolveMapboxPublicTokenchain via its constructor-injectedhttpRequest.Graceful no-result
When
intersectordifferenceproduces no overlapping geometry, thetool still returns
isError: false— the agent gets a clear textsummary and the UI shows just the input polygons, making the empty case
visually obvious.
Test plan
BaseTool— no constructorsignature changes, no new dependency injection
PolygonOpsAppUIResourceslimmed to ~70 lines using shared render🤖 Generated with Claude Code