Skip to content

refactor(opencode): retire MCP promise facades - #1438

Merged
Astro-Han merged 3 commits into
devfrom
codex/i936-mcp-service-auth-facade-retire
Jun 20, 2026
Merged

refactor(opencode): retire MCP promise facades#1438
Astro-Han merged 3 commits into
devfrom
codex/i936-mcp-service-auth-facade-retire

Conversation

@Astro-Han

@Astro-Han Astro-Han commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Summary

Retires the MCP and McpAuth Promise facade exports and keeps callers on the Effect service boundary.

Why

Related to #936.

The MCP services were still carrying per-service makeRuntime(Service, defaultLayer) bridges and exported async facade functions after the shared AppRuntime graph became the production runtime. This removes that compatibility surface without changing MCP catalog, OAuth, auth storage, or connection semantics.

Related Issue

Related to #936

Human Review Status

Pending

Review Focus

Please focus on the OAuth provider boundary and the MCP test helper conversions. The production MCP service now injects its existing McpAuth.Service into McpOAuthProvider; standalone provider usage falls back to AppRuntime without reintroducing exported service facades.

Risk Notes

No visible UI or copy changed, so the UI/manual screenshot checklist item is not applicable. No platform, packaging, updater, signing, shell, or permissions surface changed. No docs, release notes, dependencies, credentials, deletion behavior, generated content, or local file output changed.

Fresh-eye result: no P0/P1 findings. One P2 simplification was found and fixed by using the already-injected MCP auth service inside the production provider path instead of bouncing every OAuth callback through the full AppRuntime.

How To Verify

Guardrail RED: bun test test/effect/legacy-boundaries.test.ts failed before implementation because MCP still imported @/effect/run-service and exposed async facades.
Guardrail GREEN: bun test test/effect/legacy-boundaries.test.ts -> 15 passed.
Focused MCP tests: bun test test/mcp/lifecycle.test.ts test/mcp/oauth-auto-connect.test.ts test/mcp/oauth-browser.test.ts test/mcp/headers.test.ts test/mcp/auth.test.ts -> 43 passed.
Typecheck: GOMAXPROCS=2 bun run typecheck -> passed.
Diff check: git diff --check -> passed.
Caller scan: rg for old MCP/McpAuth facade calls in packages/opencode/src and packages/opencode/test found no remaining callers; remaining matches are service trace names only.

Screenshots or Recordings

Not applicable. No visible UI changes.

Checklist

How to use this checklist:

  • Tick a box by replacing [ ] with [x]. Do not edit, add, or remove items.
  • The bot-applied label items can only be honestly ticked AFTER the PR is opened and the labeler / priority-triage bots have run — return to the PR description and tick them then.
  • Most items are required. The few that are conditional are explicitly marked (conditional); for those, leave unticked if they truly do not apply and explain why in Risk Notes. All other items must be ticked before requesting human review.
  • Type label — this PR carries exactly one of bug, enhancement, task, documentation. Type labels are author-added; the labeler bot does NOT assign them. Add the label in the GitHub UI, then tick this.
  • Routing labels — this PR carries at least one of app, ui, platform, harness, ci. The labeler bot assigns these on PR open based on changed paths. Confirm the bot's choice (or override if wrong), then tick this.
  • Priority label — this PR carries exactly one of P0, P1, P2, P3. The priority-triage bot suggests one on PR open. Confirm or override, then tick this.
  • Human Review Status above is set to Pending, Approved by @<reviewer>, or Not required: <reason> (default is Pending; "not required" is restricted to bot-authored low-risk PRs).
  • I linked the related issue, or stated in Summary why there is no issue.
  • I described the review focus and any meaningful risks.
  • I replaced the example block in How To Verify with the real verification steps and the key result for each.
  • I did not introduce unrelated refactors, dependencies, generated files, or file changes beyond the stated scope.
  • (conditional) I manually checked visible UI or copy changes when needed, with screenshots or recordings. Leave unticked only if no visible UI or copy changed.
  • (conditional) I considered macOS and Windows impact for platform, packaging, updater, signing, paths, shell, or permissions changes. Leave unticked only if no platform/packaging surface was touched.
  • (conditional) I called out docs, release notes, dependencies, permissions, credentials, deletion behavior, generated content, or local file changes when relevant. Leave unticked only if none of those surfaces was touched.
  • I reviewed the final diff for unrelated changes and suspicious dependency changes.
  • I am targeting dev, and my PR title and commit messages use Conventional Commits in English.

Summary by CodeRabbit

  • Refactor
    • Removed the public Promise-based façade exports for MCP and auth operations, keeping only the effect-based service/layer surface.
    • Updated the OAuth provider to execute auth persistence via an injected effect runner.
  • Tests
    • Added a test to ensure MCP/auth modules no longer expose Promise facades.
    • Updated MCP and OAuth tests to route interactions through an effect runtime wrapper.
    • Added coverage for token persistence with immediately expiring tokens.

@github-actions github-actions Bot added the harness Model harness, prompts, tool descriptions, and session mechanics label Jun 20, 2026
@Astro-Han Astro-Han added task Narrow execution, audit, spike, migration, tracking, or upstream follow-up work P2 Medium priority tech-debt Supplemental cleanup, maintainability, architecture, test, or quality debt context labels Jun 20, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested priority: P2 (includes non-doc, non-test paths outside the low-risk bucket).

P1/P0 are reserved for maintainer confirmation. Please relabel manually if this is a release blocker, security issue, data-loss risk, or updater/runtime failure.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2b4eba7a-4707-4618-8998-3c275d517521

📥 Commits

Reviewing files that changed from the base of the PR and between 3bfbe8a and b6951a8.

📒 Files selected for processing (3)
  • packages/opencode/src/mcp/oauth-provider.ts
  • packages/opencode/test/effect/legacy-boundaries.test.ts
  • packages/opencode/test/mcp/oauth-auto-connect.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/opencode/src/mcp/oauth-provider.ts

📝 Walkthrough

Walkthrough

Removes module-level Promise façade exports from McpAuth and MCP services. Introduces an injectable AuthRunner abstraction in McpOAuthProvider routing all credential/token/state persistence through AppRuntime and McpAuth.Service. Adds explicit Effect.runPromise callbacks in the MCP OAuth provider wiring. A boundary test enforces removal. All MCP tests migrate to local MCPFacade/McpAuthFacade wrappers.

Changes

Remove MCP Promise façades and introduce AuthRunner

Layer / File(s) Summary
Remove McpAuth Promise façades
packages/opencode/src/mcp/auth.ts
Removes the makeRuntime import and all exported async backward-compat wrapper functions (get, getForUrl, all, set, remove, updateTokens, updateClientInfo, updateCodeVerifier, updateOAuthState), leaving only the Effect-based McpAuth service and layers.
McpOAuthProvider AuthRunner abstraction
packages/opencode/src/mcp/oauth-provider.ts
Introduces AuthRunner type and appAuthRunner (using AppRuntime + McpAuth.Service.use), adds runAuth as an injectable constructor parameter with default, and rewrites all credential, token, and state persistence methods to call this.runAuth instead of static McpAuth.* calls.
Remove MCP Service façades and wire runAuth callbacks
packages/opencode/src/mcp/index.ts
Removes the makeRuntime import and all 14 exported async façade functions; adds explicit (fn) => Effect.runPromise(fn(auth)) execution callbacks in both the remote-connection and startAuth OAuth provider configurations.
Legacy boundary enforcement test
packages/opencode/test/effect/legacy-boundaries.test.ts
Adds a Bun test asserting that mcp/index.ts and mcp/auth.ts contain no run-service imports, makeRuntime calls, or the removed exported façade declarations.
Migrate MCP tests to local façade wrappers
packages/opencode/test/mcp/headers.test.ts, packages/opencode/test/mcp/lifecycle.test.ts, packages/opencode/test/mcp/oauth-auto-connect.test.ts, packages/opencode/test/mcp/oauth-browser.test.ts
All MCP test files construct local MCPFacade and McpAuthFacade helpers via makeRuntime(...).runPromise and replace every direct MCP.*/McpAuth.* call with the corresponding façade method, preserving all behavioral assertions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 No more facades to hide the truth,
The Effect runtime stands in its proof!
AuthRunner hops through every call,
runPromise no longer held in thrall.
The tests wrap neatly, facades in hand —
A cleaner codebase, just as planned! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: retiring MCP promise facades, which aligns with the primary objective of removing async facade exports.
Description check ✅ Passed The description covers Summary, Why, Related Issue, Human Review Status, Review Focus, Risk Notes (with conditional items explained), How To Verify (with concrete results), and all applicable checklist items completed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/i936-mcp-service-auth-facade-retire

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/opencode/src/mcp/oauth-provider.ts`:
- Around line 127-137: The expiresAt calculation in the updateTokens call uses a
truthy check on tokens.expires_in, which treats 0 as falsy and sets expiresAt to
undefined, losing the semantic meaning of an immediately-expiring token. Replace
the truthy check with an explicit null or undefined check so that when
tokens.expires_in is 0 (or any number including 0), it is properly calculated
and included in the expiresAt value, while only falling back to undefined when
expires_in is actually null or undefined.

In `@packages/opencode/test/effect/legacy-boundaries.test.ts`:
- Around line 225-251: The current facade detection in the test file for
mcp/index.ts and mcp/auth.ts only checks for the literal async keyword pattern
(export const ... = async), but a facade can evade this by returning a Promise
without using async, such as with arrow functions or function calls that return
Promises. To harden the detection, expand the check to identify any export that
returns or resolves to a Promise, not just those using the async keyword. This
may involve checking for Promise return types, Promise-returning function calls,
or other patterns that indicate an export provides Promise-based functionality
beyond just the async keyword syntax.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5257bf4b-b0c7-45a7-a968-cb931e18e3de

📥 Commits

Reviewing files that changed from the base of the PR and between 1188881 and 3bfbe8a.

📒 Files selected for processing (8)
  • packages/opencode/src/mcp/auth.ts
  • packages/opencode/src/mcp/index.ts
  • packages/opencode/src/mcp/oauth-provider.ts
  • packages/opencode/test/effect/legacy-boundaries.test.ts
  • packages/opencode/test/mcp/headers.test.ts
  • packages/opencode/test/mcp/lifecycle.test.ts
  • packages/opencode/test/mcp/oauth-auto-connect.test.ts
  • packages/opencode/test/mcp/oauth-browser.test.ts
💤 Files with no reviewable changes (1)
  • packages/opencode/src/mcp/auth.ts

Comment thread packages/opencode/src/mcp/oauth-provider.ts
Comment thread packages/opencode/test/effect/legacy-boundaries.test.ts
…-auth-facade-retire

# Conflicts:
#	packages/opencode/test/effect/legacy-boundaries.test.ts
@Astro-Han
Astro-Han merged commit bc4f4af into dev Jun 20, 2026
43 checks passed
@Astro-Han
Astro-Han deleted the codex/i936-mcp-service-auth-facade-retire branch June 20, 2026 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

harness Model harness, prompts, tool descriptions, and session mechanics P2 Medium priority task Narrow execution, audit, spike, migration, tracking, or upstream follow-up work tech-debt Supplemental cleanup, maintainability, architecture, test, or quality debt context

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant