fix: MCP UI not rendering due to CallToolResult structure change (#6143)
This commit is contained in:
@@ -15,7 +15,7 @@ import { ChevronRight, FlaskConical } from 'lucide-react';
|
|||||||
import { TooltipWrapper } from './settings/providers/subcomponents/buttons/TooltipWrapper';
|
import { TooltipWrapper } from './settings/providers/subcomponents/buttons/TooltipWrapper';
|
||||||
import MCPUIResourceRenderer from './MCPUIResourceRenderer';
|
import MCPUIResourceRenderer from './MCPUIResourceRenderer';
|
||||||
import { isUIResource } from '@mcp-ui/client';
|
import { isUIResource } from '@mcp-ui/client';
|
||||||
import { Content, EmbeddedResource } from '../api';
|
import { CallToolResponse, Content, EmbeddedResource } from '../api';
|
||||||
|
|
||||||
interface ToolCallWithResponseProps {
|
interface ToolCallWithResponseProps {
|
||||||
isCancelledMessage: boolean;
|
isCancelledMessage: boolean;
|
||||||
@@ -26,11 +26,15 @@ interface ToolCallWithResponseProps {
|
|||||||
append?: (value: string) => void; // Function to append messages to the chat
|
append?: (value: string) => void; // Function to append messages to the chat
|
||||||
}
|
}
|
||||||
|
|
||||||
function getToolResultValue(toolResult: Record<string, unknown>): Content[] | null {
|
function getToolResultContent(toolResult: Record<string, unknown>): Content[] {
|
||||||
if ('value' in toolResult && Array.isArray(toolResult.value)) {
|
if (toolResult.status !== 'success') {
|
||||||
return toolResult.value as Content[];
|
return [];
|
||||||
}
|
}
|
||||||
return null;
|
const value = toolResult.value as CallToolResponse;
|
||||||
|
return value.content.filter((item) => {
|
||||||
|
const annotations = (item as { annotations?: { audience?: string[] } }).annotations;
|
||||||
|
return !annotations?.audience || annotations.audience.includes('user');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function isEmbeddedResource(content: Content): content is EmbeddedResource {
|
function isEmbeddedResource(content: Content): content is EmbeddedResource {
|
||||||
@@ -76,7 +80,7 @@ export default function ToolCallWithResponse({
|
|||||||
</div>
|
</div>
|
||||||
{/* MCP UI — Inline */}
|
{/* MCP UI — Inline */}
|
||||||
{toolResponse?.toolResult &&
|
{toolResponse?.toolResult &&
|
||||||
getToolResultValue(toolResponse.toolResult)?.map((content, index) => {
|
getToolResultContent(toolResponse.toolResult).map((content, index) => {
|
||||||
const resourceContent = isEmbeddedResource(content)
|
const resourceContent = isEmbeddedResource(content)
|
||||||
? { ...content, type: 'resource' as const }
|
? { ...content, type: 'resource' as const }
|
||||||
: null;
|
: null;
|
||||||
@@ -253,12 +257,9 @@ function ToolCallView({
|
|||||||
}
|
}
|
||||||
}, [toolResponse, startTime]);
|
}, [toolResponse, startTime]);
|
||||||
|
|
||||||
const toolResults: Content[] =
|
const toolResults =
|
||||||
loadingStatus === 'success' && Array.isArray(toolResponse?.toolResult.value)
|
loadingStatus === 'success' && toolResponse?.toolResult
|
||||||
? toolResponse!.toolResult.value.filter((item) => {
|
? getToolResultContent(toolResponse.toolResult)
|
||||||
const audience = item.annotations?.audience as string[] | undefined;
|
|
||||||
return !audience || audience.includes('user');
|
|
||||||
})
|
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const logs = notifications
|
const logs = notifications
|
||||||
|
|||||||
Reference in New Issue
Block a user