Skip to content

Conversation

@tsck
Copy link
Collaborator

@tsck tsck commented Dec 18, 2025

Proposed changes

  • Add useHostCommunication hook for sending UI actions to the parent window via postMessage
  • Updates useRenderData hook to capture origin, to be used in comms once available for better security
  • Adds tests for both data hooks

@tsck tsck force-pushed the feat/mcp-ui-data-hook branch from 3561828 to eb4138d Compare December 18, 2025 19:40
@coveralls
Copy link
Collaborator

coveralls commented Dec 18, 2025

Pull Request Test Coverage Report for Build 20349165663

Details

  • 101 of 103 (98.06%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.3%) to 79.757%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/ui/hooks/index.ts 0 1 0.0%
src/ui/hooks/useRenderData.ts 2 3 66.67%
Totals Coverage Status
Change from base Build 20344372865: 0.3%
Covered Lines: 6849
Relevant Lines: 8506

💛 - Coveralls

@tsck tsck changed the title feat(mcp-ui): add hook for posting data back to MCP clien feat(mcp-ui): add hook for posting data back to MCP client Dec 18, 2025
@tsck tsck marked this pull request as ready for review December 18, 2025 19:55
@tsck tsck requested a review from a team as a code owner December 18, 2025 19:55
Copilot AI review requested due to automatic review settings December 18, 2025 19:55
Copy link
Contributor

Copilot AI left a 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 useHostCommunication hook 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 useRenderData hook 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";

Comment on lines +33 to +34
describe("useHostCommunication", () => {
let postMessageMock: Mock;
Copy link

Copilot AI Dec 18, 2025

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants