fix: onprogress handler error (#9540)

Update MCPService.ts

fix onprogress error
This commit is contained in:
HydrogenE7 2025-08-26 17:10:21 +08:00 committed by GitHub
parent 5e31c809e1
commit cd2d59c6a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,7 +21,6 @@ import {
CancelledNotificationSchema, CancelledNotificationSchema,
type GetPromptResult, type GetPromptResult,
LoggingMessageNotificationSchema, LoggingMessageNotificationSchema,
ProgressNotificationSchema,
PromptListChangedNotificationSchema, PromptListChangedNotificationSchema,
ResourceListChangedNotificationSchema, ResourceListChangedNotificationSchema,
ResourceUpdatedNotificationSchema, ResourceUpdatedNotificationSchema,
@ -432,15 +431,6 @@ class McpService {
this.clearResourceCaches(serverKey) this.clearResourceCaches(serverKey)
}) })
// Set up progress notification handler
client.setNotificationHandler(ProgressNotificationSchema, async (notification) => {
logger.debug(`Progress notification received for server: ${server.name}`, notification.params)
const mainWindow = windowService.getMainWindow()
if (mainWindow) {
mainWindow.webContents.send('mcp-progress', notification.params.progress / (notification.params.total || 1))
}
})
// Set up cancelled notification handler // Set up cancelled notification handler
client.setNotificationHandler(CancelledNotificationSchema, async (notification) => { client.setNotificationHandler(CancelledNotificationSchema, async (notification) => {
logger.debug(`Operation cancelled for server: ${server.name}`, notification.params) logger.debug(`Operation cancelled for server: ${server.name}`, notification.params)
@ -629,6 +619,11 @@ class McpService {
const result = await client.callTool({ name, arguments: args }, undefined, { const result = await client.callTool({ name, arguments: args }, undefined, {
onprogress: (process) => { onprogress: (process) => {
logger.debug(`Progress: ${process.progress / (process.total || 1)}`) logger.debug(`Progress: ${process.progress / (process.total || 1)}`)
logger.debug(`Progress notification received for server: ${server.name}`, process)
const mainWindow = windowService.getMainWindow()
if (mainWindow) {
mainWindow.webContents.send('mcp-progress', process.progress / (process.total || 1))
}
}, },
timeout: server.timeout ? server.timeout * 1000 : 60000, // Default timeout of 1 minute, timeout: server.timeout ? server.timeout * 1000 : 60000, // Default timeout of 1 minute,
// 需要服务端支持: https://modelcontextprotocol.io/specification/2025-06-18/basic/lifecycle#timeouts // 需要服务端支持: https://modelcontextprotocol.io/specification/2025-06-18/basic/lifecycle#timeouts