mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-19 10:07:24 +00:00
fix: mcp not response output (#5388)
This commit is contained in:
@@ -7,6 +7,7 @@ import { readFromSecondary } from '../../mongo/utils';
|
|||||||
import { addHours } from 'date-fns';
|
import { addHours } from 'date-fns';
|
||||||
import { imageFileType } from '@fastgpt/global/common/file/constants';
|
import { imageFileType } from '@fastgpt/global/common/file/constants';
|
||||||
import { retryFn } from '@fastgpt/global/common/system/utils';
|
import { retryFn } from '@fastgpt/global/common/system/utils';
|
||||||
|
import { UserError } from '@fastgpt/global/common/error/utils';
|
||||||
|
|
||||||
export const maxImgSize = 1024 * 1024 * 12;
|
export const maxImgSize = 1024 * 1024 * 12;
|
||||||
const base64MimeRegex = /data:image\/([^\)]+);base64/;
|
const base64MimeRegex = /data:image\/([^\)]+);base64/;
|
||||||
@@ -105,7 +106,7 @@ export async function readMongoImg({ id }: { id: string }) {
|
|||||||
...readFromSecondary
|
...readFromSecondary
|
||||||
});
|
});
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return Promise.reject('Image not found');
|
return Promise.reject(new UserError('Image not found'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@@ -4,6 +4,7 @@ import { proxyError, ERROR_RESPONSE, ERROR_ENUM } from '@fastgpt/global/common/e
|
|||||||
import { addLog } from '../system/log';
|
import { addLog } from '../system/log';
|
||||||
import { clearCookie } from '../../support/permission/controller';
|
import { clearCookie } from '../../support/permission/controller';
|
||||||
import { replaceSensitiveText } from '@fastgpt/global/common/string/tools';
|
import { replaceSensitiveText } from '@fastgpt/global/common/string/tools';
|
||||||
|
import { UserError } from '@fastgpt/global/common/error/utils';
|
||||||
|
|
||||||
export interface ResponseType<T = any> {
|
export interface ResponseType<T = any> {
|
||||||
code: number;
|
code: number;
|
||||||
@@ -59,7 +60,11 @@ export const jsonRes = <T = any>(
|
|||||||
msg = error?.error?.message;
|
msg = error?.error?.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
addLog.error(`Api response error: ${url}, ${msg}`, error);
|
if (error instanceof UserError) {
|
||||||
|
addLog.info(`Request error: ${url}, ${msg}`);
|
||||||
|
} else {
|
||||||
|
addLog.error(`System unexpected error: ${url}, ${msg}`, error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(code).json({
|
res.status(code).json({
|
||||||
|
@@ -9,6 +9,7 @@ import { setCron } from '../../../common/system/cron';
|
|||||||
import { checkTimerLock } from '../../../common/system/timerLock/utils';
|
import { checkTimerLock } from '../../../common/system/timerLock/utils';
|
||||||
import { TimerIdEnum } from '../../../common/system/timerLock/constants';
|
import { TimerIdEnum } from '../../../common/system/timerLock/constants';
|
||||||
import { addLog } from '../../../common/system/log';
|
import { addLog } from '../../../common/system/log';
|
||||||
|
import { UserError } from '@fastgpt/global/common/error/utils';
|
||||||
|
|
||||||
const getGridBucket = () => {
|
const getGridBucket = () => {
|
||||||
return new connectionMongo.mongo.GridFSBucket(connectionMongo.connection.db!, {
|
return new connectionMongo.mongo.GridFSBucket(connectionMongo.connection.db!, {
|
||||||
@@ -69,7 +70,7 @@ export const getDatasetImageReadData = async (imageId: string) => {
|
|||||||
_id: new Types.ObjectId(imageId)
|
_id: new Types.ObjectId(imageId)
|
||||||
}).lean();
|
}).lean();
|
||||||
if (!fileInfo) {
|
if (!fileInfo) {
|
||||||
return Promise.reject('Image not found');
|
return Promise.reject(new UserError('Image not found'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const gridBucket = getGridBucket();
|
const gridBucket = getGridBucket();
|
||||||
@@ -84,7 +85,7 @@ export const getDatasetImageBase64 = async (imageId: string) => {
|
|||||||
_id: new Types.ObjectId(imageId)
|
_id: new Types.ObjectId(imageId)
|
||||||
}).lean();
|
}).lean();
|
||||||
if (!fileInfo) {
|
if (!fileInfo) {
|
||||||
return Promise.reject('Image not found');
|
return Promise.reject(new UserError('Image not found'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get image stream from GridFS
|
// Get image stream from GridFS
|
||||||
|
@@ -34,7 +34,7 @@ type RunToolProps = ModuleDispatchProps<{
|
|||||||
|
|
||||||
type RunToolResponse = DispatchNodeResultType<
|
type RunToolResponse = DispatchNodeResultType<
|
||||||
{
|
{
|
||||||
[NodeOutputKeyEnum.rawResponse]?: any;
|
[NodeOutputKeyEnum.rawResponse]?: any; // MCP Tool
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
},
|
},
|
||||||
Record<string, any>
|
Record<string, any>
|
||||||
@@ -197,6 +197,7 @@ export const dispatchRunTool = async (props: RunToolProps): Promise<RunToolRespo
|
|||||||
|
|
||||||
const result = await mcpClient.toolCall(toolName, params);
|
const result = await mcpClient.toolCall(toolName, params);
|
||||||
return {
|
return {
|
||||||
|
data: { [NodeOutputKeyEnum.rawResponse]: result },
|
||||||
[DispatchNodeResponseKeyEnum.nodeResponse]: {
|
[DispatchNodeResponseKeyEnum.nodeResponse]: {
|
||||||
toolRes: result,
|
toolRes: result,
|
||||||
moduleLogo: avatar
|
moduleLogo: avatar
|
||||||
|
Reference in New Issue
Block a user