Propagate HTTP backend errors to clients with full context#286
Merged
Conversation
- Modified sendHTTPRequest to return JSON-RPC error responses instead of Go errors when HTTP backends return non-200 status codes - HTTP errors (4xx, 5xx) are now properly converted to JSON-RPC error responses with status code and error body preserved - Updated unified server to check for error field in responses before attempting to unmarshal result - Updated integration test to verify error is propagated in response field rather than as Go error - Fixes issue where HTTP backend errors were converted to generic "Internal error" messages Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix HTTP error propagation from backend to client
Propagate HTTP backend errors to clients with full context
Jan 16, 2026
Collaborator
|
@copilot please create new unit and integration tests for http error propagation. also please be sure to run golangci-lint at the end. |
Created new test files: - internal/mcp/http_error_propagation_test.go: 4 test functions covering non-200 status codes, JSON-RPC errors, mixed content types, and error detail preservation - internal/server/http_error_propagation_test.go: 4 test functions covering unified server error propagation, error field checking, proxy forwarding, and data preservation All tests pass and golangci-lint reports 0 issues. Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Contributor
Author
Done! Created comprehensive tests and ran golangci-lint: New Test Files:
Test Coverage:
Results: Commit: 9dc1bc8 |
Collaborator
|
@copilot can you please fix this error make lint |
Run gofmt to fix formatting in: - internal/mcp/http_error_propagation_test.go - internal/server/http_error_propagation_test.go make lint now passes successfully. Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix HTTP Backend Error Propagation ✅
When an HTTP backend MCP server returns an error, the error is now properly propagated to the client through the gateway.
Problem Summary
HTTP backend errors (4xx, 5xx) were converted to generic "Internal error" messages, losing all original error details (status code, error body), making debugging difficult for clients.
Solution
Modified the HTTP request handling to:
Files Changed
internal/mcp/connection.go: ModifiedsendHTTPRequestto convert HTTP errors to JSON-RPC error responsesinternal/server/unified.go: Added error field checks before unmarshaling response resultstest/integration/http_error_test.go: Updated test to verify error propagation in response fieldinternal/mcp/http_error_propagation_test.go: New comprehensive unit tests (4 test functions, 13+ test cases)internal/server/http_error_propagation_test.go: New integration tests (4 test functions)Test Coverage ✅
Unit Tests (
internal/mcp/http_error_propagation_test.go):Integration Tests (
internal/server/http_error_propagation_test.go):Existing Integration Tests (all passing):
Code Quality ✅
Example Impact
Before:
{"jsonrpc":"2.0","id":1,"error":{"code":-32603,"message":"Internal error"}}After:
{ "jsonrpc": "2.0", "id": 1, "error": { "code": -32603, "message": "HTTP 503: Service Unavailable", "data": "{\"error\":\"Backend database is down\"}" } }Notes
internal/sys/sys_test.gois unrelated to these changesOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.