diff --git a/pkg/server/server.go b/pkg/server/server.go index a8580df..708b242 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -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 { diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index 86421b9..3ea4e51 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -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") }, }, {