Skip to content

Commit 771de1d

Browse files
committed
Remove incorrectly formatted error helper
1 parent 88fce3a commit 771de1d

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package main
1919

2020
import (
2121
"context"
22+
"errors"
2223
"fmt"
2324

2425
"github.com/mark3labs/mcp-go/mcp"
@@ -53,7 +54,7 @@ func main() {
5354
func helloHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
5455
name, ok := request.Params.Arguments["name"].(string)
5556
if !ok {
56-
return mcp.NewToolResultError("name must be a string"), nil
57+
return nil, errors.New("name must be a string")
5758
}
5859

5960
return mcp.NewToolResultText(fmt.Sprintf("Hello, %s!", name)), nil
@@ -107,6 +108,7 @@ package main
107108

108109
import (
109110
"context"
111+
"errors"
110112
"fmt"
111113

112114
"github.com/mark3labs/mcp-go/mcp"
@@ -156,7 +158,7 @@ func main() {
156158
result = x * y
157159
case "divide":
158160
if y == 0 {
159-
return mcp.NewToolResultError("Cannot divide by zero"), nil
161+
return nil, errors.New("Cannot divide by zero")
160162
}
161163
result = x / y
162164
}
@@ -318,7 +320,7 @@ s.AddTool(calculatorTool, func(ctx context.Context, request mcp.CallToolRequest)
318320
result = x * y
319321
case "divide":
320322
if y == 0 {
321-
return mcp.NewToolResultError("Division by zero is not allowed"), nil
323+
return nil, errors.New("Division by zero is not allowed")
322324
}
323325
result = x / y
324326
}
@@ -363,20 +365,20 @@ s.AddTool(httpTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp
363365
req, err = http.NewRequest(method, url, nil)
364366
}
365367
if err != nil {
366-
return mcp.NewToolResultError(fmt.Sprintf("Failed to create request: %v", err)), nil
368+
return nil, fmt.Errorf("Failed to create request: %v", err)
367369
}
368370

369371
client := &http.Client{}
370372
resp, err := client.Do(req)
371373
if err != nil {
372-
return mcp.NewToolResultError(fmt.Sprintf("Request failed: %v", err)), nil
374+
return nil, fmt.Errorf("Request failed: %v", err)
373375
}
374376
defer resp.Body.Close()
375377

376378
// Return response
377379
respBody, err := io.ReadAll(resp.Body)
378380
if err != nil {
379-
return mcp.NewToolResultError(fmt.Sprintf("Failed to read response: %v", err)), nil
381+
return nil, fmt.Errorf("Failed to read response: %v", err)
380382
}
381383

382384
return mcp.NewToolResultText(fmt.Sprintf("Status: %d\nBody: %s", resp.StatusCode, string(respBody))), nil

mcp/utils.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -216,19 +216,6 @@ func NewToolResultText(text string) *CallToolResult {
216216
}
217217
}
218218

219-
// NewToolResultError creates a new CallToolResult that indicates an error
220-
func NewToolResultError(errText string) *CallToolResult {
221-
return &CallToolResult{
222-
Content: []Content{
223-
TextContent{
224-
Type: "text",
225-
Text: errText,
226-
},
227-
},
228-
IsError: true,
229-
}
230-
}
231-
232219
// NewToolResultImage creates a new CallToolResult with both text and image content
233220
func NewToolResultImage(text, imageData, mimeType string) *CallToolResult {
234221
return &CallToolResult{

0 commit comments

Comments
 (0)