ui: read structuredContent from MCP tool result when content is empty (#26691)

This commit is contained in:
Gautam0507
2026-08-15 20:00:18 +02:00
committed by GitHub
parent ad1de39e07
commit 0d9ceae1e3
2 changed files with 33 additions and 4 deletions
+18 -1
View File
@@ -2,7 +2,7 @@ import { Client } from '@modelcontextprotocol/sdk/client';
import { CORS_PROXY } from '$lib/constants';
import { MCPConnectionPhase, MCPTransportType } from '$lib/enums';
import { MCPService } from '$lib/services/mcp.service';
import type { MCPConnectionLog, MCPServerConfig } from '$lib/types';
import type { MCPConnection, MCPConnectionLog, MCPServerConfig } from '$lib/types';
import { afterEach, describe, expect, it, vi } from 'vitest';
type DiagnosticFetchFactory = (
@@ -329,4 +329,21 @@ describe('MCPService', () => {
)
).toHaveLength(0);
});
it('falls back to structuredContent when content array is empty', async () => {
const connection = {
client: {
callTool: vi.fn().mockResolvedValue({
content: [],
structuredContent: { accounts: [{ id: 1 }], total: 1 }
})
},
requestTimeoutMs: 9000,
serverName: 'test-server'
} as unknown as MCPConnection;
const result = await MCPService.callTool(connection, { arguments: {}, name: 'tool' });
expect(result.isError).toBe(false);
expect(result.content).toBe('{"accounts":[{"id":1}],"total":1}');
});
});