-
Notifications
You must be signed in to change notification settings - Fork 3
Propagate HTTP backend errors to clients with full context #286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 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>
Done! Created comprehensive tests and ran golangci-lint: New Test Files:
Test Coverage:
Results: Commit: 9dc1bc8 |
|
@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>
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.