fix: ensure args are an array in AddMcpServerModal and MCPService com… (#6413)

fix: ensure args are an array in AddMcpServerModal and MCPService components
This commit is contained in:
自由的世界人 2025-05-24 23:17:15 +08:00 committed by GitHub
parent 8eb0be7562
commit 795d12c91e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 5 deletions

View File

@ -91,7 +91,7 @@ class McpService {
return JSON.stringify({ return JSON.stringify({
baseUrl: server.baseUrl, baseUrl: server.baseUrl,
command: server.command, command: server.command,
args: server.args, args: Array.isArray(server.args) ? server.args : [],
registryUrl: server.registryUrl, registryUrl: server.registryUrl,
env: server.env, env: server.env,
id: server.id id: server.id
@ -567,12 +567,11 @@ class McpService {
try { try {
const result = await client.listResources() const result = await client.listResources()
const resources = result.resources || [] const resources = result.resources || []
const serverResources = (Array.isArray(resources) ? resources : []).map((resource: any) => ({ return (Array.isArray(resources) ? resources : []).map((resource: any) => ({
...resource, ...resource,
serverId: server.id, serverId: server.id,
serverName: server.name serverName: server.name
})) }))
return serverResources
} catch (error: any) { } catch (error: any) {
// -32601 is the code for the method not found // -32601 is the code for the method not found
if (error?.code !== -32601) { if (error?.code !== -32601) {

View File

@ -95,7 +95,7 @@ const AddMcpServerModal: FC<AddMcpServerModalProps> = ({ visible, onClose, onSuc
description: serverToAdd!.description ?? '', description: serverToAdd!.description ?? '',
baseUrl: serverToAdd!.baseUrl ?? serverToAdd!.url ?? '', baseUrl: serverToAdd!.baseUrl ?? serverToAdd!.url ?? '',
command: serverToAdd!.command ?? '', command: serverToAdd!.command ?? '',
args: serverToAdd!.args || [], args: Array.isArray(serverToAdd!.args) ? serverToAdd!.args : [],
env: serverToAdd!.env || {}, env: serverToAdd!.env || {},
isActive: false, isActive: false,
type: serverToAdd!.type, type: serverToAdd!.type,
@ -236,7 +236,6 @@ const parseAndExtractServer = (
} }
} else if ( } else if (
typeof parsedJson === 'object' && typeof parsedJson === 'object' &&
parsedJson !== null &&
!Array.isArray(parsedJson) && !Array.isArray(parsedJson) &&
!parsedJson.mcpServers // 確保是直接的伺服器物件 !parsedJson.mcpServers // 確保是直接的伺服器物件
) { ) {