mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-23 17:06:42 +08:00
fix: MCP import now processes all files instead of only the first (#17179)
This commit is contained in:
@@ -30,35 +30,55 @@ export const useImportMcp = () => {
|
||||
|
||||
const onImportOk = useCallback(
|
||||
async ({ fileList }: { fileList: File[] }) => {
|
||||
if (fileList.length > 0) {
|
||||
const file = fileList[0];
|
||||
if (file.type !== FileMimeType.Json) {
|
||||
message.error(t('flow.jsonUploadTypeErrorMessage'));
|
||||
return;
|
||||
}
|
||||
if (fileList.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Folder uploads may include non-JSON files; only process JSON ones.
|
||||
const jsonFiles = fileList.filter(
|
||||
(file) =>
|
||||
file.type === FileMimeType.Json ||
|
||||
file.name.toLowerCase().endsWith('.json'),
|
||||
);
|
||||
if (jsonFiles.length === 0) {
|
||||
message.error(t('flow.jsonUploadTypeErrorMessage'));
|
||||
return;
|
||||
}
|
||||
|
||||
const errorMessage = t('flow.jsonUploadContentErrorMessage');
|
||||
const mergedMcpServers: Record<string, any> = {};
|
||||
|
||||
for (const file of jsonFiles) {
|
||||
const mcpStr = await file.text();
|
||||
const errorMessage = t('flow.jsonUploadContentErrorMessage');
|
||||
let mcp: { mcpServers?: Record<string, any> };
|
||||
try {
|
||||
const mcp = JSON.parse(mcpStr);
|
||||
try {
|
||||
McpConfigSchema.parse(mcp);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
message.error('Incorrect data format');
|
||||
return;
|
||||
}
|
||||
if (mcpStr && !isEmpty(mcp)) {
|
||||
const ret = await importMcpServer(mcp);
|
||||
if (ret.code === 0) {
|
||||
hideImportModal();
|
||||
}
|
||||
} else {
|
||||
message.error(errorMessage);
|
||||
}
|
||||
mcp = JSON.parse(mcpStr);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
message.error(errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
McpConfigSchema.parse(mcp);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
message.error('Incorrect data format');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mcpStr || isEmpty(mcp)) {
|
||||
message.error(errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
Object.assign(mergedMcpServers, mcp.mcpServers);
|
||||
}
|
||||
|
||||
if (!isEmpty(mergedMcpServers)) {
|
||||
const ret = await importMcpServer({ mcpServers: mergedMcpServers });
|
||||
if (ret.code === 0) {
|
||||
hideImportModal();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user