Skip to content

refactor(mcp): replace vendored adapter with published pi-mcp-adapter package - #1141

Draft
pmateusz wants to merge 1 commit into
masterfrom
experimental-remove-mcp-vendoring
Draft

refactor(mcp): replace vendored adapter with published pi-mcp-adapter package#1141
pmateusz wants to merge 1 commit into
masterfrom
experimental-remove-mcp-vendoring

Conversation

@pmateusz

@pmateusz pmateusz commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Linked issue

Closes #0

What does this PR do?

Remove the in-repo mcp-adapter extension (~78 files) and depend on the published pi-mcp-adapter package instead. Kimchi-specific concerns live in a new thin src/extensions/mcp/ wrapper: config loading, OAuth storage migration, server probing, read-only tool registry integration, and tool annotation catalog. Adds --mcp-config CLI flag for pointing at a specific MCP config file, and updates ACP session/new handling, permissions, and the e2e MCP suites accordingly.

Checklist

  • I have read CONTRIBUTING.md and agree to the CLA
  • This PR links to an open issue above
  • Tests pass locally (pnpm run test)
  • Lint passes (pnpm run check)
  • Documentation updated if behavior changed

… package

Remove the in-repo mcp-adapter extension (~78 files) and depend on the
published pi-mcp-adapter package instead. Kimchi-specific concerns live
in a new thin src/extensions/mcp/ wrapper: config loading, OAuth storage
migration, server probing, read-only tool registry integration, and tool
annotation catalog. Adds --mcp-config CLI flag for pointing at a specific
MCP config file, and updates ACP session/new handling, permissions, and
the e2e MCP suites accordingly.

Co-Authored-By: Kimchi <noreply@kimchi.dev>
@readme-ai-writer

readme-ai-writer Bot commented Sep 4, 2026

Copy link
Copy Markdown

Documentation Changes Added

Page Section Action Summary
coding-mcp-serversGuides📝 UpdatedAdd documentation for the --mcp-config CLI flag that allows specifying a custom MCP configuration file path.
kimchi-cliGuides📝 UpdatedAdd --mcp-config flag to CLI usage section, remove obsolete maxToolResultChars/mcpSearchLimit/mcpSearch config options that were replaced by the published MCP adapter package.

🔗 View all changes in ReadMe


Actions

  • Merge documentation branch with PR merge
  • Delete documentation branch with PR close

If neither actions are selected, on PR close/merge the docs branch in ReadMe will remain open.

@kimchi-review

kimchi-review Bot commented Sep 4, 2026

Copy link
Copy Markdown

Kimchi Code Review

Property Value
Commit 8f7fb4a
Author @pmateusz
Files changed 116
Review status Completed
Comments 5 (2 info, 3 warning)
Duration 86s

Summary

📊 Review Score: 81/100 (overall code quality — 0 lowest, 100 highest)
⏱️ Estimated effort to review: 4/5 (1 = trivial, 5 = very complex)

🧪 Tests: yes — Existing tests were updated: src/commands/mcp.test.ts was rewritten to cover the new keyring-check subcommand and the upstream probe delegation, and src/extensions/context-budget.test.ts was updated for the new mcp/config.js path. However, the diff shows a large reduction in mcp.test.ts coverage (from 736 to 173 lines), removing many validation, OAuth isolation, timeout, cleanup, and large-payload tests. No new test files for the new facade modules are visible in the diff; the audit document describes manual/CI verification gates instead.

📝 Found 5 issue(s). See inline comments for details.

What to expect

Kimchi will analyze the changes in this pull request and post:

  • A summary of the overall changes
  • Inline comments on specific lines with findings categorized by issue type

The review typically completes within a few minutes. This comment will be updated once the review is ready.

Interact with Kimchi
  • @getkimchi review — re-trigger a full review on the latest commit
  • @getkimchi summary — regenerate the PR summary
  • @getkimchi ignore — skip this PR (no review will be posted)
  • Reply to any inline comment to ask follow-up questions or request clarification
Configuration

Reviews are configured by your organization admin.
Review instructions, excluded directories, and severity thresholds can be adjusted per repository in the Kimchi dashboard.


Powered by Kimchi — AI-powered code review by CAST AI

@pmateusz
pmateusz marked this pull request as draft September 4, 2026 14:13

@kimchi-review kimchi-review 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.

📊 Review Score: 81/100 (overall code quality — 0 lowest, 100 highest)
⏱️ Estimated effort to review: 4/5 (1 = trivial, 5 = very complex)

🧪 Tests: yes — Existing tests were updated: src/commands/mcp.test.ts was rewritten to cover the new keyring-check subcommand and the upstream probe delegation, and src/extensions/context-budget.test.ts was updated for the new mcp/config.js path. However, the diff shows a large reduction in mcp.test.ts coverage (from 736 to 173 lines), removing many validation, OAuth isolation, timeout, cleanup, and large-payload tests. No new test files for the new facade modules are visible in the diff; the audit document describes manual/CI verification gates instead.

📝 Found 5 issue(s). See inline comments for details.

Comment thread src/commands/mcp.test.ts
@@ -1,736 +1,173 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️🧪 Testing

The diff replaces the previous 736-line probe test suite with a 173-line suite, dropping coverage for input-validation edge cases, OAuth URL-mismatch credential isolation, stdin TTY/timeout/size guards, large-payload flush behavior, and finally-cleanup assertions. Without equivalent replacement tests in the diff, regressions in runProbe error paths are more likely to go undetected.

💡 Suggestion: Migrate the deleted probe tests to exercise UpstreamMcpProbe instead of McpServerManager, or add integration tests for kimchi mcp probe covering OAuth credential isolation, timeout paths, and adapter cleanup before this branch ships.

Comment thread src/commands/mcp.ts
@@ -114,76 +124,26 @@ async function runProbe(args: string[]): Promise<number> {
return await emitError("Server config must have either 'command' or 'url'", null)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️🏗️ Design

runProbe now sets timeoutMs to 60_000 and passes authenticate: true for every URL-based ServerEntry, not only servers that advertise OAuth support. If UpstreamMcpProbe.probeTools interprets authenticate: true as a request to start an OAuth flow, plain HTTP MCP servers may unnecessarily prompt for authorization and wait a full minute before failing.

💡 Suggestion: Drive the authenticate option and the longer timeout from the server's auth configuration (for example, definition.auth === "oauth" or an upstream supportsOAuth check) rather than from the presence of a URL.

Comment thread src/commands/mcp.ts
const usedThrowaway = probeName !== name

const manager = new McpServerManager()
const controller = new AbortController()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️⚠️ Error Handling

The finally block in runProbe only clears the timeout; it no longer calls manager.closeAll() or explicitly aborts the UpstreamMcpProbe instance. If probeTools throws before returning, the upstream adapter's subprocesses, HTTP transports, or OAuth callback listener could remain alive after the CLI exits.

💡 Suggestion: Call controller.abort() in the finally block and, if UpstreamMcpProbe exposes a close/dispose method, invoke it there so the command cleans up even when probeTools rejects.

Comment thread src/commands/mcp.ts
@@ -114,76 +124,26 @@ async function runProbe(args: string[]): Promise<number> {
return await emitError("Server config must have either 'command' or 'url'", null)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ℹ️🔧 Maintainability

The timeout message claims the 60-second limit is "including OAuth flow" for any server with a URL, even when the server does not use OAuth. This makes logs and error messages misleading for non-auth HTTP servers.

💡 Suggestion: Choose the timeout and message based on whether the server configuration actually requires OAuth, or rephrase the message to avoid implying OAuth for non-auth HTTP servers.

{
get: (_target, prop) => {
if (prop === "registerTool") return (tool: AnyToolDef) => tools.set(tool.name, tool)
if (prop === "getFlag") return () => undefined

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ℹ️🔧 Maintainability

The createCaptureApi proxy now intercepts getFlag and always returns undefined. Any extension whose registered tool surface depends on feature flags will register a different set of tools under measurement than in production, weakening the canonical context-budget measurement.

💡 Suggestion: Either mirror the real flag values from the extension API or document that getFlag is intentionally stubbed for the budget measurement and verify the resulting tool list remains representative.

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.

1 participant