-
Notifications
You must be signed in to change notification settings - Fork 176
feat(mcp-ui): add hook for posting data back to MCP client #812
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
base: main
Are you sure you want to change the base?
Conversation
3561828 to
eb4138d
Compare
Pull Request Test Coverage Report for Build 20349165663Details
💛 - Coveralls |
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.
Pull request overview
This PR introduces a new React hook for bidirectional communication between the MCP UI and its parent window, along with enhanced security through origin tracking.
- Adds
useHostCommunicationhook to enable the UI to send various types of messages (intents, notifications, prompts, tool calls, links, and size changes) back to the MCP client via postMessage - Updates
useRenderDatahook to capture and return the parent window's origin for secure communication - Includes comprehensive unit tests for both hooks
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/ui/hooks/useHostCommunication.ts |
New hook providing six communication methods (intent, notify, prompt, tool, link, reportSizeChange) with configurable target origin |
src/ui/hooks/useRenderData.ts |
Enhanced to capture parent window origin from the first valid message and return it alongside existing data |
src/ui/hooks/index.ts |
Exports the new useHostCommunication hook |
tests/unit/ui/useHostCommunication.test.ts |
Tests covering all communication methods, origin configuration, and edge cases |
tests/unit/ui/useRenderData.test.ts |
Tests verifying the new parentOrigin field behavior and integration with existing functionality |
Comments suppressed due to low confidence (1)
tests/unit/ui/useRenderData.test.ts:1
- Tests on lines 55-61, 63-67, and 79-85 contain redundant assertions about the initial state values. Consider consolidating these into a single comprehensive test case that checks both the object shape and initial values, reducing duplication while maintaining coverage.
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
| describe("useHostCommunication", () => { | ||
| let postMessageMock: Mock; |
Copilot
AI
Dec 18, 2025
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.
The type Mock is imported from vitest but the more specific type ReturnType<typeof vi.fn> is used in useRenderData.test.ts (line 34). For consistency across test files, consider using ReturnType<typeof vi.fn> here as well, which was the pattern established in the companion test file.
Proposed changes
useHostCommunicationhook for sending UI actions to the parent window via postMessageuseRenderDatahook to capture origin, to be used in comms once available for better security