Skip to content

Commit fd0b70a

Browse files
committed
fix(client): specify iframe
1 parent a829f5b commit fd0b70a

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

packages/client/src/components/HtmlResource.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,14 @@ export const HtmlResource: React.FC<RenderHtmlResourceProps> = ({
8888

8989
useEffect(() => {
9090
function handleMessage(event: MessageEvent) {
91-
if (event.data && typeof event.data === 'object' && event.data.tool) {
92-
onGenericMcpAction(event.data.tool, event.data.params || {})
93-
.catch(err => {
94-
console.error("Error from onGenericMcpAction in RenderHtmlResource:", err);
95-
});
91+
// Only process the message if it came from this specific iframe
92+
if (iframeRef.current && event.source === iframeRef.current.contentWindow) {
93+
if (event.data?.tool) {
94+
onGenericMcpAction(event.data.tool, event.data.params || {})
95+
.catch(err => {
96+
console.error("Error from onGenericMcpAction in RenderHtmlResource:", err);
97+
});
98+
}
9699
}
97100
}
98101
window.addEventListener('message', handleMessage);

0 commit comments

Comments
 (0)