feat: MCP get_current_selection tool#39
Merged
trmquang93 merged 1 commit intomainfrom Apr 17, 2026
Merged
Conversation
Adds a live bridge between the Drawd browser app and the MCP server so AI agents can read the user's current canvas selection without asking for IDs. - mcp-server: HTTP listener on localhost:3337 receives selection snapshots; `get_current_selection` tool enriches them from FlowState (screen name, hotspot count, connection endpoints, etc.) with a 60s staleness guard. - drawd app: `useSelectionReporter` debounces selection state changes (screens, stickies, connections, hotspots, groups, comments) and POSTs them to the bridge. Fails silently when the bridge isn't running.
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
Adds a new MCP tool,
get_current_selection, that returns the element(s) the user currently has selected in the running Drawd browser app — so an AI agent can act on "this screen" or "this hotspot" without the user pasting IDs.Selection is 100% runtime state and never persisted, so the tool relies on a tiny localhost HTTP bridge between the app and the MCP server.
How it works
mcp-server/src/selection-bridge.jsopens an HTTP listener onlocalhost:3337(override withDRAWD_SELECTION_PORT). It stores the latest selection snapshot in memory. If the port is busy it warns on stderr and the stdio server keeps running.mcp-server/src/tools/selection-tools.jsreads the snapshot, enriches each item fromFlowState:screen→ name, description, status, hotspotCountsticky→ content, color, x, yconnection→ fromScreenId, toScreenId, label, actionhotspot→ screenId, label, action, targetScreenIdscreenGroup→ name, screenIdscomment→ text, targetType, targetId, resolved{ selection: null, reason: \"no_recent_selection\", hint }.src/hooks/useSelectionReporter.jswatches every selection slot (canvasSelection,selectedScreen/Sticky/ScreenGroup/Connection/CommentId,selectedHotspots, andhotspotInteractionfor single-hotspot select), de-dups, debounces 150 ms, and POSTs to the bridge. Fetch errors are swallowed so the app is unaffected when the bridge isn't running.Test plan
npm run lintpassesnpm test— 648 tests passmcp-server/npm run buildsucceeds;node dist/index.jsboots withSelection bridge listening on http://localhost:3337npm run dev+ MCP server, select elements, callget_current_selectionfrom an MCP client