Skip to content

Commit 13488f7

Browse files
jbaclaude
andauthored
Export GetError and SetError methods (#753)
Exported GetError and SetError. Fixes #64 Co-authored-by: Claude <noreply@anthropic.com>
1 parent b4f957f commit 13488f7

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

mcp/mcp_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,7 +2124,7 @@ func TestToolErrorMiddleware(t *testing.T) {
21242124
res, err := h(ctx, method, req)
21252125
if err == nil {
21262126
if ctr, ok := res.(*CallToolResult); ok {
2127-
middleErr = ctr.getError()
2127+
middleErr = ctr.GetError()
21282128
}
21292129
}
21302130
return res, err
@@ -2161,7 +2161,7 @@ func TestToolErrorMiddleware(t *testing.T) {
21612161
t.Fatal("want error, got none")
21622162
}
21632163
// Clients can't see the error, because it isn't marshaled.
2164-
if err := res.getError(); err != nil {
2164+
if err := res.GetError(); err != nil {
21652165
t.Fatalf("got %v, want nil", err)
21662166
}
21672167
if middleErr != errTestFailure {

mcp/protocol.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,17 @@ type CallToolResult struct {
116116
err error
117117
}
118118

119-
// TODO(#64): consider exposing setError (and getError), by adding an error
120-
// field on CallToolResult.
121-
func (r *CallToolResult) setError(err error) {
119+
// SetError sets the error for the tool result and populates the Content field
120+
// with the error text. It also sets IsError to true.
121+
func (r *CallToolResult) SetError(err error) {
122122
r.Content = []Content{&TextContent{Text: err.Error()}}
123123
r.IsError = true
124124
r.err = err
125125
}
126126

127-
// getError returns the error set with setError, or nil if none.
127+
// GetError returns the error set with SetError, or nil if none.
128128
// This function always returns nil on clients.
129-
func (r *CallToolResult) getError() error {
129+
func (r *CallToolResult) GetError() error {
130130
return r.err
131131
}
132132

mcp/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func toolForErr[In, Out any](t *Tool, h ToolHandlerFor[In, Out]) (*Tool, ToolHan
339339
}
340340
// For regular errors, embed them in the tool result as per MCP spec
341341
var errRes CallToolResult
342-
errRes.setError(err)
342+
errRes.SetError(err)
343343
return &errRes, nil
344344
}
345345

0 commit comments

Comments
 (0)