ui: read structuredContent from MCP tool result when content is empty (#26691)
This commit is contained in:
@@ -18,7 +18,8 @@ import {
|
||||
DEFAULT_CLIENT_VERSION,
|
||||
DEFAULT_IMAGE_MIME_TYPE,
|
||||
DEFAULT_MCP_CONFIG,
|
||||
HEADERS
|
||||
HEADERS,
|
||||
NEWLINE
|
||||
} from '$lib/constants';
|
||||
import {
|
||||
MCPConnectionPhase,
|
||||
@@ -70,6 +71,7 @@ interface ToolResultContentItem {
|
||||
|
||||
interface ToolCallResult {
|
||||
content?: ToolResultContentItem[];
|
||||
structuredContent?: Record<string, unknown>;
|
||||
isError?: boolean;
|
||||
_meta?: Record<string, unknown>;
|
||||
}
|
||||
@@ -1012,10 +1014,20 @@ export class MCPService {
|
||||
|
||||
if (!Array.isArray(content)) return '';
|
||||
|
||||
return content
|
||||
const formatted = content
|
||||
.map((item) => this.formatSingleContent(item))
|
||||
.filter(Boolean)
|
||||
.join('\n');
|
||||
.join(NEWLINE);
|
||||
|
||||
if (formatted !== '') {
|
||||
return formatted;
|
||||
}
|
||||
|
||||
if (result.structuredContent && typeof result.structuredContent === 'object') {
|
||||
return JSON.stringify(result.structuredContent);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
private static formatSingleContent(content: ToolResultContentItem): string {
|
||||
|
||||
Reference in New Issue
Block a user