Commit Graph

200 Commits

Author SHA1 Message Date
sam-ent
12dca1e750 Fix Apps Script integration with main server
- Add appscript to --tools CLI choices, tool_imports, and tool_icons
- Add script service to SERVICE_CONFIGS in service_decorator
- Add script scope imports and SCOPE_GROUPS mappings
- Fix variable shadowing in _get_script_project_impl

These changes complete the Apps Script integration by adding the
missing wiring in main.py and service_decorator.py that was needed
to make the feature functional.
2026-01-13 22:11:35 +00:00
sam-ent
f5702b32b8 Implement Google Apps Script integration
Core implementation:
- Added OAuth scopes for Apps Script API (auth/scopes.py)
- Created gappsscript module with 11 tools
- Implemented 6 core tools (list, get, create, update, run)
- Implemented 5 extended tools (deployments, processes)
- Added tool tier definitions to tool_tiers.yaml

Tools follow existing patterns:
- Async with asyncio.to_thread for API calls
- Proper decorator chain (@server.tool, @handle_http_errors, @require_google_service)
- Formatted string outputs for user readability
- Comprehensive logging

All tools tested for pattern compliance with existing codebase.
2026-01-13 19:20:40 +00:00
Olivier Schiavo
2cdc55ac7d fix_start_google_auth 2026-01-12 16:05:32 +01:00
Dmytro Dziuma
0d4394ae27 feat: implement --read-only mode with tool filtering
- Adds --read-only CLI flag to restrict OAuth scopes to read-only permissions
- Implements dynamic tool filtering to disable tools requiring write permissions when in read-only mode
- Updates auth/scopes.py to manage read-only scope mappings
- Enhances @require_google_service and handle_http_errors decorators to propagate scope metadata
- Updates documentation in README.md
2025-12-30 22:08:11 +00:00
Taylor Wilsdon
6b8352a354 apply ruff formatting 2025-12-13 13:49:28 -08:00
Taylor Wilsdon
2cbeaa5a13 Add Gmail filter management tools 2025-12-13 13:40:05 -08:00
Taylor Wilsdon
3adcbcd0f6 Merge pull request #288 from joshed-io/feat/gmail-attachment-http-serving
Add HTTP URL-based Attachment Serving for Gmail Attachments
2025-12-08 09:49:36 -05:00
Taylor Wilsdon
a60a556359 token refresh uses the embedded creds with optional client secret path 2025-12-08 09:35:40 -05:00
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
705cf20044 better approach 2025-11-28 13:53:34 -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
6833ebd70b populate synthetic token object 2025-11-02 08:03:50 -05: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
b0f04eff69 more feedback 2025-10-18 13:44:31 -04:00
Taylor Wilsdon
f70da12dfd review comments 2025-10-18 13:19:24 -04:00
Taylor Wilsdon
33b41a59d8 timezone awareness handling improvements and tasks fix 2025-10-18 13:01:43 -04:00
Taylor Wilsdon
923df7eca5 refactor oauth2.1 support to fastmcp native 2025-10-05 18:00:10 -04:00
Taylor Wilsdon
1e9feaa48f fix issuer 2025-09-30 15:35:10 -04:00
Taylor Wilsdon
6087b74578 dynamically set oauth base 2025-09-29 17:02:32 -04:00
Taylor Wilsdon
8b035d7033 add userinfo and fix issuer 2025-09-29 16:01:28 -04:00
Taylor Wilsdon
bbab827652 timezone aware handling 2025-09-28 16:13:55 -04:00
Taylor Wilsdon
238a314fef session binding and legacy compatibility 2025-09-28 16:08:41 -04:00
Taylor Wilsdon
5b8e8477c0 ruff 2025-08-24 14:09:23 -04:00
Taylor Wilsdon
5626bae905 update scope retrieval for legacy oauth2callback 2025-08-24 14:00:21 -04:00
Taylor Wilsdon
ec9a20d8a3 scope the scopes 2025-08-24 11:15:11 -04:00
Taylor Wilsdon
24abf2a0f0 scope the scopes 2025-08-24 10:37:04 -04:00
Taylor Wilsdon
3c6a66b616 whitespace 2025-08-23 12:25:31 -04:00
Taylor Wilsdon
26ef6cc12e refac 2025-08-23 12:20:27 -04:00
Taylor Wilsdon
788e39368d refac decorator, add configure_logt_formatting helper, fixed variable scope & pep8 2025-08-23 12:04:04 -04:00
Taylor Wilsdon
57748df9c2 dynamically modify function params when in oauth2.1 mode 2025-08-23 11:39:37 -04:00
Taylor Wilsdon
3280a76a65 stateless mode for fastmcp entrypoint 2025-08-23 11:19:46 -04:00
Taylor Wilsdon
8f9a46e55b implement WORKSPACE_MCP_STATELESS_MODE 2025-08-23 11:12:21 -04:00
Taylor Wilsdon
a591783a9b ruff 2025-08-22 11:03:34 -04:00
Taylor Wilsdon
705cf29df3 update base uri per fastmcp #1387 2025-08-22 10:13:13 -04:00
Taylor Wilsdon
c136e6276f ruff 2025-08-22 09:52:12 -04:00
Taylor Wilsdon
f1b06446bc WORKSPACE_EXTERNAL_URL - add an document usage 2025-08-22 09:51:49 -04:00
Taylor Wilsdon
01f48b6c5e Update auth/google_remote_auth_provider.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-08-22 09:31:05 -04:00
Abel Santillan Rodriguez
399999144c fix: ensure trailing slash in resource URL for OAuth protected resource 2025-08-21 13:33:36 -06:00
Abel Santillan Rodriguez
4e1e02d1de fix: add base_url to authorization_servers and resource_server_url in GoogleRemoteAuthProvider 2025-08-21 13:09:23 -06:00
Abel Santillan Rodriguez
ff364596c3 fix: remove port from authorization and resource server URLs in GoogleRemoteAuthProvider 2025-08-21 13:04:50 -06:00
Abel Santillan Rodriguez
effae6649f fix: update base_url to exclude port from OAuth configuration 2025-08-21 12:54:39 -06:00
Taylor Wilsdon
34c4a5f8e7 code now properly checks the boolean return value from store_credential instead of overwriting the
credentials object.
2025-08-18 13:09:05 -04:00
Taylor Wilsdon
03cb54a2e1 Merge branch 'main' of https://github.com/taylorwilsdon/google_workspace_mcp into credential-provider 2025-08-18 13:04:36 -04:00
Shawn Zhu
13d0d66f4e doc: how to use credential store 2025-08-17 17:41:23 -04:00
Taylor Wilsdon
efcd525870 ruff check 2025-08-14 11:10:23 -04:00
Taylor Wilsdon
985228046e improve logic a bit, cleanup 2025-08-14 10:22:20 -04:00
Shawn Zhu
3a52f16f14 removes user_google_email argument from tool schema under multi-user mode 2025-08-13 22:36:19 -04:00
Taylor Wilsdon
9bdbd64b27 ruff check 2025-08-13 16:22:49 -04:00
Taylor Wilsdon
f17c4fec15 refac service decorator to simplify and remove unused cache nonsense 2025-08-13 16:21:58 -04:00