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 16ea4cbdec
commit 9428461fb7
2 changed files with 3 additions and 5 deletions

View File

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

View File

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