MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / SetError

Method SetError

mcp/protocol.go:132–138  ·  view source on GitHub ↗

SetError sets the error for the tool result and sets IsError to true. If Content has not already been populated, it is set to the error text. If Content has already been populated, it is left unchanged, allowing callers to provide a user-friendly message while still recording the underlying error fo

(err error)

Source from the content-addressed store, hash-verified

130// To restore the previous behavior where Content was always overwritten,
131// set MCPGODEBUG=seterroroverwrite=1.
132func (r *CallToolResult) SetError(err error) {
133 if len(r.Content) == 0 || seterroroverwrite == "1" {
134 r.Content = []Content{&TextContent{Text: err.Error()}}
135 }
136 r.IsError = true
137 r.err = err
138}
139
140// GetError returns the error set with SetError, or nil if none.
141// This function always returns nil on clients.

Callers 2

toolForErrFunction · 0.95

Calls 1

ErrorMethod · 0.45

Tested by 1