Merged
Conversation
Signed-off-by: Madhav Kandukuri <madhav165@gmail.com>
Signed-off-by: Madhav Kandukuri <madhav165@gmail.com>
Signed-off-by: Madhav Kandukuri <madhav165@gmail.com>
Signed-off-by: Madhav Kandukuri <madhav165@gmail.com>
0b1b28f to
a766ad2
Compare
- Replace broad 'except Exception' with specific exceptions: ValidationError, ValueError, KeyError, TypeError, binascii.Error - Use logger.exception() instead of logger.error() to include traceback - Update e2e test to actually test corrupted data scenario by mocking convert_tool_to_read to fail for one tool while succeeding for others This addresses concerns that broad exception catching could mask DB/session errors or programming bugs. Now only data validation errors are caught and logged, while unexpected errors will properly propagate. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Add e2e tests verifying graceful error handling for: - Resources listing - Prompts listing - Servers listing - Gateways listing - A2A agents listing Each test creates entities, mocks the convert_*_to_read method to fail for one entity, and verifies: 1. API returns 200 status 2. Valid entities are in the response 3. Corrupted entity is excluded from the response This provides comprehensive test coverage for the graceful error handling pattern across all entity types. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
a766ad2 to
77a58ff
Compare
crivetimihai
approved these changes
Jan 20, 2026
kcostell06
pushed a commit
to kcostell06/mcp-context-forge
that referenced
this pull request
Feb 24, 2026
* Fix listing loops Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> * Fix more calls to convert to read functions Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> * Wrap all convert to read calls in try catch Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> * Add additional tests Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> * fix: Narrow exception handling to specific data validation errors - Replace broad 'except Exception' with specific exceptions: ValidationError, ValueError, KeyError, TypeError, binascii.Error - Use logger.exception() instead of logger.error() to include traceback - Update e2e test to actually test corrupted data scenario by mocking convert_tool_to_read to fail for one tool while succeeding for others This addresses concerns that broad exception catching could mask DB/session errors or programming bugs. Now only data validation errors are caught and logged, while unexpected errors will properly propagate. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * test: Add failure-path tests for all entity types Add e2e tests verifying graceful error handling for: - Resources listing - Prompts listing - Servers listing - Gateways listing - A2A agents listing Each test creates entities, mocks the convert_*_to_read method to fail for one entity, and verifies: 1. API returns 200 status 2. Valid entities are in the response 3. Corrupted entity is excluded from the response This provides comprehensive test coverage for the graceful error handling pattern across all entity types. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
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.
🐛 Bug-fix PR
Closes #2172
📌 Summary
Fixes a bug where a single entity with corrupted data would cause the entire listing operation to fail. When
convert_*_to_readfunctions encountered invalid data (e.g., malformed JSON inauth_value, missing required fields), the exception would propagate up and return a 500 error instead of gracefully returning the valid entities.🔁 Reproduction Steps
Issue: Parsing failures in entity conversion stops entire listing
auth_valuefield)/admin/tools,/tools/list, etc.)🐞 Root Cause
The
convert_*_to_readfunctions (e.g.,convert_tool_to_read,convert_resource_to_read,convert_prompt_to_read) were called without exception handling in listing loops. When Pydantic validation failed for any single entity, the exception would bubble up and abort the entire operation.Affected locations:
mcpgateway/services/tool_service.py-list_tools,list_server_tools,list_tools_for_usermcpgateway/services/resource_service.py- resource listing methodsmcpgateway/services/prompt_service.py- prompt listing methodsmcpgateway/routers/admin.py- admin API endpoints💡 Fix Description
Wrapped all
convert_*_to_readcalls in try-except blocks to handle conversion failures gracefully:Key design points:
🧪 Verification
make lintmake test📐 MCP Compliance (if relevant)
✅ Checklist
make black isort pre-commit)