Skip to content

[BUG]: Single entity parsing failure stops entire listing operation #2172

@madhav165

Description

@madhav165

Bug Summary

When listing tools, resources, prompts, servers, gateways, or A2A agents, if any single entity fails to parse/convert, the entire listing operation fails and returns zero results. This affects both MCP protocol endpoints (/sse, /mcp) and the Admin UI.

Symptoms

  • Connecting to gateway with /sse or /mcp returns no tools when any tool has parsing issues
  • Admin UI shows tools only up to the point of failure (e.g., stops at 50 tools)
  • Pagination controls don't accurately reflect the total number of entities
  • No error indication to the user about which entity caused the failure

Root Cause

The entity listing methods iterate over database results and convert each to a read model without per-item error handling:

# Example from tool_service.py:1792-1793
result = []
for s in tools_db:
    result.append(self.convert_tool_to_read(s, include_metrics=False, include_auth=False))

If convert_tool_to_read() raises an exception on any single tool, the loop terminates immediately and no results are returned.

Failure Points in Conversion Methods

For tools specifically (convert_tool_to_read() lines 636-716):

  1. decode_auth(tool.auth_value) - AES-GCM decryption failures on corrupted auth
  2. base64.b64decode() and string parsing for basic auth credentials
  3. next(iter(decoded_auth_value)) - empty dict for authheaders type
  4. ToolRead.model_validate(tool_dict) - Pydantic schema validation failures

Similar conversion methods exist for other entity types with their own potential failure points.

Affected Code Locations

Service File Line Method
Tools mcpgateway/services/tool_service.py 1792 list_tools()
Tools mcpgateway/services/tool_service.py 1918 list_server_tools()
Tools mcpgateway/services/tool_service.py 2045 list_tools_for_user()
Resources mcpgateway/services/resource_service.py 1057 list_resources()
Prompts mcpgateway/services/prompt_service.py 1064 list_prompts()
Servers mcpgateway/services/server_service.py 834 list_servers()
Gateways mcpgateway/services/gateway_service.py 1433 list_gateways()
A2A Agents mcpgateway/services/a2a_service.py 651 list_a2a_agents()

Proposed Fix

Wrap each entity conversion in a try-except block to allow partial results and log failures:

result = []
for s in tools_db:
    try:
        result.append(self.convert_tool_to_read(s, include_metrics=False, include_auth=False))
    except Exception as e:
        logger.error(f"Failed to convert tool {getattr(s, 'id', 'unknown')} ({getattr(s, 'name', 'unknown')}): {e}")
        # Continue with remaining tools instead of failing completely

This ensures:

  • Users see all valid entities even when some are corrupted
  • Errors are logged with entity identification for debugging
  • The system degrades gracefully rather than failing completely

Impact

  • High: Affects core functionality of tool/resource/prompt discovery
  • User-facing: Both API clients and Admin UI users experience silent failures
  • Data integrity: Corrupted entities can block access to all other valid entities

Labels

bug, high-priority, services, mcp-protocol, admin-ui

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions