Fix malformed mcp.json error handling in ACP #153
Merged
+118
−7
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.
Description
This PR fixes issue #151 where malformed
mcp.jsonconfiguration file errors were silently swallowed in ACP (Agent Client Protocol), providing no feedback to users.Problem
When users had a malformed
mcp.jsonfile:This created a poor user experience for editor/IDE users (VS Code, Cursor, etc.) who wouldn't know why their MCP servers weren't loading.
Solution
Changes Made
Created custom exception (
MCPConfigurationErrorinstore.py)Updated
AgentStore.load_mcp_configuration()(instore.py)MCPConfigurationErrorinstead of silently returning{}{}when file doesn't exist (valid case)Updated
agent.py::_setup_acp_conversation()MCPConfigurationErrorRequestError.invalid_paramswith helpful messageAdded comprehensive test coverage (in
test_agent.py)User Impact
Before ❌
After ✅
Testing
All tests pass:
test_mcp_config_validation.py)test_agent.py)Test Coverage
Example Error Message
When a user has malformed
mcp.json, they now see:{ "code": -32602, "message": "Invalid params", "data": { "reason": "Invalid MCP configuration file", "details": "Invalid JSON: trailing characters at line 20 column 1", "help": "Please check ~/.openhands/mcp.json for JSON syntax errors" } }Benefits
Checklist
Fixes #151
@neubig can click here to continue refining the PR
🚀 Try this PR