Commit Graph

973 Commits

Author SHA1 Message Date
Josh Dzielak
ee1db221af Add HTTP URL-based attachment serving for Gmail attachments
This commit implements a new feature that allows Gmail attachments to be
served via HTTP URLs instead of returning base64-encoded data in the tool
response. This avoids consuming LLM context window space and token budgets
for large attachments.

Architecture:
-------------
The implementation works in both stdio and streamable-http transport modes:

1. Temp File Storage (core/attachment_storage.py):
   - New AttachmentStorage class manages temporary file storage in ./tmp/attachments/
   - Uses UUID-based file IDs to prevent guessing/unauthorized access
   - Tracks metadata: filename, mime type, size, creation/expiration times
   - Files expire after 1 hour (configurable) with automatic cleanup support
   - Handles base64 decoding and file writing

2. HTTP Route Handlers:
   - Added /attachments/{file_id} route to main FastMCP server (streamable-http mode)
   - Added same route to MinimalOAuthServer (stdio mode)
   - Both routes serve files with proper Content-Type headers via FileResponse
   - Returns 404 for expired or missing attachments

3. Modified get_gmail_attachment_content():
   - Now saves attachments to temp storage and returns HTTP URL
   - Attempts to fetch filename/mimeType from message metadata (best effort)
   - Handles stateless mode gracefully (skips file saving, shows preview)
   - Falls back to base64 preview if file saving fails
   - URL generation respects WORKSPACE_EXTERNAL_URL for reverse proxy setups

Key Features:
-------------
- Works in both stdio and streamable-http modes (uses existing HTTP servers)
- Respects stateless mode (no file writes when WORKSPACE_MCP_STATELESS_MODE=true)
- Secure: UUID-based file IDs prevent unauthorized access
- Automatic expiration: Files cleaned up after 1 hour
- Reverse proxy support: Uses WORKSPACE_EXTERNAL_URL if configured
- Graceful degradation: Falls back to preview if storage fails

Benefits:
---------
- Avoids context window bloat: Large attachments don't consume LLM tokens
- Better performance: Clients can stream/download files directly
- More efficient: No need to decode base64 in client applications
- Works across network boundaries: URLs accessible from any client

The feature maintains backward compatibility - if file saving fails or stateless
mode is enabled, the function falls back to showing a base64 preview.
2025-12-04 16:37:10 +01:00
Taylor Wilsdon
0402b1a0b8 chore: release v1.6.0 2025-11-28 14:14:16 -05:00
Taylor Wilsdon
1ce2f068af Merge pull request #285 from taylorwilsdon/fix_require_multiple_services
fix: better approach for issues/244
2025-11-28 14:13:37 -05:00
Taylor Wilsdon
705cf20044 better approach 2025-11-28 13:53:34 -05:00
Taylor Wilsdon
5183aef08e Merge pull request #272 from silarsis/main
Issue #269 - supporting shortcuts
2025-11-25 17:14:19 -05:00
Kevin Littlejohn
c9d4cd803c Remove extra_fields from resolve_drive_item call
Removed the extra_fields parameter from resolve_drive_item call.
2025-11-25 13:43:48 +08:00
Kevin Littlejohn
6c06e90123 Fix formatting issue in drive_tools.py 2025-11-25 13:36:02 +08:00
Taylor Wilsdon
7936097b7b merge main 2025-11-16 14:22:06 -05:00
Taylor Wilsdon
d470fbdd13 Merge branch 'main' of github.com:taylorwilsdon/google_workspace_mcp into silarsis/main 2025-11-16 14:22:02 -05:00
Taylor Wilsdon
bf99eabe0b Merge pull request #275 from taylorwilsdon/issues/274
fix: fix media calls
2025-11-12 12:00:06 -05:00
Taylor Wilsdon
fd26e4037a fix media calls 2025-11-12 11:54:55 -05:00
Kevin Littlejohn
cbeabb36a1 Remove shortcut_resolution patch artifact 2025-11-11 16:44:39 +08:00
Kevin Littlejohn
55dfba3d83 Handle Drive shortcuts transparently 2025-11-11 16:43:00 +08:00
Taylor Wilsdon
973f921c32 chore: release v1.5.5 2025-11-10 11:17:44 -05:00
Taylor Wilsdon
78a458b226 dxt update 2025-11-10 11:17:37 -05:00
Taylor Wilsdon
d0faa593e9 Merge pull request #270 from yairwein/main
feat: Add support for file:// URLs in create_drive_file
2025-11-10 11:17:04 -05:00
Taylor Wilsdon
72dd6330b6 Merge branch 'main' of github.com:taylorwilsdon/google_workspace_mcp into yairwein/main 2025-11-10 11:14:53 -05:00
Taylor Wilsdon
f9fdb94529 add streamable http check 2025-11-10 11:13:47 -05:00
Taylor Wilsdon
9f969f05a5 ruff 2025-11-10 11:03:44 -05:00
Taylor Wilsdon
b3efc76399 address feedback 2025-11-10 11:03:38 -05:00
Taylor Wilsdon
4c92a542da Merge pull request #266 from benjaminjackson/fix/add-to-cc-metadata-fields
fix(gmail): add To and Cc fields to message metadata responses
2025-11-10 10:56:16 -05:00
Taylor Wilsdon
d8c0e719df Merge pull request #268 from cfdude/feat/update-drive-file-tool
feat(drive): add update_drive_file tool for comprehensive file metadata management
2025-11-10 10:55:49 -05:00
Taylor Wilsdon
902ca92bb6 address feedback 2025-11-10 10:54:38 -05:00
Yair Weinberger
12e2be0807 feat: Add support for file:// URLs in create_drive_file
Added ability to upload local files to Google Drive using file:// URL scheme
in the create_drive_file tool. This enables uploading files from /tmp and
other local paths without requiring HTTP/HTTPS hosting.

Changes:
- Added urllib.parse.urlparse and pathlib.Path imports
- Detect file:// URLs and read directly from local filesystem
- Validate file exists before attempting upload
- Updated docstring to reflect support for file://, http://, and https://
- Added error handling for unsupported URL schemes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 17:12:26 +00:00
Rob Sherman
541677388b feat(drive): implement update_drive_file function with OAuth scope fix
- Added comprehensive update_drive_file function to modify Google Drive file metadata
- Fixed OAuth scope issue by using 'drive_file' instead of non-existent 'drive_write'
- Supports moving files, renaming, updating descriptions, managing sharing permissions
- Includes support for custom properties and file status (starred/trashed)
- Updated README.md and tool_tiers.yaml documentation
- Successfully tested with all parameters

Fixes #220 (OAuth stdio mode authentication issues)
2025-11-05 22:58:44 -08:00
Benjamin Jackson
ca61416acb fix(gmail): add To and Cc fields to message metadata responses
Previously, the metadataHeaders parameter only requested Subject and
From fields from the Gmail API, even though To and Cc are standard
metadata fields. This updates all metadata API calls to include To
and Cc in both single message and batch operations.

Changes:
- Updated metadataHeaders to include To, Cc in all API calls
- Extended _extract_headers() calls to request To, Cc
- Updated response formatting to display To, Cc fields
- Handles missing To/Cc gracefully with empty strings
- Updated docstrings to reflect new fields in responses

Affected functions:
- get_gmail_message_content() (gmail/gmail_tools.py:369-457)
- get_gmail_messages_content_batch() (gmail/gmail_tools.py:463-638)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 16:40:04 -05:00
Taylor Wilsdon
c7b1a633d1 Merge pull request #264 from taylorwilsdon/all_drive_support
enh: All Drive API operations now include supportsAllDrives=True
2025-11-04 11:20:35 -05:00
Taylor Wilsdon
332bc9c9ae Update README.md 2025-11-04 11:17:00 -05:00
Taylor Wilsdon
9b873092b2 remove alldrives from comments 2025-11-04 11:02:20 -05:00
Taylor Wilsdon
01a0de105a trailing comma 2025-11-04 10:39:53 -05:00
Taylor Wilsdon
8363ae1c06 add additional bits 2025-11-04 10:36:49 -05:00
Taylor Wilsdon
24d79ab470 All Drive API operations now include supportsAllDrives=True 2025-11-04 10:19:37 -05:00
Taylor Wilsdon
7ac9087939 Update README.md 2025-11-03 12:21:20 -05:00
Taylor Wilsdon
2fc133ec5a Update README.md 2025-11-03 12:20:42 -05:00
Taylor Wilsdon
a9625dd71a update dxt 2025-11-02 08:44:08 -05:00
Taylor Wilsdon
e9e8c40ab7 chore: release v1.5.4 2025-11-02 08:43:15 -05:00
Taylor Wilsdon
ee6242627b bump vers 2025-11-02 08:43:06 -05:00
Taylor Wilsdon
6691de4ccf chore: release v1.5.3 2025-11-02 08:42:57 -05:00
Taylor Wilsdon
64d4050bda Merge pull request #237 from olivermdb/fix-gmail-attachment-ephemeral-ids
Add Gmail attachment support with ephemeral ID handling
2025-11-02 08:40:18 -05:00
Taylor Wilsdon
3b9805a5b7 Merge pull request #248 from yairwein/main
feat: add external OAuth 2.1 provider mode for bearer token authentic…
2025-11-02 08:04:29 -05:00
Taylor Wilsdon
6833ebd70b populate synthetic token object 2025-11-02 08:03:50 -05:00
Taylor Wilsdon
39bea59f40 Merge branch 'main' of github.com:taylorwilsdon/google_workspace_mcp into yairwein/main 2025-11-02 08:03:32 -05:00
Taylor Wilsdon
519434e7bd Merge pull request #249 from loserbcc/fix/gmail-from-header-bug
Fix: Gmail send_message now respects user_google_email for From header
2025-11-02 08:01:14 -05:00
Taylor Wilsdon
c45ddeba7e Update README.md 2025-11-01 19:59:49 -04:00
LoserBcc
2d4a2baefd Fix: Gmail send_message now respects user_google_email for From header
## Problem
Emails sent via send_gmail_message were always showing as from a default
user account regardless of which account was specified in the
user_google_email parameter.

## Root Cause
The _prepare_gmail_message() function was not setting the From header in
the MIME message. Gmail API defaults to the primary send-as address when
no From header is provided.

## Solution
- Added from_email parameter to _prepare_gmail_message()
- Set From header explicitly: message["From"] = from_email
- Updated send_gmail_message() to pass user_google_email as from_email
- Updated draft_gmail_message() to pass user_google_email as from_email
- Capitalized MIME headers (Subject, From, To, Cc, Bcc) per conventions

## Testing
Verified emails now correctly show sender address for multiple accounts.
Each account now properly displays its own address in the From field.

Fixes multi-account email sending functionality.
2025-10-24 21:40:36 -04:00
Yair Weinberger
241f0987ae feat: add external OAuth 2.1 provider mode for bearer token authentication
Add support for external OAuth 2.1 provider mode where authentication
is handled by external systems that issue Google OAuth access tokens.

**Changes:**

1. **New Environment Variable: `EXTERNAL_OAUTH21_PROVIDER`**
   - Enables external OAuth mode when set to `true`
   - Requires `MCP_ENABLE_OAUTH21=true`
   - Disables protocol-level auth (MCP handshake/tools list work without auth)
   - Requires bearer tokens in Authorization headers for tool calls

2. **New File: `auth/external_oauth_provider.py`**
   - Custom provider extending FastMCP's GoogleProvider
   - Handles ya29.* Google OAuth access tokens
   - Validates tokens via google-auth library + userinfo API
   - Returns properly formatted AccessToken objects

3. **Modified: `auth/oauth_config.py`**
   - Add `external_oauth21_provider` config option
   - Validation that external mode requires OAuth 2.1
   - Helper methods for checking external provider mode

4. **Modified: `core/server.py`**
   - Use ExternalOAuthProvider when external mode enabled
   - Use standard GoogleProvider otherwise
   - Set server.auth = None for external mode (no protocol auth)

5. **Modified: `README.md`**
   - New "External OAuth 2.1 Provider Mode" section
   - Usage examples and configuration
   - Added to environment variables table

**How It Works:**
- MCP handshake and tools/list do NOT require authentication
- Tool calls require `Authorization: Bearer ya29.xxx` headers
- Tokens validated by calling Google's userinfo API
- Multi-user support via per-request authentication
- Stateless-compatible for containerized deployments

**Use Cases:**
- Integrating with existing authentication systems
- Custom OAuth flows managed by your application
- API gateways handling authentication upstream
- Multi-tenant SaaS with centralized auth
- Mobile/web apps with their own OAuth implementation

**Example Configuration:**
```bash
export MCP_ENABLE_OAUTH21=true
export EXTERNAL_OAUTH21_PROVIDER=true
export GOOGLE_OAUTH_CLIENT_ID=your_client_id
export GOOGLE_OAUTH_CLIENT_SECRET=your_client_secret
export WORKSPACE_MCP_STATELESS_MODE=true  # Optional
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-24 15:43:29 +03:00
Taylor Wilsdon
ec41ba18c9 fix type hints 2025-10-23 14:49:47 -04:00
Taylor Wilsdon
a14ee47ee8 Merge branch 'main' of github.com:taylorwilsdon/google_workspace_mcp into fix-gmail-attachment-ephemeral-ids 2025-10-23 14:39:55 -04:00
Taylor Wilsdon
95d5c8b4ad remove mcpo 2025-10-19 16:18:42 -04:00
Taylor Wilsdon
d4b7cab7ab update dxt 2025-10-19 16:17:06 -04:00