Dont show MCP UI/Apps until tool is approved (#6492)
Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
@@ -55,6 +55,7 @@ interface ToolCallWithResponseProps {
|
||||
toolResponse?: ToolResponseMessageContent;
|
||||
notifications?: NotificationEvent[];
|
||||
isStreamingMessage?: boolean;
|
||||
isPendingApproval: boolean;
|
||||
append?: (value: string) => void;
|
||||
}
|
||||
|
||||
@@ -110,10 +111,8 @@ function McpAppWrapper({
|
||||
? requestWithMeta.toolCall.value.arguments
|
||||
: undefined;
|
||||
|
||||
// Memoize toolInput to prevent unnecessary re-renders
|
||||
const toolInput = useMemo(() => ({ arguments: toolArguments || {} }), [toolArguments]);
|
||||
|
||||
// Memoize toolResult to prevent unnecessary re-renders
|
||||
const toolResult = useMemo(() => {
|
||||
if (!toolResponse) return undefined;
|
||||
const resultWithMeta = toolResponse.toolResult as ToolResultWithMeta;
|
||||
@@ -153,6 +152,7 @@ export default function ToolCallWithResponse({
|
||||
toolResponse,
|
||||
notifications,
|
||||
isStreamingMessage,
|
||||
isPendingApproval,
|
||||
append,
|
||||
}: ToolCallWithResponseProps) {
|
||||
// Handle both the wrapped ToolResult format and the unwrapped format
|
||||
@@ -173,6 +173,8 @@ export default function ToolCallWithResponse({
|
||||
requestWithMeta._meta?.ui?.resourceUri || resultWithMeta?.value?._meta?.ui?.resourceUri
|
||||
);
|
||||
|
||||
const shouldShowMcpContent = !isPendingApproval;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
@@ -191,7 +193,8 @@ export default function ToolCallWithResponse({
|
||||
/>
|
||||
</div>
|
||||
{/* MCP UI — Inline */}
|
||||
{!hasMcpAppResourceURI &&
|
||||
{shouldShowMcpContent &&
|
||||
!hasMcpAppResourceURI &&
|
||||
toolResponse?.toolResult &&
|
||||
getToolResultContent(toolResponse.toolResult).map((content, index) => {
|
||||
const resourceContent = isEmbeddedResource(content)
|
||||
@@ -214,7 +217,8 @@ export default function ToolCallWithResponse({
|
||||
}
|
||||
})}
|
||||
|
||||
{hasMcpAppResourceURI && sessionId && (
|
||||
{/* MCP App */}
|
||||
{shouldShowMcpContent && hasMcpAppResourceURI && sessionId && (
|
||||
<McpAppWrapper
|
||||
toolRequest={toolRequest}
|
||||
toolResponse={toolResponse}
|
||||
|
||||
Reference in New Issue
Block a user