resultutil

package
v0.1.0-rc.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unwrap

func Unwrap[T any](r *Result) (T, error)

Unwrap returns the typed data and error. If the result contains an error, it returns zero value of T and the error. If successful, it returns the data cast to type T and nil error.

Types

type Result

type Result struct {
	// Data holds the structured result data (only set for successful results)
	Data any
	// JSONText holds the JSON string representation of Data
	JSONText string
	// Error holds any error that occurred (nil for successful results)
	Error error
}

Result represents a common tool execution result that can be converted to either MCP or Toolset result types.

func NewErrorResult

func NewErrorResult(err error) *Result

NewErrorResult creates an error result with the given error.

func NewSuccessResult

func NewSuccessResult(data any) *Result

NewSuccessResult creates a successful result with structured data. The data will be automatically marshaled to JSON. If marshaling fails, an error result is returned instead.

func (*Result) IsError

func (r *Result) IsError() bool

IsError returns true if the result represents an error.

func (*Result) ToMCPResult

func (r *Result) ToMCPResult() (*mcp.CallToolResult, error)

ToMCPResult converts the Result to an MCP CallToolResult. Returns (result, nil) following the MCP pattern where errors are encoded in the result, not the error return value.

func (*Result) ToToolsetResult

func (r *Result) ToToolsetResult() (*api.ToolCallResult, error)

ToToolsetResult converts the Result to a Toolset ToolCallResult. Returns (result, nil) following the pattern where errors are encoded in the ToolCallResult, not the error return value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL