Open History to see the last commit
1import type { ContentPart } from '@tanstack/ai'
2
3/**
4 * Converts a single MCP resource content block to a TanStack `ContentPart`.
5 *
6 * - `text` field present → `{ type: 'text', content: text }`
7 * - `blob` field present → `{ type: 'text', content: '[binary resource <uri>]' }`
8 * - otherwise → `{ type: 'text', content: JSON.stringify(content) }`
9 */
10export function mcpResourceToContentPart(content: {
11 uri?: string
12 text?: string
13 blob?: string
14 [key: string]: unknown
15}): ContentPart {
16 if (typeof content.text === 'string') {
17 return { type: 'text', content: content.text }
18 }
19 if (typeof content.blob === 'string') {
20 return { type: 'text', content: `[binary resource ${content.uri ?? ''}]` }
21 }
22 return { type: 'text', content: JSON.stringify(content) }
23}