Skip to content

fix(mcp): report incomplete inject and remove operations - #1439

Merged
SaulMoro merged 1 commit into
Tencent:mainfrom
ydflow:fix/mcp-command-failure-status
Oct 27, 2026
Merged

SaulMoro merged 1 commit into
Tencent:mainfrom
ydflow:fix/mcp-command-failure-status

Conversation

@ydflow

@ydflow ydflow commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

With a malformed tool config such as ~/.claude.json, teamai mcp inject and teamai mcp remove can exit 0 and print success or "Already up to date" / "Nothing to remove", even though that tool was skipped. Both commands now consume the reconciler's existing unparsed result, list any successful changes, report the operation as incomplete with a retry instruction, and exit 1, including with --dry-run.

Type of Change

  • Bug fix

Test Plan

  • npm run build
  • npx tsc --noEmit
  • npm run lint
  • npx vitest run src/__tests__/mcp-cmd.test.ts — 13 passed. New checks exercise both commands with/without writes and in normal/dry-run mode.
  • Added regression tests that fail before the runtime fix.
  • Real CLI: after building, npx vitest run --config vitest.e2e.config.ts src/__tests__/e2e/mcp-command-errors.test.ts src/__tests__/e2e/mcp-uninstall.test.ts --retry=0 — 2 files, 5 passed. The new file was rerun after strengthening its ownership assertion — 2 passed.
  • Full unit suite passes locally. An attempted npx vitest run --maxWorkers=4 on Windows was stopped after unrelated failures; the full local suite is not claimed to pass. Four representative failures were reproduced in a clean worktree at upstream 703d1c93e66d32c73e13ea6fffb14f7a9bfaf5a4: token permission assertions observe 0o666 instead of 0o600 (two cases), a skill-install ACK fails, and creating a path-alias symlink fails with EPERM. This is not a claim that every full-suite failure has been individually classified. Linux/macOS validation is left to CI.

Real-CLI regression scenario (Windows, offline git fixtures, Claude and Cursor config targets):

  1. Inject a team server into both valid tool configs.
  2. Corrupt Claude's JSON, then preview inject/remove: exit 1, with both tool configs and ownership records unchanged.
  3. Execute inject/remove: Cursor is updated/removed and its change is listed; Claude's broken bytes and ownership record remain intact; overall exit 1, with no global success message.
  4. Repeat without repairing Claude: still exit 1, with no "Already up to date" / "Nothing to remove" message.
  5. Repair Claude and retry: exit 0, with the intended update/removal completed.

Before the runtime fix, both new CLI cases failed at step 2 because the commands returned 0. No real model or remote provider requests are needed for these fixtures; extra provider/agent combinations are left to CI.

Related Issues

Found while reviewing MCP delivery error handling on current main. No duplicate Issue/PR found in the searches performed for this change.

Notes for Reviewers

The reconciliation engine and its file/ownership writes are unchanged. unparsed is produced by reconcileTargets and already read by env commands and team scripts; this change adds two command consumers. Partial updates remain applied, and mcp remove still releases only git exclusions the existing cleanup proves clean. The English/Chinese sharing guides and setup management reference describe the exit status and retry behavior.

Scripts that previously treated a skipped tool config as success will now receive a nonzero exit status. This is an intentional failure-reporting correction; repairing the named config and rerunning the command completes the operation.

@github-actions

Copy link
Copy Markdown

No findings in the specified PR diff.

The PR description satisfies the testing requirement: it records a build followed by representative real-CLI checks for both commands, covering dry runs, partial changes, preserved ownership records, and successful retries. Deferring extra provider/agent coverage to CI is acceptable.

Review was read-only; I did not run, build, or install anything from the PR.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This was generated by AI during triage.

@ydflow Thanks, this works on macOS too. With the built CLI, the git provider, Claude and Cursor, and a broken ~/.claude.json:

  • On main, mcp inject and mcp remove, with and without --dry-run, exit 0 with a false success, "Already up to date" or "Nothing to remove".
  • Here they exit 1. They list the Cursor change, then say the operation is incomplete and how to retry.
  • The broken file's bytes and its ownership record stay unchanged, and a rerun after repairing the file exits 0.
  • A config that can't be read because of its permissions also exits 1.
  • pull with the same broken config still exits 0 and reports the failed check, so it does not regress.

The other readers of unparsed (env commands, team scripts, pull, uninstall) stay consistent with this.

[P3 nit] When one tool was written and another skipped, the "Restart your AI tool session" hint is dropped (src/mcp-cmd.ts:150), although the written tool still needs a restart.

Verified at 9523c18: both new tests fail on main and pass here, also under a symlinked TMPDIR; tsc, lint, the related unit tests (459) and the e2e files that call mcp inject or mcp remove pass; CI is green. We agree with the CI review's "no findings".

@SaulMoro
SaulMoro merged commit 6050e0e into Tencent:main Oct 27, 2026
18 checks passed
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
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