mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-06 21:35:52 +08:00
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:
parent
469b29c941
commit
86e3776fff
@ -83,7 +83,7 @@ export enum IpcChannel {
|
|||||||
Mcp_UploadDxt = 'mcp:upload-dxt',
|
Mcp_UploadDxt = 'mcp:upload-dxt',
|
||||||
Mcp_AbortTool = 'mcp:abort-tool',
|
Mcp_AbortTool = 'mcp:abort-tool',
|
||||||
Mcp_GetServerVersion = 'mcp:get-server-version',
|
Mcp_GetServerVersion = 'mcp:get-server-version',
|
||||||
|
Mcp_Progress = 'mcp:progress',
|
||||||
// Python
|
// Python
|
||||||
Python_Execute = 'python:execute',
|
Python_Execute = 'python:execute',
|
||||||
|
|
||||||
|
|||||||
@ -17,3 +17,8 @@ export type FileChangeEvent = {
|
|||||||
filePath: string
|
filePath: string
|
||||||
watchPath: string
|
watchPath: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type MCPProgressEvent = {
|
||||||
|
callId: string
|
||||||
|
progress: number // 0-1 range
|
||||||
|
}
|
||||||
|
|||||||
@ -27,6 +27,8 @@ import {
|
|||||||
ToolListChangedNotificationSchema
|
ToolListChangedNotificationSchema
|
||||||
} from '@modelcontextprotocol/sdk/types.js'
|
} from '@modelcontextprotocol/sdk/types.js'
|
||||||
import { nanoid } from '@reduxjs/toolkit'
|
import { nanoid } from '@reduxjs/toolkit'
|
||||||
|
import { MCPProgressEvent } from '@shared/config/types'
|
||||||
|
import { IpcChannel } from '@shared/IpcChannel'
|
||||||
import {
|
import {
|
||||||
BuiltinMCPServerNames,
|
BuiltinMCPServerNames,
|
||||||
type GetResourceResponse,
|
type GetResourceResponse,
|
||||||
@ -689,7 +691,10 @@ class McpService {
|
|||||||
})
|
})
|
||||||
const mainWindow = windowService.getMainWindow()
|
const mainWindow = windowService.getMainWindow()
|
||||||
if (mainWindow) {
|
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,
|
timeout: server.timeout ? server.timeout * 1000 : 60000, // Default timeout of 1 minute,
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import { useTimer } from '@renderer/hooks/useTimer'
|
|||||||
import type { ToolMessageBlock } from '@renderer/types/newMessage'
|
import type { ToolMessageBlock } from '@renderer/types/newMessage'
|
||||||
import { isToolAutoApproved } from '@renderer/utils/mcp-tools'
|
import { isToolAutoApproved } from '@renderer/utils/mcp-tools'
|
||||||
import { cancelToolAction, confirmToolAction } from '@renderer/utils/userConfirmation'
|
import { cancelToolAction, confirmToolAction } from '@renderer/utils/userConfirmation'
|
||||||
|
import { MCPProgressEvent } from '@shared/config/types'
|
||||||
|
import { IpcChannel } from '@shared/IpcChannel'
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Collapse,
|
Collapse,
|
||||||
@ -85,16 +87,19 @@ const MessageMcpTool: FC<Props> = ({ block }) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const removeListener = window.electron.ipcRenderer.on(
|
const removeListener = window.electron.ipcRenderer.on(
|
||||||
'mcp-progress',
|
IpcChannel.Mcp_Progress,
|
||||||
(_event: Electron.IpcRendererEvent, value: number) => {
|
(_event: Electron.IpcRendererEvent, data: MCPProgressEvent) => {
|
||||||
setProgress(value)
|
// Only update progress if this event is for our specific tool call
|
||||||
|
if (data.callId === id) {
|
||||||
|
setProgress(data.progress)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return () => {
|
return () => {
|
||||||
setProgress(0)
|
setProgress(0)
|
||||||
removeListener()
|
removeListener()
|
||||||
}
|
}
|
||||||
}, [])
|
}, [id])
|
||||||
|
|
||||||
const cancelCountdown = () => {
|
const cancelCountdown = () => {
|
||||||
if (timer.current) {
|
if (timer.current) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user