fix(MCPService): Improve server addition and status update error handling; add localized error messages
This commit is contained in:
parent
03c18287fc
commit
723e686455
@ -193,15 +193,14 @@ export default class MCPService extends EventEmitter {
|
|||||||
throw new Error(`Server with name ${server.name} already exists`)
|
throw new Error(`Server with name ${server.name} already exists`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to servers list
|
|
||||||
const updatedServers = [...this.servers, server]
|
|
||||||
this.servers = updatedServers
|
|
||||||
this.notifyReduxServersChanged(updatedServers)
|
|
||||||
|
|
||||||
// Activate if needed
|
// Activate if needed
|
||||||
if (server.isActive) {
|
if (server.isActive) {
|
||||||
await this.activate(server).catch(this.logError(`Failed to activate server ${server.name}`))
|
await this.activate(server)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add to servers list
|
||||||
|
this.servers = [...this.servers, server]
|
||||||
|
this.notifyReduxServersChanged(this.servers)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -260,16 +259,16 @@ export default class MCPService extends EventEmitter {
|
|||||||
throw new Error(`Server ${name} not found`)
|
throw new Error(`Server ${name} not found`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update server status
|
|
||||||
server.isActive = isActive
|
|
||||||
this.notifyReduxServersChanged([...this.servers])
|
|
||||||
|
|
||||||
// Activate or deactivate as needed
|
// Activate or deactivate as needed
|
||||||
if (isActive) {
|
if (isActive) {
|
||||||
await this.activate(server)
|
await this.activate(server)
|
||||||
} else {
|
} else {
|
||||||
await this.deactivate(name)
|
await this.deactivate(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update server status
|
||||||
|
server.isActive = isActive
|
||||||
|
this.notifyReduxServersChanged([...this.servers])
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -336,6 +335,7 @@ export default class MCPService extends EventEmitter {
|
|||||||
this.emit('server-started', { name })
|
this.emit('server-started', { name })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(`[MCP] Error activating server ${name}:`, error)
|
log.error(`[MCP] Error activating server ${name}:`, error)
|
||||||
|
server.isActive = false
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -786,6 +786,7 @@
|
|||||||
"active": "Active",
|
"active": "Active",
|
||||||
"addServer": "Add Server",
|
"addServer": "Add Server",
|
||||||
"addSuccess": "Server added successfully",
|
"addSuccess": "Server added successfully",
|
||||||
|
"addError": "Failed to add server",
|
||||||
"args": "Arguments",
|
"args": "Arguments",
|
||||||
"argsTooltip": "Each argument on a new line",
|
"argsTooltip": "Each argument on a new line",
|
||||||
"command": "Command",
|
"command": "Command",
|
||||||
@ -794,6 +795,7 @@
|
|||||||
"confirmDelete": "Delete Server",
|
"confirmDelete": "Delete Server",
|
||||||
"confirmDeleteMessage": "Are you sure you want to delete the server?",
|
"confirmDeleteMessage": "Are you sure you want to delete the server?",
|
||||||
"deleteSuccess": "Server deleted successfully",
|
"deleteSuccess": "Server deleted successfully",
|
||||||
|
"deleteError": "Failed to delete server",
|
||||||
"description": "Description",
|
"description": "Description",
|
||||||
"duplicateName": "A server with this name already exists",
|
"duplicateName": "A server with this name already exists",
|
||||||
"editServer": "Edit Server",
|
"editServer": "Edit Server",
|
||||||
@ -807,6 +809,7 @@
|
|||||||
"title": "MCP Servers",
|
"title": "MCP Servers",
|
||||||
"type": "Type",
|
"type": "Type",
|
||||||
"updateSuccess": "Server updated successfully",
|
"updateSuccess": "Server updated successfully",
|
||||||
|
"updateError": "Failed to update server",
|
||||||
"url": "URL",
|
"url": "URL",
|
||||||
"toggleError": "Toggle failed"
|
"toggleError": "Toggle failed"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -786,6 +786,7 @@
|
|||||||
"active": "有効",
|
"active": "有効",
|
||||||
"addServer": "サーバーを追加",
|
"addServer": "サーバーを追加",
|
||||||
"addSuccess": "サーバーが正常に追加されました",
|
"addSuccess": "サーバーが正常に追加されました",
|
||||||
|
"addError": "サーバーの追加に失敗しました",
|
||||||
"args": "引数",
|
"args": "引数",
|
||||||
"argsTooltip": "1行に1つの引数を入力してください",
|
"argsTooltip": "1行に1つの引数を入力してください",
|
||||||
"command": "コマンド",
|
"command": "コマンド",
|
||||||
@ -793,6 +794,7 @@
|
|||||||
"config_description": "モデルコンテキストプロトコルサーバーの設定",
|
"config_description": "モデルコンテキストプロトコルサーバーの設定",
|
||||||
"confirmDelete": "サーバーを削除",
|
"confirmDelete": "サーバーを削除",
|
||||||
"confirmDeleteMessage": "本当にこのサーバーを削除しますか?",
|
"confirmDeleteMessage": "本当にこのサーバーを削除しますか?",
|
||||||
|
"deleteError": "サーバーの削除に失敗しました",
|
||||||
"deleteSuccess": "サーバーが正常に削除されました",
|
"deleteSuccess": "サーバーが正常に削除されました",
|
||||||
"description": "説明",
|
"description": "説明",
|
||||||
"duplicateName": "同じ名前のサーバーが既に存在します",
|
"duplicateName": "同じ名前のサーバーが既に存在します",
|
||||||
@ -807,6 +809,7 @@
|
|||||||
"title": "MCP サーバー",
|
"title": "MCP サーバー",
|
||||||
"type": "タイプ",
|
"type": "タイプ",
|
||||||
"updateSuccess": "サーバーが正常に更新されました",
|
"updateSuccess": "サーバーが正常に更新されました",
|
||||||
|
"updateError": "サーバーの更新に失敗しました",
|
||||||
"url": "URL",
|
"url": "URL",
|
||||||
"toggleError": "切り替えに失敗しました"
|
"toggleError": "切り替えに失敗しました"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -786,6 +786,7 @@
|
|||||||
"active": "Активен",
|
"active": "Активен",
|
||||||
"addServer": "Добавить сервер",
|
"addServer": "Добавить сервер",
|
||||||
"addSuccess": "Сервер успешно добавлен",
|
"addSuccess": "Сервер успешно добавлен",
|
||||||
|
"addError": "Ошибка добавления сервера",
|
||||||
"args": "Аргументы",
|
"args": "Аргументы",
|
||||||
"argsTooltip": "Каждый аргумент с новой строки",
|
"argsTooltip": "Каждый аргумент с новой строки",
|
||||||
"command": "Команда",
|
"command": "Команда",
|
||||||
@ -793,6 +794,7 @@
|
|||||||
"config_description": "Настройка серверов протокола контекста модели",
|
"config_description": "Настройка серверов протокола контекста модели",
|
||||||
"confirmDelete": "Удалить сервер",
|
"confirmDelete": "Удалить сервер",
|
||||||
"confirmDeleteMessage": "Вы уверены, что хотите удалить этот сервер?",
|
"confirmDeleteMessage": "Вы уверены, что хотите удалить этот сервер?",
|
||||||
|
"deleteError": "Не удалось удалить сервер",
|
||||||
"deleteSuccess": "Сервер успешно удален",
|
"deleteSuccess": "Сервер успешно удален",
|
||||||
"description": "Описание",
|
"description": "Описание",
|
||||||
"duplicateName": "Сервер с таким именем уже существует",
|
"duplicateName": "Сервер с таким именем уже существует",
|
||||||
@ -807,6 +809,7 @@
|
|||||||
"title": "Серверы MCP",
|
"title": "Серверы MCP",
|
||||||
"type": "Тип",
|
"type": "Тип",
|
||||||
"updateSuccess": "Сервер успешно обновлен",
|
"updateSuccess": "Сервер успешно обновлен",
|
||||||
|
"updateError": "Ошибка обновления сервера",
|
||||||
"url": "URL",
|
"url": "URL",
|
||||||
"toggleError": "Переключение не удалось"
|
"toggleError": "Переключение не удалось"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -786,6 +786,7 @@
|
|||||||
"active": "启用",
|
"active": "启用",
|
||||||
"addServer": "添加服务器",
|
"addServer": "添加服务器",
|
||||||
"addSuccess": "服务器添加成功",
|
"addSuccess": "服务器添加成功",
|
||||||
|
"addError": "添加服务器失败",
|
||||||
"args": "参数",
|
"args": "参数",
|
||||||
"argsTooltip": "每个参数占一行",
|
"argsTooltip": "每个参数占一行",
|
||||||
"command": "命令",
|
"command": "命令",
|
||||||
@ -793,6 +794,7 @@
|
|||||||
"config_description": "配置模型上下文协议服务器",
|
"config_description": "配置模型上下文协议服务器",
|
||||||
"confirmDelete": "删除服务器",
|
"confirmDelete": "删除服务器",
|
||||||
"confirmDeleteMessage": "您确定要删除该服务器吗?",
|
"confirmDeleteMessage": "您确定要删除该服务器吗?",
|
||||||
|
"deleteError": "删除服务器失败",
|
||||||
"deleteSuccess": "服务器删除成功",
|
"deleteSuccess": "服务器删除成功",
|
||||||
"description": "描述",
|
"description": "描述",
|
||||||
"duplicateName": "已存在同名服务器",
|
"duplicateName": "已存在同名服务器",
|
||||||
@ -807,6 +809,7 @@
|
|||||||
"title": "MCP 服务器",
|
"title": "MCP 服务器",
|
||||||
"type": "类型",
|
"type": "类型",
|
||||||
"updateSuccess": "服务器更新成功",
|
"updateSuccess": "服务器更新成功",
|
||||||
|
"updateError": "更新服务器失败",
|
||||||
"url": "URL",
|
"url": "URL",
|
||||||
"toggleError": "切换失败"
|
"toggleError": "切换失败"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -786,6 +786,7 @@
|
|||||||
"active": "啟用",
|
"active": "啟用",
|
||||||
"addServer": "新增伺服器",
|
"addServer": "新增伺服器",
|
||||||
"addSuccess": "伺服器新增成功",
|
"addSuccess": "伺服器新增成功",
|
||||||
|
"addError": "添加伺服器失敗",
|
||||||
"args": "參數",
|
"args": "參數",
|
||||||
"argsTooltip": "每個參數佔一行",
|
"argsTooltip": "每個參數佔一行",
|
||||||
"command": "指令",
|
"command": "指令",
|
||||||
@ -793,6 +794,7 @@
|
|||||||
"config_description": "設定模型上下文協議伺服器",
|
"config_description": "設定模型上下文協議伺服器",
|
||||||
"confirmDelete": "刪除伺服器",
|
"confirmDelete": "刪除伺服器",
|
||||||
"confirmDeleteMessage": "您確定要刪除該伺服器嗎?",
|
"confirmDeleteMessage": "您確定要刪除該伺服器嗎?",
|
||||||
|
"deleteError": "刪除伺服器失敗",
|
||||||
"deleteSuccess": "伺服器刪除成功",
|
"deleteSuccess": "伺服器刪除成功",
|
||||||
"description": "描述",
|
"description": "描述",
|
||||||
"duplicateName": "已存在相同名稱的伺服器",
|
"duplicateName": "已存在相同名稱的伺服器",
|
||||||
@ -807,6 +809,7 @@
|
|||||||
"title": "MCP 伺服器",
|
"title": "MCP 伺服器",
|
||||||
"type": "類型",
|
"type": "類型",
|
||||||
"updateSuccess": "伺服器更新成功",
|
"updateSuccess": "伺服器更新成功",
|
||||||
|
"updateError": "更新伺服器失敗",
|
||||||
"url": "URL",
|
"url": "URL",
|
||||||
"toggleError": "切換失敗"
|
"toggleError": "切換失敗"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -160,9 +160,9 @@ const MCPSettings: FC = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleToggleActive = (name: string, isActive: boolean) => {
|
const handleToggleActive = async (name: string, isActive: boolean) => {
|
||||||
try {
|
try {
|
||||||
window.api.mcp.setServerActive(name, isActive)
|
await window.api.mcp.setServerActive(name, isActive)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
window.message.error(`${t('settings.mcp.toggleError')}: ${error.message}`)
|
window.message.error(`${t('settings.mcp.toggleError')}: ${error.message}`)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user