fix: improve error handling across both MCP servers#1
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
fix: improve error handling across both MCP servers#1devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
- outlook auth: check for 'access_token' key before accessing it from
acquire_token_silent result (previously caused raw KeyError on error
responses); log warning and fall back to device flow gracefully
- outlook auth: move _save_cache after success check in device flow
(previously saved potentially corrupt cache on auth failure)
- gmail auth: catch refresh failures with actionable error message
suggesting token deletion and re-auth
- gmail.py & graph.py: catch non-JSON 2xx responses instead of letting
JSONDecodeError propagate without context
- outlook server: use safe .get('id') on createReply/createForward
responses with explicit ValueError if missing
- outlook server & gmail server: validate 'to' is provided in forward
mode before making API calls
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Summary
Several error paths silently swallowed failures or raised opaque exceptions with no actionable context. This PR fixes them across both servers:
Outlook auth (
outlook-mcp/auth.py)acquire_token_silentcan return{"error": ..., "error_description": ...}without anaccess_tokenkey — previously caused a rawKeyError. Now checks for"access_token" in resultbefore accessing it, logs the error to stderr, and falls back to device-code flow._save_cachewas called before the error check afteracquire_token_by_device_flow— a failed auth would persist corrupt cache state. Moved_save_cacheafter the success guard.Gmail auth (
gmail-mcp/auth.py)creds.refresh(Request())failure (revoked token, network error) propagated as an opaquegoogle.auth.exceptions.RefreshError. Now caught and re-raised asRuntimeErrorwith a message pointing the user to delete the token file and re-authenticate.HTTP wrappers (
gmail.py,graph.py)r.json()on a 2xx response with non-JSON body (e.g. HTML from a proxy) threw a contextlessJSONDecodeError. Now caught and re-raised with the status code and a prefix of the response body.Server tools (
outlook server.py,gmail server.py)outlook_draft:result['id']aftercreateReply/createForward→ rawKeyErrorif the Graph response lackedid. Now uses.get("id")with an explicitValueError.outlook_sendandgmail_send: forward mode accepted an emptytoand sent it to the API, producing an opaque backend error. Now validates early withValueError("'to' is required when forwarding a message").Link to Devin session: https://app.devin.ai/sessions/74827009bae543b298df6aa924affd05
Requested by: @fafaisland