fix(mcp): enhance progress event structure to include callId for specific tool tracking (#9946)

* fix(mcp): enhance progress event structure to include callId for specific tool tracking

* refactor(mcp): add MCP progress event with callId and progress percentage
This commit is contained in:
SuYao 2025-09-05 17:26:20 +08:00 committed by GitHub
parent 469b29c941
commit 86e3776fff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 6 deletions

View File

@ -83,7 +83,7 @@ export enum IpcChannel {
Mcp_UploadDxt = 'mcp:upload-dxt',
Mcp_AbortTool = 'mcp:abort-tool',
Mcp_GetServerVersion = 'mcp:get-server-version',
Mcp_Progress = 'mcp:progress',
// Python
Python_Execute = 'python:execute',

View File

@ -17,3 +17,8 @@ export type FileChangeEvent = {
filePath: string
watchPath: string
}
export type MCPProgressEvent = {
callId: string
progress: number // 0-1 range
}

View File

@ -27,6 +27,8 @@ import {
ToolListChangedNotificationSchema
} from '@modelcontextprotocol/sdk/types.js'
import { nanoid } from '@reduxjs/toolkit'
import { MCPProgressEvent } from '@shared/config/types'
import { IpcChannel } from '@shared/IpcChannel'
import {
BuiltinMCPServerNames,
type GetResourceResponse,
@ -689,7 +691,10 @@ class McpService {
})
const mainWindow = windowService.getMainWindow()
if (mainWindow) {
mainWindow.webContents.send('mcp-progress', process.progress / (process.total || 1))
mainWindow.webContents.send(IpcChannel.Mcp_Progress, {
callId: toolCallId,
progress: process.progress / (process.total || 1)
} as MCPProgressEvent)
}
},
timeout: server.timeout ? server.timeout * 1000 : 60000, // Default timeout of 1 minute,

View File

@ -7,6 +7,8 @@ import { useTimer } from '@renderer/hooks/useTimer'
import type { ToolMessageBlock } from '@renderer/types/newMessage'
import { isToolAutoApproved } from '@renderer/utils/mcp-tools'
import { cancelToolAction, confirmToolAction } from '@renderer/utils/userConfirmation'
import { MCPProgressEvent } from '@shared/config/types'
import { IpcChannel } from '@shared/IpcChannel'
import {
Button,
Collapse,
@ -85,16 +87,19 @@ const MessageMcpTool: FC<Props> = ({ block }) => {
useEffect(() => {
const removeListener = window.electron.ipcRenderer.on(
'mcp-progress',
(_event: Electron.IpcRendererEvent, value: number) => {
setProgress(value)
IpcChannel.Mcp_Progress,
(_event: Electron.IpcRendererEvent, data: MCPProgressEvent) => {
// Only update progress if this event is for our specific tool call
if (data.callId === id) {
setProgress(data.progress)
}
}
)
return () => {
setProgress(0)
removeListener()
}
}, [])
}, [id])
const cancelCountdown = () => {
if (timer.current) {