Skip to content

feat(mcp): add guided setup and per-tool approval management - #1284

Open
xwil1 wants to merge 5 commits into
alibaba:mainfrom
xwil1:feat/mcp-permission-upstream
Open

xwil1 wants to merge 5 commits into
alibaba:mainfrom
xwil1:feat/mcp-permission-upstream

Conversation

@xwil1

@xwil1 xwil1 commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add guided MCP connection setup and per-tool permissions through ocr mcp, reusing the project's MCP Go SDK integration and Bubble Tea components.

Users can add or import a connection, confirm startup, discover its tools, select the tools they want, and choose when execution needs approval. The manager uses one full-screen session with separate server and action areas.

Main changes

  • Add connection management for stdio and remote Streamable HTTP, plus Cursor JSON / Codex TOML import. Import saves a disabled connection without starting it.
  • Separate model-visible tool selection from the independent execution-time authorization check. Automatic approval never enables additional tools.
  • Resolve global, server and tool permissions with parent deny taking precedence. Non-interactive / CI runs hide ask tools.
  • Provide Allow once, Allow this review, Deny once and Deny this review. Review-scoped decisions stay in memory. Approval timeout is configurable from 1–600 seconds, default 60.
  • Bind tool definitions and providers to the same fingerprinted, qualified identity. Changed definitions require acceptance; collisions cannot silently select another executor.
  • Bound discovery and results, validate connections, restrict inherited environment variables, redact credentials, and save configuration atomically with stale-write protection.
  • Preserve unknown JSON fields across model/MCP configuration updates using shared serialization helpers. Unknown fields do not grant access or restore revoked tools; the atomic private-file save path remains in place.
  • Preserve upstream's unified execution/failure reporting, bounded concurrent MCP shutdown, and native model replay support. Sensitive transcript copies and compression input are sanitized; raw traffic logging is disabled when a review exposes MCP tools. Ordinary tool calls retain upstream extra_content, while sensitive transcript copies omit opaque metadata without changing the live replay payload.
  • Update MCP guides, configuration, CLI and CI documentation in English, Chinese, Japanese, Russian and Korean, with documentation contract tests.

Compatibility changes

  • Empty or omitted tool lists now mean no enabled tools, not every server tool.
  • Legacy configuration cannot silently become unattended authorization; missing or changed fingerprints require review.
  • Legacy setup commands are no longer executed automatically during review.
  • Follow upstream's removal of OCR_CONFIG_PATH: configuration commands and review use the default user config. Tests and isolated examples use a dedicated HOME / USERPROFILE.
  • Non-loopback plaintext HTTP needs explicit opt-in. Server safety annotations are not authorization.

Review map

  • internal/mcp: policy, identity, discovery, authorization and transport boundaries.
  • cmd/opencodereview: manager, wizard/import, atomic configuration and review integration.
  • internal/llmloop / internal/session: sensitive-call reporting, native transcript and compression handling.
  • Tests and documentation account for approximately 46% and 11% of added lines respectively; implementation and supporting configuration account for the remainder.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

Latest upstream-sync validation (5f8e5ab): make check, make build, full make test with race detection, make coverage (91.0%), action/plugin/MCP-documentation contracts, launcher/update tests, real-terminal management and all nine review-approval scenarios, Linux build, Windows CLI-test cross-compilation, and git diff --check passed.

The validation history for this PR also includes:

  • make check, make build, go test ./..., go vet ./... and git diff --check passed.
  • make test passed with race detection across all packages. Targeted race tests also passed for MCP, the LLM loop, sessions and the CLI.
  • make coverage passed at 91.0% after the latest upstream merge, above the 90% threshold.
  • Action/plugin/documentation contracts, launcher tests and update tests passed.
  • Documentation-site lint, typecheck, 38 tests, build and size checks passed. Two pre-existing React Hook lint warnings and Webpack size advisories remain; the enforced size check is 93.58 kB / 150 kB.
  • Linux and Windows cross-compilation passed. The latest update also recompiles the CLI test binary for Windows.

Based on 5f8e5ab, including #1031's shared frontend extraction, the narrowed English-only exemptions, upstream configuration-field preservation, removal of OCR_CONFIG_PATH, and tool-call extra_content replay. This PR does not modify extensions/. MCP argument redaction remains compatible with upstream tool-failure handling, JSON argument recovery, and aggregate token-budget enforcement.

The real-terminal regression harness covers setup/import, discovery with zero business calls, tool selection and revocation, save/back/cancel/timeout, all four approval choices, per-review cache reset, and CI ask/allow behavior. Integration tests additionally cover EOF, disabled/unselected tools, parent deny and fingerprint drift. Denied or canceled cases assert zero underlying MCP calls.

A small live-service smoke test used the locally configured fast-context MCP and deepseek-ai/deepseek-v4-flash through an OpenAI-compatible endpoint:

Scenario Approval prompts Actual MCP calls Review result
Allow once 1 1 Completed; found the intended boundary regression
Deny this review 1 0 Completed from the existing diff; did not retry the search

The input was one nine-line Go file with a one-line change. Six model requests were made in total. An isolated forwarding/counting harness was used; model replies and MCP results were not simulated. Persistent configuration stayed unchanged, and credential checks passed. Other permission combinations are covered by automated tests, not by additional live-model runs.

  • make test passes locally
  • Terminal interaction testing through automated PTY harnesses, including the two live-service scenarios above

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable)
  • CLA check passes (license/cla)

Related to #1281. This PR does not close the issue.

@xwil1 xwil1 changed the title feat(mcp)!: add guided setup and per-tool approval management feat(mcp): add guided setup and per-tool approval management Sep 15, 2026
Comment thread cmd/opencodereview/mcp_wizard.go Fixed
@lizhengfeng101

Copy link
Copy Markdown
Contributor

Heads up — #1031 just landed on main and moved the VS Code webview and shared types into a new extensions/frontend/ package, so please rebase onto the latest main and relocate any changes under extensions/vscode/src/webview/ or extensions/vscode/src/shared/ to extensions/frontend/src/.

@xwil1
xwil1 force-pushed the feat/mcp-permission-upstream branch from de889bf to 8a3a535 Compare September 18, 2026 10:44
@xwil1

xwil1 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Heads up — #1031 just landed on main and moved the VS Code webview and shared types into a new extensions/frontend/ package, so please rebase onto the latest main and relocate any changes under extensions/vscode/src/webview/ or extensions/vscode/src/shared/ to extensions/frontend/src/.注意—— #1031 刚刚合并到主分支,并将 VS Code webview 和共享类型移到了一个新的 extensions/frontend/ 包中,因此请基于最新的主分支进行 rebase,并将 extensions/vscode/src/webview/ 或 extensions/vscode/src/shared/ 的任何更改迁移到 extensions/frontend/src/ 。

ok

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants