feat: Apps Script fallback for local image insertion in enterprise environments#62
Merged
a-bonus merged 1 commit intoa-bonus:mainfrom Feb 22, 2026
Conversation
…e environments
The current insertImage tool requires making uploaded files publicly
readable via drive.permissions.create({ type: 'anyone' }), which is
blocked by many enterprise Google Workspace security policies.
This adds an opt-in Apps Script-based path that bypasses the public
sharing requirement by using DocumentApp to insert images directly
from Drive blobs. The feature is gated behind APPS_SCRIPT_DEPLOYMENT_ID
env var — without it, behavior is completely unchanged.
Changes:
- Add script.external_request OAuth scope
- Add Script API client (google.script v1)
- Refactor uploadImageToDrive() to support skipPublicSharing mode
- Add insertImageViaAppsScript() helper using marker-based insertion
- Modify insertImage tool to use Apps Script path when configured
- Include ready-to-deploy Apps Script in apps_script/
Co-authored-by: Cursor <cursoragent@cursor.com>
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
Enterprise Google Workspace environments often block public file sharing (
drive.permissions.create({ type: 'anyone' })), which causesinsertImagewithlocalImagePathto fail with "insufficient permissions".This PR adds an opt-in Apps Script-based fallback that inserts images directly from Drive blobs via
DocumentApp, bypassing the public sharing requirement entirely.How it works
[mcp-img-FILEID]marker at the target position via the Docs APIChanges
src/auth.ts— Addedscript.external_requestOAuth scopesrc/clients.ts— Added Script API client (google.script('v1')) andgetScriptClient()helpersrc/googleDocsApiHelpers.ts— AddedskipPublicSharingoption touploadImageToDrive(), addedinsertImageViaAppsScript()helpersrc/tools/docs/insertImage.ts— Uses Apps Script path whenAPPS_SCRIPT_DEPLOYMENT_IDenv var is set; falls back to existing behavior otherwiseapps_script/mcp_image_inserter.gs— Ready-to-deploy Apps Script functionBackward compatibility
Fully backward compatible. The Apps Script path only activates when
APPS_SCRIPT_DEPLOYMENT_IDis set as an environment variable. Without it, behavior is identical to before.Setup (for users who need this)
apps_script/mcp_image_inserter.gsAPPS_SCRIPT_DEPLOYMENT_IDenv var to the deployment IDTest plan
npm run build)APPS_SCRIPT_DEPLOYMENT_ID, existing behavior is unchangedMade with Cursor