MCPcopy Create free account
hub / github.com/TanStack/ai / resultToText

Function resultToText

packages/ai-react/src/mcp-app-resource.tsx:31–37  ·  view source on GitHub ↗

* Coalesce an arbitrary bridge result into the `string` required by the * `CallToolResult` text content block. `JSON.stringify` is typed to return * `string` but actually returns `undefined` for inputs like `undefined` or a * function, so we narrow explicitly to avoid `text: undefined`.

(result: unknown)

Source from the content-addressed store, hash-verified

29 * function, so we narrow explicitly to avoid `text: undefined`.
30 */
31function resultToText(result: unknown): string {
32 if (typeof result === 'string') return result
33 // `JSON.stringify`'s lib signature claims `string`, but it returns
34 // `undefined` for `undefined`/function inputs; type the call honestly.
35 const stringify: (value: unknown) => string | undefined = JSON.stringify
36 return stringify(result) ?? 'null'
37}
38
39export function MCPAppResource(props: MCPAppResourceProps): JSX.Element {
40 const { bridge } = props

Callers 1

MCPAppResourceFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected