Skip to content

Commit e249f27

Browse files
authored
bugfix/github mcp crash (#19)
* Enhance error handling in MCP client and server for OAuth authentication - Implemented comprehensive error classification for OAuth-related issues in the MCPProxyServer and Client. - Refactored error handling to provide user-friendly messages and recovery instructions for various OAuth scenarios. - Added safety checks and logging enhancements during Dynamic Client Registration to improve robustness and traceability. * Enhance OAuth error handling and logging in client connection - Improved validation and diagnostics for OAuth handler state before proceeding with Dynamic Client Registration. - Added detailed logging for metadata investigation and potential OAuth endpoints. - Enhanced error classification and user-friendly messages for various OAuth scenarios, including unsupported DCR and metadata unavailability. - Implemented cleanup and recovery instructions to guide users through OAuth setup failures. * Enhance error handling and logging for tool calls in MCPProxyServer and Client - Improved error messages with enriched context for OAuth-related issues, connection errors, and permission denials. - Refactored error handling in CallTool methods to provide clearer guidance and recovery instructions. - Removed deprecated error classification function to streamline code and improve maintainability.
1 parent 88472ca commit e249f27

File tree

3 files changed

+453
-64
lines changed

3 files changed

+453
-64
lines changed

internal/server/mcp.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ func (p *MCPProxyServer) handleCallTool(ctx context.Context, request mcp.CallToo
421421
// Call tool via upstream manager
422422
result, err := p.upstreamManager.CallTool(ctx, toolName, args)
423423
if err != nil {
424+
// Errors are now enriched at their source with context and guidance
424425
// Log error with additional context for debugging
425426
p.logger.Error("Tool call failed",
426427
zap.String("tool_name", toolName),
@@ -429,19 +430,7 @@ func (p *MCPProxyServer) handleCallTool(ctx context.Context, request mcp.CallToo
429430
zap.String("server_name", serverName),
430431
zap.String("actual_tool", actualToolName))
431432

432-
// Provide clear error messages based on error type
433-
var errorMsg string
434-
if strings.Contains(err.Error(), "no connected client found") {
435-
errorMsg = fmt.Sprintf("Server '%s' does not exist or is not configured. Available proxy tools: upstream_servers, retrieve_tools, read_cache, call_tool. Use 'upstream_servers' with operation 'list' to see configured upstream servers.", serverName)
436-
} else if strings.Contains(err.Error(), "client for server") && strings.Contains(err.Error(), "is not connected") {
437-
errorMsg = fmt.Sprintf("Server '%s' is currently disconnected or in connecting state. Check server configuration and connectivity.", serverName)
438-
} else if strings.Contains(err.Error(), "client not connected") {
439-
errorMsg = fmt.Sprintf("Server '%s' is not connected. The server may be starting up, experiencing connection issues, or may be misconfigured.", serverName)
440-
} else {
441-
errorMsg = fmt.Sprintf("Tool call to '%s:%s' failed: %v", serverName, actualToolName, err)
442-
}
443-
444-
return mcp.NewToolResultError(errorMsg), nil
433+
return mcp.NewToolResultError(err.Error()), nil
445434
}
446435

447436
// Increment usage stats

0 commit comments

Comments
 (0)