Skip to content

fix: improve error handling across both MCP servers#1

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1781199262-improve-error-handling
Open

fix: improve error handling across both MCP servers#1
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1781199262-improve-error-handling

Conversation

@devin-ai-integration

Copy link
Copy Markdown

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_silent can return {"error": ..., "error_description": ...} without an access_token key — previously caused a raw KeyError. Now checks for "access_token" in result before accessing it, logs the error to stderr, and falls back to device-code flow.
  • _save_cache was called before the error check after acquire_token_by_device_flow — a failed auth would persist corrupt cache state. Moved _save_cache after the success guard.

Gmail auth (gmail-mcp/auth.py)

  • creds.refresh(Request()) failure (revoked token, network error) propagated as an opaque google.auth.exceptions.RefreshError. Now caught and re-raised as RuntimeError with 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 contextless JSONDecodeError. 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'] after createReply/createForward → raw KeyError if the Graph response lacked id. Now uses .get("id") with an explicit ValueError.
  • outlook_send and gmail_send: forward mode accepted an empty to and sent it to the API, producing an opaque backend error. Now validates early with ValueError("'to' is required when forwarding a message").

Link to Devin session: https://app.devin.ai/sessions/74827009bae543b298df6aa924affd05
Requested by: @fafaisland

- 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>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant