fix(chat-ui): move MCPEvent to shared mcp_tools/types, skip partial events on abort

- Move MCPEvent interface to mcp_tools/types.tsx (shared with MCPServer/MCPTool),
  eliminating the playground→chat cross-module dependency. chat/types.ts and
  both playground components now import from mcp_tools/types.
- Only persist accumulated MCP events when the stream completes cleanly; aborted
  or errored turns drop partial events to avoid showing incomplete tool calls.
This commit is contained in:
Ishaan Jaffer 2026-03-10 17:47:56 -07:00
parent 1453f85105
commit 622d0f9d88
5 changed files with 33 additions and 30 deletions

View file

@ -320,8 +320,9 @@ const ChatPage: React.FC<ChatPageProps> = ({ accessToken, userRole, userId, user
});
}
} finally {
// Persist MCP events once after the turn ends (single localStorage write).
if (accumulatedMCPEvents.length > 0) {
// Persist MCP events only when the stream completed cleanly — partial
// events from an aborted/errored turn would show incomplete tool calls.
if (accumulatedMCPEvents.length > 0 && !abortControllerRef.current?.signal.aborted) {
updateLastAssistantMessage(convId!, { mcpEvents: accumulatedMCPEvents });
}
setIsStreaming(false);

View file

@ -1,29 +1,4 @@
/** Represents a single MCP tool event emitted during an assistant turn. */
export interface MCPEvent {
type: string;
sequence_number?: number;
output_index?: number;
item_id?: string;
item?: {
id?: string;
type?: string;
server_label?: string;
tools?: Array<{
name: string;
description: string;
annotations?: {
read_only?: boolean;
};
input_schema?: unknown;
}>;
name?: string;
arguments?: string;
output?: string;
};
delta?: string;
arguments?: string;
timestamp?: number;
}
export type { MCPEvent } from "../mcp_tools/types";
export interface ChatMessage {
id: string;

View file

@ -1,3 +1,30 @@
/** A single MCP tool event emitted by the LiteLLM proxy during a Responses API turn. */
export interface MCPEvent {
type: string;
sequence_number?: number;
output_index?: number;
item_id?: string;
item?: {
id?: string;
type?: string;
server_label?: string;
tools?: Array<{
name: string;
description: string;
annotations?: {
read_only?: boolean;
};
input_schema?: unknown;
}>;
name?: string;
arguments?: string;
output?: string;
};
delta?: string;
arguments?: string;
timestamp?: number;
}
export interface Team {
team_id: string;
team_alias?: string;

View file

@ -1,6 +1,6 @@
import React from "react";
import { Typography, Collapse } from "antd";
import type { MCPEvent } from "../../chat/types";
import type { MCPEvent } from "../../mcp_tools/types";
const { Text } = Typography;
const { Panel } = Collapse;

View file

@ -3,7 +3,7 @@ import { MessageType } from "../chat_ui/types";
import { TokenUsage } from "../chat_ui/ResponseMetrics";
import { getProxyBaseUrl } from "@/components/networking";
import NotificationManager from "@/components/molecules/notifications_manager";
import type { MCPEvent } from "../../chat/types";
import type { MCPEvent } from "../../mcp_tools/types";
import { MCPServer } from "../../mcp_tools/types";
import {
CodeInterpreterResult,