Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,13 +826,14 @@ func handleToolCallJSONRPC(connID string, req *jsonRPCRequest, toolSet *mcp.Tool
log.Printf("Received response body for tool '%s': %s", params.ToolName, string(bodyBytes))
// Check status code for API-level errors
if httpResp.StatusCode < 200 || httpResp.StatusCode >= 300 {
// Put error details into the Content field so MCP clients can access them
errText := fmt.Sprintf("Tool '%s' API call failed with status %s: %s", params.ToolName, httpResp.Status, string(bodyBytes))
resultPayload = ToolResultPayload{
IsError: true,
Error: &MCPError{
Code: httpResp.StatusCode,
Message: fmt.Sprintf("Tool '%s' API call failed with status %s", params.ToolName, httpResp.Status),
Data: string(bodyBytes), // Include response body in error data
},
Content: []ToolResultContent{{
Type: "text",
Text: errText,
}},
ToolCallID: fmt.Sprintf("%v", req.ID),
}
} else {
Expand Down
14 changes: 7 additions & 7 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ func TestHttpMethodPostHandler(t *testing.T) {
expectedSyncStatus: http.StatusAccepted,
expectedSyncBody: "Request accepted, response will be sent via SSE.\n",
checkAsyncResponse: func(t *testing.T, resp jsonRPCResponse) {
assert.Equal(t, "call-post-err-1", resp.ID)
assert.Nil(t, resp.Error)
resultPayload, ok := resp.Result.(ToolResultPayload)
require.True(t, ok)
assert.True(t, resultPayload.IsError)
require.NotNil(t, resultPayload.Error)
assert.Contains(t, resultPayload.Error.Message, "operation details for tool 'nonexistent_tool' not found")
assert.Equal(t, "call-post-err-1", resp.ID)
assert.Nil(t, resp.Error)
resultPayload, ok := resp.Result.(ToolResultPayload)
require.True(t, ok)
assert.True(t, resultPayload.IsError)
require.NotNil(t, resultPayload.Error)
assert.Contains(t, resultPayload.Error.Message, "operation details for tool 'nonexistent_tool' not found")
},
},
{
Expand Down
Loading