$npx -y skills add iurykrieger/claude-bedrock --skill gdoc-to-markdownInternal fetcher module for Google Docs and Sheets. Fetches content via MCP (preferred, when available), Google API with bearer token or public URL export (fallback), or browser DOM extraction via Claude in Chrome (last resort) and returns Markdown. Used by /bedrock:learn and /be
| 1 | # Google Docs & Sheets Fetcher |
| 2 | |
| 3 | Internal module — invoked by `/bedrock:learn` Phase 1 and `/bedrock:sync` Phase 2, not user-invocable. |
| 4 | |
| 5 | Fetches a Google Docs document or Google Sheets spreadsheet and converts it to a local Markdown file. |
| 6 | Supports both document types with automatic detection. Three layers in fallback order: |
| 7 | **MCP (preferred) → API / Public Export → Browser DOM extraction.** |
| 8 | |
| 9 | **Dependency:** Browser fallback (Layer 3) requires `scripts/extract.js` (relative to this skill directory). |
| 10 | |
| 11 | --- |
| 12 | |
| 13 | ## Step 1 — Parse URL and Detect Type |
| 14 | |
| 15 | Parse the URL. Accept these formats: |
| 16 | |
| 17 | **Google Docs:** |
| 18 | - `https://docs.google.com/document/d/{docId}/edit` |
| 19 | - `https://docs.google.com/document/d/{docId}/edit#heading=...` |
| 20 | - `https://docs.google.com/document/d/{docId}/edit?tab=t.0` |
| 21 | - `https://docs.google.com/document/d/{docId}` |
| 22 | - Raw document ID (no URL) — treat as Doc by default |
| 23 | |
| 24 | **Google Sheets:** |
| 25 | - `https://docs.google.com/spreadsheets/d/{docId}/edit` |
| 26 | - `https://docs.google.com/spreadsheets/d/{docId}/edit#gid=0` |
| 27 | - `https://docs.google.com/spreadsheets/d/{docId}` |
| 28 | - Raw spreadsheet ID — only if the user explicitly mentions "sheet" or "spreadsheet" |
| 29 | |
| 30 | **Detect type:** |
| 31 | - URL contains `/spreadsheets/d/` → **Sheet** |
| 32 | - URL contains `/document/d/` → **Doc** |
| 33 | - Raw ID with no URL → default to **Doc** unless user context indicates Sheet |
| 34 | |
| 35 | Extract the `{docId}` — the string between `/d/` and the next `/` or end of path. |
| 36 | |
| 37 | --- |
| 38 | |
| 39 | ## Step 2 — Layer 1: MCP (Google Docs) |
| 40 | |
| 41 | The preferred layer. Checks if a Google Docs/Drive MCP server is installed and authenticated. |
| 42 | |
| 43 | ### 2.1 Check MCP availability |
| 44 | |
| 45 | Use ToolSearch to check if any Google Docs or Google Drive MCP tools are available: |
| 46 | |
| 47 | ``` |
| 48 | ToolSearch(query: "google docs drive document", max_results: 5) |
| 49 | ``` |
| 50 | |
| 51 | Evaluate the result: |
| 52 | |
| 53 | - **Google Docs/Drive MCP tools found and functional** → proceed to **2.2 Fetch via MCP** |
| 54 | - **MCP tools found but not authenticated** → proceed to **2.3 Guide authentication** |
| 55 | - **No Google Docs MCP tools found** (this is the expected case today) → log and fall through: |
| 56 | |
| 57 | > **MCP not available:** No Google Docs/Drive MCP server installed. |
| 58 | > When a Google Docs MCP becomes available, install it for direct document access. |
| 59 | > Falling back to API (Layer 2). |
| 60 | |
| 61 | ### 2.2 Fetch via MCP |
| 62 | |
| 63 | Use the Google Docs MCP tools to fetch the document content. The specific tool depends on what the MCP exposes. |
| 64 | |
| 65 | - **Success** → convert content to Markdown if not already, proceed to **Output Contract** |
| 66 | - **Error** → log the error and fall through to Layer 2: |
| 67 | |
| 68 | > **MCP fetch failed:** {error message}. |
| 69 | > Falling back to API (Layer 2). |
| 70 | |
| 71 | ### 2.3 Guide authentication |
| 72 | |
| 73 | If an MCP is installed but not authenticated, guide the user: |
| 74 | |
| 75 | > **MCP not authenticated:** A Google Docs MCP server is installed but requires authentication. |
| 76 | > Complete the authentication flow as prompted by the MCP server. |
| 77 | > After authentication, Google documents can be fetched directly via MCP. |
| 78 | |
| 79 | Ask the user: "Would you like to authenticate the Google Docs MCP now, or skip to API fallback (Layer 2)?" |
| 80 | |
| 81 | - **User wants to authenticate** → invoke the MCP authentication tool, wait for the user to complete the flow, then retry **2.2 Fetch via MCP** |
| 82 | - **User declines** → log "User declined MCP authentication, falling to Layer 2" → continue to Step 3 |
| 83 | |
| 84 | --- |
| 85 | |
| 86 | ## Step 3 — Layer 2: API |
| 87 | |
| 88 | Uses the Google Drive/Sheets API with a bearer token or public URL export. |
| 89 | |
| 90 | ### Strategy selection |
| 91 | |
| 92 | - **If `GOOGLE_ACCESS_TOKEN` env var exists** → use **Strategy A (API with token)** |
| 93 | - **If `GOOGLE_ACCESS_TOKEN` is NOT set** → use **Strategy B (Public Export)** |
| 94 | - **If Strategy B fails (private document)** → guide and fall through to Layer 3: |
| 95 | |
| 96 | > **API not available:** This document requires authentication and no `GOOGLE_ACCESS_TOKEN` is set. |
| 97 | > Generate a token at https://developers.google.com/oauthplayground/ with the `https://www.googleapis.com/auth/drive.readonly` scope. |
| 98 | > Export: `export GOOGLE_ACCESS_TOKEN="your-token"`. |
| 99 | > Falling back to Browser extraction (Layer 3). |
| 100 | |
| 101 | Inform the caller which strategy is being used and whether the document is a **Doc** or **Sheet**. |
| 102 | |
| 103 | --- |
| 104 | |
| 105 | ### Google Docs — Strategy A (API with token) |
| 106 | |
| 107 | #### A.1 Fetch as Markdown |
| 108 | |
| 109 | Use `WebFetch`: |
| 110 | ``` |
| 111 | WebFetch( |
| 112 | url: "https://www.googleapis.com/drive/v3/files/{docId}/export?mimeType=text/markdown", |
| 113 | headers: { "Authorization": "Bearer {GOOGLE_ACCESS_TOKEN}" }, |
| 114 | prompt: "Return the COMPLETE raw content exactly as-is. Do not summarize or truncate." |
| 115 | ) |
| 116 | ``` |
| 117 | |
| 118 | If WebFetch cannot send the Authorization header, fall back to |