Skip to content

Conversation

@Jayyk09
Copy link
Contributor

@Jayyk09 Jayyk09 commented Feb 1, 2026

Description

This pull request extends the Gmail MCP server refactoring by adding structured error handling, input validation utilities, and documentation improvements.

This expands on PR #958 to improve upon error handling and explicit checks for ids, permissions and email addresses before tools are called. Uses basic regex pattern search and adds actionable items based on Error Status for users.

Should only be merged after PR 958

Key Changes

Code Organization:

  • utils.ts: Adds error handling and validation modules
  • index.ts (refactored): Updated imports to use new modules, wired in structured error handling and validation

Error Handling (utils.ts):

  • GmailErrorType enum covering auth, quota, rate limit, validation, and API error categories
  • GmailMCPError custom error class with structured type, status code, and context
  • parseGoogleApiError() — maps Google API HTTP errors to typed GmailMCPError instances
  • parseZodError() — converts Zod validation failures into user-friendly error messages
  • formatGmailError() / addErrorGuidance() — formats errors with actionable guidance for LLM consumers

Validation (utils.ts):

  • validateEmailAddresses() — validates recipient email format before API calls
  • validateId() — validates Gmail message/thread IDs

Related issue

Type of change

  • New MCP feature (non-breaking change which adds functionality)

How has this been tested?

  • Build passes locally
  • All 10 Gmail tools verified functional
  • Manual testing. Attached screenshots below. No breaking changes
Screenshot 2026-01-31 at 6 23 16 PM Screenshot 2026-01-31 at 6 36 32 PM

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Extract type definitions (GmailMessagePart, EmailAttachment, EmailContent) and
Zod schemas (SendEmailSchema, ReadEmailSchema, etc.) into a dedicated module
for better code organization and maintainability.
Consolidate utility functions into a dedicated module:
- Email utilities (createEmailMessage, validateEmail, encodeEmailHeader)
- PDF extraction using pdfjs-dist (Mozilla PDF.js) for better compatibility
- DOCX extraction using mammoth
- XLSX extraction using exceljs
- Base64 conversion utilities
- Email content extraction from MIME parts
- Batch processing utilities with fallback handling
- Contact search warmup functionality
- Update imports to use schemas.js and utils.js
- Remove inline type definitions (moved to schemas.ts)
- Remove inline utility functions (moved to utils.ts)
- Remove inline Zod schemas (moved to schemas.ts)
- Add express.json() middleware for proper request body parsing
- Add await to asyncLocalStorage.run() for proper async handling
All functionality has been migrated to utils.ts with the proper naming
convention. The utl.ts file is no longer needed.
Add a table listing all available MCP tools with their names and
descriptions for easier reference.
Add GmailErrorType enum, GmailMCPError class, error parsing functions
(parseGoogleApiError, parseZodError), error formatting with guidance,
and input validation helpers (validateEmailAddresses, validateId,
validateIds, validateApiResponse, sanitizeEmailContent).
Add input validation to handleEmailAction (email addresses, thread ID),
replace generic catch block with structured error classification
(GmailMCPError / ZodError / Google API error), and log typed error
details to console.
@Jayyk09 Jayyk09 changed the title feat(gmail): improve error logging in the serve feat(gmail): improve error logging for pre-tool-calling checks Feb 1, 2026
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