View the source code for this module on GitHub: https://github.com/mcp-use/mcp-use/blob/main/libraries/typescript/packages/server/src/response-helpers.ts
CallToolResult objects. Import them from mcp-use. Resource and prompt callbacks may still return helper results; the server converts them to ReadResourceResult / GetPromptResult.
Functions
text
Creates a plain text content response, the most common response type for tools and resources._meta.mimeType to text/plain.
ReturnsstringrequiredThe text content to return
SignatureCallToolResultResult with a singletextcontent item andtext/plainMIME type
markdown
Creates a Markdown content response. Identical shape totext, but sets the _meta.mimeType to text/markdown so clients render it as Markdown.
ReturnsstringrequiredThe Markdown content to return
SignatureCallToolResultResult withtext/markdownMIME type metadata
html
Creates an HTML content response for web display. Returns the HTML inside atext content item and sets _meta.mimeType to text/html.
ReturnsstringrequiredThe HTML content to return
SignatureCallToolResultResult withtext/htmlMIME type metadata
xml
Creates an XML content response. Returns the XML inside atext content item and sets _meta.mimeType to text/xml.
ReturnsstringrequiredThe XML content to return
SignatureCallToolResultResult withtext/xmlMIME type metadata
css
Creates a CSS stylesheet content response. Returns the CSS inside atext content item and sets _meta.mimeType to text/css.
ReturnsstringrequiredThe CSS content to return
SignatureCallToolResultResult withtext/cssMIME type metadata
javascript
Creates a JavaScript code content response. Returns the source inside atext content item and sets _meta.mimeType to text/javascript.
ReturnsstringrequiredThe JavaScript content to return
SignatureCallToolResultResult withtext/javascriptMIME type metadata
object
Creates a JSON object response that carries both a text representation and typed structured content. The text content is the pretty-printed JSON (JSON.stringify(data, null, 2)), structuredContent holds the typed data, and _meta.mimeType is set to application/json. The generic T flows through to the result type so callers get full type inference.
If data is an array, object delegates to array internally (array as structuredContent directly — no { data } wrap). Note that the _meta.mimeType is only set on the non-array path.
ReturnsT extends Record<string, any>requiredThe object to return as JSON. An array is forwarded toarray()
SignatureTypedCallToolResult<T>Result with pretty-printed JSON text, typedstructuredContent, andapplication/jsonMIME type
array
Deprecated. Prefer{ content: [{ type: "text", text: JSON.stringify(data) }], structuredContent: data } — the 2026 wire accepts array roots (no { data } wrap).
Creates a JSON response for an array. The array is returned as structuredContent directly. The text content is the pretty-printed JSON of the original array. Unlike the other JSON helper, array does not set a _meta.mimeType.
ReturnsT extends any[]requiredThe array to return as JSON
SignatureCallToolResultResult whosestructuredContentis the array and whose text content is the pretty-printed array
Arrays are automatically wrapped in an object with a
data field. If you pass an array to object, it calls array() internally.image
Creates an image content response from base64 data or a data URL. Emits animage content item with data and mimeType, and sets _meta to { mimeType, isImage: true }. The mimeType defaults to image/png when not provided.
ReturnsstringrequiredThe image data (data URL or base64)stringdefault:"image/png"MIME type of the image (default: “image/png”)
SignatureCallToolResultResult with animagecontent item andisImagemetadata
audio
Creates an audio content response from either base64 data or a file path. The argument is treated as a file path when it contains a path separator (/ or \) or a . and is shorter than 1000 characters. In that case the file is read asynchronously and the function returns a Promise<CallToolResult>, so you must await it. Otherwise the base64 string is used directly and a synchronous CallToolResult is returned.
When a file path is read, the MIME type is taken from mimeType if provided, otherwise inferred from the file extension. The extension map covers wav (audio/wav), mp3 (audio/mpeg), ogg (audio/ogg), m4a (audio/mp4), webm (audio/webm), flac (audio/flac), and aac (audio/aac), falling back to audio/wav for anything else. On the synchronous base64 path the MIME type defaults to audio/wav. The result emits an audio content item and sets _meta to { mimeType, isAudio: true }.
ReturnsstringrequiredAudio data as a base64 string, or a path to an audio filestringMIME type (e.g. “audio/wav”). Defaults to “audio/wav” for base64 data, or is inferred from the file extension for file paths
SignatureCallToolResult | Promise<CallToolResult>Synchronous result for base64 data, or a Promise for file paths
binary
Creates a binary content response from base64-encoded data. The base64 string is placed in atext content item, _meta.mimeType is set to the provided MIME type, and _meta.isBinary is set to true. Unlike image and audio, mimeType is required.
ReturnsstringrequiredThe base64-encoded binary datastringrequiredThe MIME type of the binary content
SignatureCallToolResultResult with the base64 payload andisBinarymetadata
resource
Creates an embedded resource content item. It supports two call patterns selected at runtime:- Three arguments
resource(uri, mimeType, text): builds a resource from an explicit URI, MIME type, and text.mimeTypeandtextare only added to the embedded resource when truthy. - Two arguments
resource(uri, content): when the second argument is an object with acontentproperty (a result from another helper such astextorobject), the text is read from its firsttextcontent item and the MIME type is read from its_meta.mimeType, then re-embedded underuri.
resource content item and does not set _meta.
ReturnsstringrequiredThe resource URIstring | CallToolResult | TypedCallToolResult<any>requiredMIME type (3-arg pattern) or a helper result (2-arg pattern)stringOptional text content, only used in the 3-arg pattern
SignatureCallToolResultResult with a single embeddedresourcecontent item
mix
Combines multiple helper results into a single response. Thecontent arrays of all inputs are concatenated in order. The structuredContent objects from every input that has one are shallow-merged into a single object (added only if at least one input has structuredContent), and the _meta objects are shallow-merged the same way. Use it to return text alongside images, embedded resources, or several content items together.
ReturnsCallToolResult[]requiredThe helper results to merge, in order
SignatureCallToolResultResult with the flattened content array and mergedstructuredContentand_meta
mix() merges content arrays and combines the structuredContent and _meta objects from all inputs, allowing complex multi-part responses.error
Creates an error response. SetsisError: true and returns the message as a single text content item. The return type is TypedCallToolResult<never> so it composes with tools that declare an output schema. Does not set _meta.
ReturnsstringrequiredThe error message
SignatureTypedCallToolResult<never>Result withisError: trueand the message as text content
widget
Creates a response for a tool that renders a widget. The widget configuration (name, invoking and invoked status, and so on) is set on the tool’swidget property at registration time. widget() carries only the runtime data described by WidgetResponseConfig.
Per SEP-1865, widget data flows through standard MCP channels: tool arguments reach the widget via ui/notifications/tool-input, and the tool result (content plus structuredContent) reaches it via ui/notifications/tool-result. There is no custom mcp-use/props sideband. The fields have different visibility:
The exact build behavior:
- content: if
messageis set, content is a single text item with that message. Otherwise, ifoutputhas a non-empty content array, that content is used. Otherwise content falls back to a single empty text item. - _meta: set to
metadataonly whenmetadatahas at least one key. - structuredContent: set to
output.structuredContentwhen present, otherwise to the resolved props (propsor its deprecated aliasdata) when those have at least one key.
ReturnsWidgetResponseConfigrequiredRuntime data for the widget
SignatureCallToolResultResult withstructuredContent(props),content(the LLM-visible text), and_meta(metadata)
Types
TypedCallToolResult
A typedCallToolResult that constrains structuredContent to a specific type T. Used for output-schema validation and to give callers type inference on the structured data. T must be a record type (object) to satisfy the SDK’s CallToolResult interface, and defaults to Record<string, unknown>.
The properties are listed explicitly rather than via extends Omit<CallToolResult, "structuredContent"> to avoid breaking type inference, a known interaction between Zod .passthrough() and TypeScript Omit.
Propertiesextends Record<string, unknown>default:"Record<string, unknown>"The shape ofstructuredContent
SignatureCallToolResult['content']requiredThe content array, same shape as the SDKCallToolResultTTyped structured dataCallToolResult['isError']Error flag, same shape as the SDKCallToolResultCallToolResult['_meta']Response metadata, same shape as the SDKCallToolResultunknownIndex signature permitting additional properties
WidgetResponseConfig
Runtime configuration passed towidget. It carries only runtime data, not the widget’s registration-time configuration. All fields are optional.
SignatureRecord<string, any>Widget-only data sent asstructuredContentin the tool result. The widget receives it viaui/notifications/tool-result. Per spec,structuredContentis not added to model contextRecord<string, any>Deprecated. Legacy alias forpropsCallToolResult | TypedCallToolResult<any>Response helper result (text(),object(), and so on) that the model sees. Summarizes the tool result for the conversationRecord<string, unknown>Extra metadata sent in the tool result’s_meta. The widget receives it viauseWidget().metadata. Not added to model context. Use for pagination cursors, timestamps, and so onstringOptional override for the text message incontent. Used when you want to show different text thanoutputprovides