feat(scan): enable configured MCP tools during full-file scans

Author: lizhengfeng101Created Sep 28, 2026Updated Sep 29, 2026
Labelsenhancementhelp wantedgo

Description

ocr review connects to configured MCP servers, registers their tools alongside the built-in tools, and exposes their definitions to the review agent. ocr scan loads the same user configuration but currently only passes its built-in tool definitions to the full-file review agent. Consequently, configured MCP tools cannot be used while scanning files.

Make configured MCP tools available to the main task of ocr scan, with the same server configuration, allowlist, name-conflict handling, connection-failure behavior, and bounded shutdown as ocr review. Reuse the existing MCP client registration and definition-collection path rather than introducing a scan-specific MCP implementation. Keep file_read_diff hidden in scan mode; enabling MCP must not add a diff where none exists. The scan pre-plan remains tool-free.

Expected behavior: with a configured MCP server, ocr scan --path <file> can invoke an allowed external tool for context while reviewing that file. Without a configured server, scan behavior remains unchanged.

Scope

  • Files/areas: cmd/opencodereview/scan_cmd.go, shared MCP initialization in cmd/opencodereview/review_cmd.go (and shared CLI code as needed), scan integration tests, and pages/src/content/docs/en/mcp.md.
  • Connect MCP servers before creating the scan agent; add only successfully registered MCP definitions to its main-task tool list and close clients on all exit paths. Preserve --preview as a no-LLM/no-MCP-startup operation.
  • Use the existing internal/mcp provider and shared internal/llmloop execution path; do not introduce new scan-only MCP configuration or change the review command's behavior.

Acceptance Criteria

  • ocr scan discovers and invokes configured, allowlisted MCP tools through both supported transports (local stdio and remote Streamable HTTP); tools absent from an allowlist and conflicting/reserved names are not exposed.
  • A failing MCP server is diagnosed without preventing scan from using its built-in tools; successful clients are closed on success, scan failure, and cancellation. ocr scan --preview neither connects to nor starts MCP servers.
  • Scan's main task receives MCP tool definitions and their calls return usable context. file_read_diff remains unavailable, and the scan pre-plan does not gain tool access.
  • Add automated scan-level integration tests using working local and remote MCP test servers and a deterministic LLM stub that requests an MCP tool, consumes its response, and finishes a scan. Test the failure/allowlist/conflict/cleanup cases as well. Unit tests or mocks of registration alone are insufficient.
  • Document the scan behavior and demonstrate an actual end-to-end ocr scan --path <file> run against an MCP server. In the PR description, provide reproducible setup/commands, sanitized output or logs proving the tool was called and its result reached the scan agent, plus the observed result. Do not present AI-generated code or a green CI badge as a substitute for this verification.
  • If AI/LLM was used in the contribution, disclose the tools and models in the initial PR. Review and understand every AI-produced code, test, and documentation change yourself before requesting review; be able to explain the behavior and validation from your own understanding.
  • make test, make check, and make coverage pass.

Context

ocr scan predates the MCP integration. MCP startup, tool registration, and definition collection currently happen only in the review command (cmd/opencodereview/review_cmd.go); scan builds the same built-in registry but does not perform those steps (cmd/opencodereview/scan_cmd.go). The shared tool-use runner already accepts a registry and tool definitions. Existing MCP client tests in internal/mcp/ include real stdio and remote transport fixtures that can inform the scan-level tests.

This is open for a community contributor. Please comment if you plan to work on it; no assignee is required.

AI/LLM disclosure: This issue was drafted with OpenAI Codex (model gpt-6-sol) using local repository inspection and the GitHub CLI (gh).

Source: alibaba/open-code-review