$npx -y skills add iurykrieger/claude-bedrock --skill confluence-to-markdownInternal fetcher module for Confluence pages. Fetches content via Atlassian MCP (preferred), REST API with Basic Auth (fallback), or browser DOM extraction via Claude in Chrome (last resort) and returns Markdown. Used by /bedrock:learn and /bedrock:sync — not intended for direct
| 1 | # Confluence Fetcher |
| 2 | |
| 3 | Internal module — invoked by `/bedrock:learn` Phase 1 and `/bedrock:sync` Phase 2, not user-invocable. |
| 4 | |
| 5 | Fetches a Confluence page and returns its content as Markdown. Three layers in fallback order: |
| 6 | **MCP (preferred) → REST API → Browser DOM extraction.** |
| 7 | |
| 8 | **Dependency:** Browser fallback (Layer 3) requires `scripts/extract.js` (relative to this skill directory). |
| 9 | |
| 10 | --- |
| 11 | |
| 12 | ## Step 1 — Parse URL |
| 13 | |
| 14 | Parse the Confluence URL. Accept these formats: |
| 15 | - `https://<domain>.atlassian.net/wiki/spaces/<spaceKey>/pages/<pageId>/<title>` |
| 16 | - `https://<domain>.atlassian.net/wiki/spaces/<spaceKey>/pages/<pageId>` |
| 17 | - `https://<domain>.atlassian.net/wiki/x/<shortlink>` |
| 18 | - `https://<domain>.atlassian.net/wiki/pages/viewpage.action?pageId=<pageId>` |
| 19 | |
| 20 | Extract: |
| 21 | - **Base URL**: `https://<domain>.atlassian.net` (everything before `/wiki/...`) |
| 22 | - **Page ID**: the numeric ID from the URL path (segment after `/pages/`) or `pageId` query parameter |
| 23 | - **Full URL**: the original URL as provided (needed for browser fallback) |
| 24 | |
| 25 | --- |
| 26 | |
| 27 | ## Step 2 — Layer 1: MCP (Atlassian) |
| 28 | |
| 29 | The preferred layer. Uses the `plugin:atlassian:atlassian` MCP server if installed and authenticated. |
| 30 | |
| 31 | ### 2.1 Check MCP availability |
| 32 | |
| 33 | Use ToolSearch to check if Atlassian MCP tools are available: |
| 34 | |
| 35 | ``` |
| 36 | ToolSearch(query: "atlassian confluence page", max_results: 5) |
| 37 | ``` |
| 38 | |
| 39 | Evaluate the result: |
| 40 | |
| 41 | - **MCP tools found and functional** (tools other than `authenticate` and `complete_authentication` are available) → proceed to **2.2 Fetch via MCP** |
| 42 | - **Only `authenticate` / `complete_authentication` tools found** (MCP installed but not authenticated) → proceed to **2.3 Guide authentication** |
| 43 | - **No Atlassian MCP tools found** → log and fall through: |
| 44 | |
| 45 | > **MCP not available:** No Atlassian MCP server installed. |
| 46 | > Install the Atlassian MCP plugin for Claude Code to enable direct Confluence access. |
| 47 | > Falling back to API (Layer 2). |
| 48 | |
| 49 | ### 2.2 Fetch via MCP |
| 50 | |
| 51 | Use the Atlassian MCP tools to fetch the page content. The specific tool depends on what the MCP exposes after authentication (typically a page read or content retrieval tool). |
| 52 | |
| 53 | Call the MCP tool passing the page ID or URL. The MCP returns the page content directly. |
| 54 | |
| 55 | - **Success** → convert content to Markdown if not already, proceed to **Output Contract** |
| 56 | - **Error** → log the error and fall through to Layer 2: |
| 57 | |
| 58 | > **MCP fetch failed:** {error message}. |
| 59 | > Falling back to API (Layer 2). |
| 60 | |
| 61 | ### 2.3 Guide authentication |
| 62 | |
| 63 | If the MCP is installed but not authenticated, guide the user: |
| 64 | |
| 65 | > **MCP not authenticated:** The Atlassian MCP server is installed but requires authentication. |
| 66 | > Run `mcp__plugin_atlassian_atlassian__authenticate` to start the OAuth flow, then complete it in your browser. |
| 67 | > After authentication, Confluence pages can be fetched directly via MCP. |
| 68 | |
| 69 | Ask the user: "Would you like to authenticate the Atlassian MCP now, or skip to API fallback (Layer 2)?" |
| 70 | |
| 71 | - **User wants to authenticate** → invoke `mcp__plugin_atlassian_atlassian__authenticate`, wait for the user to complete the OAuth flow, then retry **2.2 Fetch via MCP** |
| 72 | - **User declines** → log "User declined MCP authentication, falling to Layer 2" → continue to Step 3 |
| 73 | |
| 74 | --- |
| 75 | |
| 76 | ## Step 3 — Layer 2: API (REST) |
| 77 | |
| 78 | Uses the Confluence REST API with Basic Auth (API token + email). |
| 79 | |
| 80 | ### 3.1 Check credentials |
| 81 | |
| 82 | ```bash |
| 83 | echo "CONFLUENCE_API_TOKEN: ${CONFLUENCE_API_TOKEN:+set}" && echo "CONFLUENCE_USER_EMAIL: ${CONFLUENCE_USER_EMAIL:+set}" |
| 84 | ``` |
| 85 | |
| 86 | - **Both set** → proceed to **3.2 Compute auth header** |
| 87 | - **Either missing** → guide and fall through: |
| 88 | |
| 89 | > **API not available:** `CONFLUENCE_API_TOKEN` or `CONFLUENCE_USER_EMAIL` environment variable is not set. |
| 90 | > Generate an API token at https://id.atlassian.com/manage-profile/security/api-tokens and export both variables: |
| 91 | > `export CONFLUENCE_API_TOKEN="your-token"` and `export CONFLUENCE_USER_EMAIL="your-email"`. |
| 92 | > Falling back to Browser extraction (Layer 3). |
| 93 | |
| 94 | ### 3.2 Compute Basic Auth header |
| 95 | |
| 96 | ```bash |
| 97 | echo -n "${CONFLUENCE_USER_EMAIL}:${CONFLUENCE_API_TOKEN}" | base64 |
| 98 | ``` |
| 99 | |
| 100 | ### 3.3 Fetch the page |
| 101 | |
| 102 | Use `WebFetch`: |
| 103 | ``` |
| 104 | WebFetch( |
| 105 | url: "{baseUrl}/wiki/api/v2/pages/{pageId}?body-format=storage", |
| 106 | headers: { |
| 107 | "Authorization": "Basic {base64_value}", |
| 108 | "Accept": "application/json" |
| 109 | } |
| 110 | ) |
| 111 | ``` |
| 112 | |
| 113 | If WebFetch cannot send the Authorization header, fall back to `curl` via Bash: |
| 114 | ```bash |
| 115 | curl -sL -H "Authorization: Basic {base64_value}" -H "Accept: application/json" \ |
| 116 | "{baseUrl}/wiki/api/v2/pages/{pageId}?body-format=storage" |
| 117 | ``` |
| 118 | |
| 119 | ### 3.4 Extract content from re |