The jsonResult utility function is used to format tool execution data into a CallToolResult object compatible with the Model Context Protocol (MCP) SDK. It performs two actions:
- It creates a
content array containing a single text object where the input data is stringified as a formatted JSON string. - It attaches the original data object to a
structuredContent property.
This is useful when building MCP tools that need to return structured data to a client while ensuring the data is also readable as text in the tool's response.
import { jsonResult } from './utils/response';
const myData = { success: true, count: 42 };
const result = jsonResult(myData);
// result is equivalent to:
// {
// content: [{ type: 'text', text: '{\n "success": true,\n "count": 42\n}' }],
// structuredContent: { success: true, count: 42 }
// }