Skip to content
Merged
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
14 changes: 14 additions & 0 deletions internal/mcp/mcp_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func DecodeToolResponse(resp *http.Response) (map[string]json.RawMessage, error)
Result struct {
Content []json.RawMessage `json:"content"`
StructuredContent map[string]json.RawMessage `json:"structuredContent"`
IsError bool `json:"isError"`
} `json:"result"`
Error *struct {
Code int `json:"code"`
Expand All @@ -124,6 +125,19 @@ func DecodeToolResponse(resp *http.Response) (map[string]json.RawMessage, error)
return nil, errors.Newf("MCP tools/call failed: %d %s", jsonRPCResp.Error.Code, jsonRPCResp.Error.Message)
}

if jsonRPCResp.Result.IsError {
if len(jsonRPCResp.Result.Content) > 0 {
var textContent struct {
Text string `json:"text"`
}
if err := json.Unmarshal(jsonRPCResp.Result.Content[0], &textContent); err == nil && textContent.Text != "" {
return nil, errors.Newf("MCP tool error: %s", textContent.Text)
}
return nil, errors.Newf("MCP tool error: %s", string(jsonRPCResp.Result.Content[0]))
}
return nil, errors.New("MCP tool returned an error")
}

return jsonRPCResp.Result.StructuredContent, nil
}
func readSSEResponseData(resp *http.Response) ([]byte, error) {
Expand Down
Loading