-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Upgrade to MCP-UI ~5.6.2 and handle internalized auto iframe resizing #3889
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,60 +1,61 @@ | ||
| import { UIResourceRenderer, UIActionResult } from '@mcp-ui/client'; | ||
| import { ResourceContent } from '../types/message'; | ||
| import { useState, useCallback } from 'react'; | ||
|
|
||
| // Extend UIActionResult to include size-change type | ||
| type ExtendedUIActionResult = | ||
| | UIActionResult | ||
| | { | ||
| type: 'size-change'; | ||
| payload: { | ||
| height: string; | ||
| }; | ||
| }; | ||
| import { useCallback } from 'react'; | ||
| import { toast } from 'react-toastify'; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. popin' some toast for user feedback, as we work to make the action handling real |
||
|
|
||
| interface MCPUIResourceRendererProps { | ||
| content: ResourceContent; | ||
| } | ||
|
|
||
| export default function MCPUIResourceRenderer({ content }: MCPUIResourceRendererProps) { | ||
| console.log('MCPUIResourceRenderer', content); | ||
| const [iframeHeight, setIframeHeight] = useState('200px'); | ||
|
|
||
| const handleUIAction = useCallback(async (result: ExtendedUIActionResult) => { | ||
| console.log('Handle action from MCP UI Action:', result); | ||
| const handleAction = (action: UIActionResult) => { | ||
| console.log( | ||
| `MCP UI message received (but only handled with a toast notification for now):`, | ||
| action | ||
| ); | ||
| toast.info(`${action.type} message sent from MCP UI, refer to console for more info`, { | ||
| data: action, | ||
| }); | ||
| return { status: 'handled', message: `${action.type} action logged` }; | ||
| }; | ||
|
|
||
| // Handle UI actions here | ||
| const handleUIAction = useCallback(async (result: UIActionResult) => { | ||
| switch (result.type) { | ||
| case 'intent': | ||
| case 'intent': { | ||
| // TODO: Implement intent handling | ||
| handleAction(result); | ||
| break; | ||
| } | ||
|
|
||
| case 'link': | ||
| case 'link': { | ||
| // TODO: Implement link handling | ||
| handleAction(result); | ||
| break; | ||
| } | ||
|
|
||
| case 'notify': | ||
| // TODO: Implement notification handling | ||
| case 'notify': { | ||
| // TODO: Implement notify handling | ||
| handleAction(result); | ||
| break; | ||
| } | ||
|
|
||
| case 'prompt': | ||
| case 'prompt': { | ||
| // TODO: Implement prompt handling | ||
| handleAction(result); | ||
| break; | ||
| } | ||
|
|
||
| case 'tool': | ||
| // TODO: Implement tool handling | ||
| case 'tool': { | ||
| // TODO: Implement tool call handling | ||
| handleAction(result); | ||
| break; | ||
| } | ||
|
|
||
| // Currently, `size-change` is non-standard | ||
| case 'size-change': { | ||
| // We expect the height to be a string with a unit | ||
| console.log('Setting iframe height to:', result.payload.height); | ||
| setIframeHeight(result.payload.height); | ||
| default: { | ||
| console.warn('unsupported message sent from MCP-UI:', result); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| return { status: 'handled' }; | ||
| }, []); | ||
|
|
||
| return ( | ||
|
|
@@ -64,7 +65,10 @@ export default function MCPUIResourceRenderer({ content }: MCPUIResourceRenderer | |
| resource={content.resource} | ||
| onUIAction={handleUIAction} | ||
| htmlProps={{ | ||
| style: { minHeight: iframeHeight }, | ||
| autoResizeIframe: { | ||
| height: true, | ||
| width: false, // set to false to allow for responsive design | ||
| }, | ||
|
Comment on lines
+68
to
+71
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mcp-ui add this based on our feedback |
||
| }} | ||
| /> | ||
| </div> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,24 +49,19 @@ export default function ToolCallWithResponse({ | |
| </div> | ||
| {/* MCP UI — Inline */} | ||
| {toolResponse?.toolResult?.value && | ||
| toolResponse.toolResult.value.map((content, index, results) => { | ||
| toolResponse.toolResult.value.map((content, index) => { | ||
| if (content.type === 'resource' && content.resource.uri?.startsWith('ui://')) { | ||
| if (index === results.length - 1) { | ||
| return ( | ||
| <> | ||
| <MCPUIResourceRenderer key={`${content.type}-${index}`} content={content} /> | ||
| {/* Append a disclaimer if this is the last item in the array */} | ||
| <div className="mt-3 p-4 py-3 border border-borderSubtle rounded-lg bg-background-muted flex items-center"> | ||
| <FlaskConical className="mr-2" size={20} /> | ||
| <div className="text-sm font-medium mono"> | ||
| MCP UI is experimental and may change at any time. | ||
| </div> | ||
| return ( | ||
| <div key={`${content.type}-${index}`} className="mt-3"> | ||
| <MCPUIResourceRenderer content={content} /> | ||
| <div className="mt-3 p-4 py-3 border border-borderSubtle rounded-lg bg-background-muted flex items-center"> | ||
| <FlaskConical className="mr-2" size={20} /> | ||
| <div className="text-sm font-medium mono"> | ||
| MCP UI is experimental and may change at any time. | ||
| </div> | ||
| </> | ||
| ); | ||
| } else { | ||
| return <MCPUIResourceRenderer key={`${content.type}-${index}`} content={content} />; | ||
| } | ||
| </div> | ||
| </div> | ||
|
Comment on lines
+57
to
+63
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. decided to simplify and always show the info box |
||
| ); | ||
| } else { | ||
| return null; | ||
| } | ||
|
|
||
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.
if you'd like you can also move this back to "^5.6.1" -- since merging #3859 we're respecting the lock file on all platforms
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.
cool, will do in the next pr related to mcp-ui