Skip to main content
Glama
README.md
# ScopeGuard MCP

Spec-to-sprint drift detection and release readiness verification built on Atlassian Forge.

Engineering teams draft specifications and Architecture Decision Records (ADRs) in Confluence, track sprint work in Jira, and write code inside AI-assisted IDEs. When a product manager edits a Confluence specification mid-sprint, both the Jira acceptance criteria and the developer's coding context go stale. ScopeGuard MCP closes that loop inside Atlassian Forge without external servers, databases, or third-party LLM keys.

## Architecture Overview

ScopeGuard runs on the Forge `nodejs22.x` runtime using user-scoped OAuth permissions (`api.asUser()`).

```text
+-----------------------------------+       +--------------------------------------+
| External AI IDE (Claude/Cursor)   |       | Jira & Confluence UI Kit 2 Surfaces  |
| OAuth 2.1 via                     |       | - jira:issuePanel (Drift & Diffs)    |
| mcp.atlassian.com/forge/<app-id>  |       | - jira:projectPage (Sprint Matrix)   |
+-----------------+-----------------+       | - confluence:contentBylineItem       |
                  |                         | - rovo:agent (ScopeGuard Steward)    |
                  v                         +------------------+-------------------+
+--------------------------------------------------------------+-------------------+
|                    Atlassian Forge Runtime (nodejs22.x)                          |
|                                                                                  |
|  [src/actions.ts]  <-----  [src/engine/service.ts]  ----->  [src/resolvers.ts]   |
|         |                             |                              |           |
|         v                             v                              v           |
|  @forge/api (Jira v3 + Confluence v2 REST)       @forge/kvs (storage:app)        |
|  - Issue & remote link resolution                - baseline:{issueKey}:{pageId}  |
|  - Confluence storage XML fetch                  - evidence:{issueKey}           |
|  - Sub-task creation & audit comments            - blockers:{issueKey}           |
|  - Deterministic SHA-256 section diffing         - audit:{projectKey}:{isoDate}  |
|  - Isolated preview state                        - demo:* keys                   |
+----------------------------------------------------------------------------------+
```

### Deterministic Drift Engine and Before/After Diffs

Core drift detection lives in `src/engine/driftEngine.ts` and relies on Node's built-in `node:crypto` module.

1. The Confluence parser reads storage XHTML, extracts `<h1>` through `<h3>` sections, decodes HTML entities, normalizes whitespace, and hashes each section with SHA-256.
2. Locking a baseline stores `{ pageId, specVersion, sectionHashes, sections, capturedAt }` in `@forge/kvs`.
3. Subsequent checks compare the live Confluence page version and section hashes against the stored baseline, classifying each heading as `UNCHANGED`, `MODIFIED`, `ADDED`, or `REMOVED`.
4. For every changed section, the diff payload includes both `baselineExcerpt` and `liveExcerpt` so engineers see a direct Before vs After comparison inside Jira and in IDE MCP responses.
5. Readiness scores run from `0` to `100`: `100` when aligned with zero blockers, `95` when drift is acknowledged via implementation evidence for the live spec version, and lower when unacknowledged edits (`-10` version drift, `-15` modified, `-20` removed, `-10` added) or active release blockers (`-25` each) exist.

### Quick Demo Mode (Isolated Preview State)

On any Jira issue with `NO_LINKED_SPEC`, `jira:issuePanel` renders **Run Quick Demo Preview** alongside a **Clear Demo Preview** reset control. Clicking **Run Quick Demo Preview** populates a realistic drifted contract example (including Before vs After excerpts and sample IDE verification proof) isolated under `demo:` KVS keys. Real project baselines, Jira comments, and production audit logs stay untouched.

### Exposed Modules

| Module Type | Key | Purpose |
| :--- | :--- | :--- |
| `rovo:agent` | `scopeguard-steward-agent` | In-product Rovo agent (`ScopeGuard Steward`) wired to 5 triage actions (excluding `log-impl-evidence`) |
| `rovo:mcp` | `scopeguard-mcp-server` | Hosted MCP server exposing all 6 typed `action` tools over OAuth 2.1 |
| `action` | `check-spec-drift` | Compares live Confluence section hashes against the stored Jira baseline |
| `action` | `verify-contract-gate` | Returns acceptance criteria, Before/After ADR excerpts, score, and gate status |
| `action` | `scan-sprint-readiness` | Scans non-subtask project issues, computes aggregate readiness, and lists active blockers |
| `action` | `sync-adr-to-subtasks` | Creates a follow-up Jira sub-task and posts an audit comment summarizing the delta |
| `action` | `log-impl-evidence` | Stores structured IDE/CI verification (`commitSha`, `testsPassed`, `testsFailed`, `specVersion`) in KVS and Jira |
| `action` | `flag-release-blocker` | Records an active release blocker in KVS, adds `scopeguard-blocked` label, and comments |
| `jira:issuePanel` | `scopeguard-issue-panel` | UI Kit 2 panel with drift badge, Before/After diffs, evidence log, and Quick Demo Mode |
| `jira:projectPage` | `scopeguard-project-dashboard` | UI Kit 2 sprint matrix with KPI strip (`Total Scanned`, `Aligned`, `Drifted`, `Active Blockers`, `Avg Readiness`) and status filters (`All`, `Drifted`, `Blocked`, `Aligned`, `Unbaselined`) |
| `confluence:contentBylineItem` | `scopeguard-spec-byline` | Confluence page byline showing all linked Jira issues and live readiness scores |

### Structured IDE Evidence Fields

When an external MCP client or CI runner calls `log-impl-evidence`, it can attach structured verification fields alongside `issueKey` and `evidenceNote`:

| Input Field | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| `issueKey` | `string` | Yes | Target Jira issue key such as `SG-14` |
| `evidenceNote` | `string` | Yes | Concise summary of the verification run |
| `specVersion` | `integer` | No | Confluence page version verified during implementation |
| `commitSha` | `string` | No | Git commit hash tied to the verified change |
| `testsPassed` | `integer` | No | Count of passing automated tests |
| `testsFailed` | `integer` | No | Count of failing automated tests |

ScopeGuard records these fields in `@forge/kvs` and formats them into the Jira audit comment so reviewers trace each commit directly to the exact Confluence spec version.

### Least-Privilege Permissions

ScopeGuard requests five Forge scopes in `manifest.yml`: `storage:app`, `read:jira-work`, `write:jira-work`, `read:page:confluence`, and `read:confluence-content.all`. Confluence write scopes are omitted because ScopeGuard only reads Confluence specifications and writes audit artifacts to Jira and KVS.

## Setup and Deployment

### Prerequisites

- Node.js matching `@forge/cli@16.0.0` engine requirements: `^22.23.4 || ^24.22.1 || >=26.12.1` (note: local environments running older Node 24 releases such as `v24.13.1` should switch to `22.23.4` via `nvm` before running `npx @forge/cli@latest`)
- An Atlassian Cloud Developer site with both Jira and Confluence enabled
- An Atlassian API token created at `id.atlassian.com/manage/api-tokens`

If your machine currently runs an older Node 24 build (for example `v24.13.1`), install and select Node `22.23.4` first:

```bash
nvm install 22.23.4
nvm use 22.23.4
node -v
```

### Local Verification

Install local dependencies, run TypeScript type checking, and execute the unit test suite:

```bash
npm install
npx tsc --noEmit
npm test
```

### Register, Lint, and Deploy to Forge

Invoke the Forge CLI via `npx` so no global package installation is required:

```bash
npx @forge/cli@latest login
npx @forge/cli@latest register
npx @forge/cli@latest lint --fix
npx @forge/cli@latest deploy
npx @forge/cli@latest install
```

During `forge install`, select both your Jira and Confluence sites for the target developer instance.

Note on `app.rovo` metadata: `app.rovo` (`tag`, `description`, `keywords`) is currently omitted (commented) in `manifest.yml` because `@forge/cli@16.0.0` (`@forge/manifest@13.9.1`) rejects it during lint and deploy. Re-enable `app.rovo` once Forge CLI updates ahead of the January 5, 2027 enforcement date.

### Enable External MCP Tools in Atlassian Administration

Forge keeps external `rovo:mcp` tool access disabled by default until a site administrator enables it.

1. Open Atlassian Administration (`admin.atlassian.com`) and select your target organization.
2. Navigate to **Apps**, select **Sites**, choose your developer site, and open **Connected apps**.
3. Open **ScopeGuard MCP** and select the **Tools** tab.
4. Toggle external access on for all 6 actions (`check-spec-drift`, `verify-contract-gate`, `scan-sprint-readiness`, `sync-adr-to-subtasks`, `log-impl-evidence`, `flag-release-blocker`).

## Connecting an AI IDE via Atlassian MCP

Once external tools are enabled, point your MCP-compatible coding client to the hosted Forge MCP endpoint using the app UUID recorded in `manifest.yml`:

```text
https://mcp.atlassian.com/forge/<app-id>
```

Replace `<app-id>` with the UUID portion of `app.id` in `manifest.yml` (after the `ari:cloud:ecosystem::app/` prefix).

### Claude Code Configuration

```bash
claude mcp add --transport http scopeguard https://mcp.atlassian.com/forge/<app-id>
```

Authenticate via the OAuth 2.1 browser prompt when Claude Code connects for the first time. All Jira and Confluence requests execute under your signed-in Atlassian user permissions.

### Cursor Configuration

Add the hosted server entry to `.cursor/mcp.json`:

```json
{
  "mcpServers": {
    "scopeguard": {
      "url": "https://mcp.atlassian.com/forge/<app-id>"
    }
  }
}
```

Reload MCP servers in Cursor settings and complete the OAuth 2.1 sign-in prompt.

## Judge Walkthrough (60-Second Verification)

Judges can verify every surface on a test Jira project and Confluence space in two ways: instant preview via Quick Demo Mode or live end-to-end roundtrip.

1. **Instant Quick Demo Preview:** Open `ScopeGuard Contract & Drift` on any Jira issue without a linked Confluence page and click **Run Quick Demo Preview**. Inspect the simulated Before/After section diff, readiness score, and sample IDE evidence, then click **Clear Demo Preview** when ready to test live data.
2. **Baseline Capture:** Create a Confluence page with two or three `<h2>` sections, link its URL to a Jira issue (via Web Link or issue description), open **ScopeGuard Contract & Drift**, and click **Lock Spec Baseline**. The badge turns green (`ALIGNED`, `100/100`).
3. **Mid-Sprint Spec Drift & Before/After Diffs:** Edit one `<h2>` section in Confluence and publish a new page version. Refresh the Jira issue panel to inspect `SPEC DRIFT DETECTED`, the `MODIFIED` row with `baselineExcerpt` vs `liveExcerpt`, and the updated readiness score.
4. **IDE MCP Roundtrip:** From Claude Code or Cursor, run `verify-contract-gate` for the issue key, review the Before/After ADR excerpt, update code/tests, and call `log-impl-evidence` with `commitSha`, `testsPassed`, `testsFailed`, and the live `specVersion`. Refreshing the Jira panel flips the status to `DRIFT VERIFIED` (`95/100`) and displays the audit comment.
5. **Rovo Agent and Cross-Surface Views:** Open Rovo Chat inside Jira, select **ScopeGuard Steward**, and run the sprint drift starter prompt to trigger `scan-sprint-readiness`, drill down with `check-spec-drift`, and test `sync-adr-to-subtasks` or `flag-release-blocker`. Open **ScopeGuard Readiness** from the Jira project sidebar to inspect the KPI strip (`Total Scanned`, `Aligned`, `Drifted`, `Active Blockers`, `Avg Readiness`) and interactive status filters (`All`, `Drifted`, `Blocked`, `Aligned`, `Unbaselined`), then click the **ScopeGuard Linked Jira Status** byline item on Confluence to confirm reverse-linked reporting.