UNPKG

@tanstack/ai-mcp

Version:

Host-side Model Context Protocol client for TanStack AI: discover and run MCP server tools, resources, and prompts in any adapter's chat() loop, with generated end-to-end types.

24 lines (22 loc) 793 B
import type { ContentPart } from '@tanstack/ai' /** * Converts a single MCP resource content block to a TanStack `ContentPart`. * * - `text` field present → `{ type: 'text', content: text }` * - `blob` field present → `{ type: 'text', content: '[binary resource <uri>]' }` * - otherwise → `{ type: 'text', content: JSON.stringify(content) }` */ export function mcpResourceToContentPart(content: { uri?: string text?: string blob?: string [key: string]: unknown }): ContentPart { if (typeof content.text === 'string') { return { type: 'text', content: content.text } } if (typeof content.blob === 'string') { return { type: 'text', content: `[binary resource ${content.uri ?? ''}]` } } return { type: 'text', content: JSON.stringify(content) } }