Skip to content

Commit 4e00f7d

Browse files
authored
feat(mcp): add NewToolResultErrorf (#357)
1 parent 4b71176 commit 4e00f7d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

mcp/utils.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,21 @@ func NewToolResultErrorFromErr(text string, err error) *CallToolResult {
327327
}
328328
}
329329

330+
// NewToolResultErrorf creates a new CallToolResult with an error message.
331+
// The error message is formatted using the fmt package.
332+
// Any errors that originate from the tool SHOULD be reported inside the result object.
333+
func NewToolResultErrorf(format string, a ...any) *CallToolResult {
334+
return &CallToolResult{
335+
Content: []Content{
336+
TextContent{
337+
Type: "text",
338+
Text: fmt.Sprintf(format, a...),
339+
},
340+
},
341+
IsError: true,
342+
}
343+
}
344+
330345
// NewListResourcesResult creates a new ListResourcesResult
331346
func NewListResourcesResult(
332347
resources []Resource,

0 commit comments

Comments
 (0)