Skip to content

fix(remove): remove a root MCP server named 'ambiguous' instead of refusing it silently (#862) - #864

Merged
jeff-r2026 merged 1 commit into
Tencent:mainfrom
SaulMoro:fix/remove-mcp-ambiguous-name
Sep 28, 2026
Merged

jeff-r2026 merged 1 commit into
Tencent:mainfrom
SaulMoro:fix/remove-mcp-ambiguous-name

Conversation

@SaulMoro

Copy link
Copy Markdown
Collaborator

Summary

teamai remove mcp ambiguous refused to remove a server named ambiguous from mcp/mcp.yaml, and gave no reason. mcpRemovalTarget returned string | 'ambiguous' | null, so a server name and the refusal sentinel had the same type, and the root-file match return name came back as 'ambiguous'. The function now returns a tagged result, and the caller switches on kind with a never check:

-mcpRemovalTarget(...): Promise<string | 'ambiguous' | null>
+type McpRemovalTarget = { kind: 'target'; name: string } | { kind: 'ambiguous' } | { kind: 'not-found' };
+mcpRemovalTarget(...): Promise<McpRemovalTarget>

 removeCore
   for name of names
     mcpRemovalTarget(name)
-      if target === 'ambiguous' -> refuse        // also a root server named "ambiguous"
-      else if target === null    -> not found
-      else                       -> found.push(target)
+      switch target.kind
+        'ambiguous' -> refuse                    // every path that returns it logs why first
+        'not-found' -> not found
+        'target'    -> found.push(target.name)
+        default     -> const unhandled: never = target

Every path returns what it returned before, now tagged: each 'ambiguous' becomes { kind: 'ambiguous' } and each null becomes { kind: 'not-found' }. The agents path sets its ambiguous flag inline and publishedNameFor returns string | null, so no other resource type has this collision.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Test Plan

  • npx tsc --noEmit passes
  • npm run lint passes (0 warnings)
  • npx vitest run passes (5174 passed; the 9 failures are 15 s timeouts in git-kind-reports.test.ts, which times out identically on main at a8ab8e0 on this machine)
  • Added/updated tests for the change

Three tests in remove-command.test.ts under teamai remove mcp picks one file, through the exported remove:

removes a root server named "ambiguous"                         before: FAIL (removeItem called 0 times)   after: pass
refuses "ambiguous" when only several namespaces define it      before: pass                               after: pass
skips a name no MCP file defines as not found                   before: pass                               after: pass

npx vitest run src/__tests__/remove-command.test.ts: 11 passed. npx vitest run --config vitest.e2e.config.ts src/__tests__/e2e/remove-mcp-namespaces.test.ts: 7 passed.

Real CLI, built dist/index.js, sandbox HOME, a local bare remote whose mcp/mcp.yaml defines ambiguous and db:

Before (main at a8ab8e0):

$ teamai remove mcp ambiguous --force
✖ Nothing was removed.
exit code: 1
removal branch: <none>

After (this branch):

$ teamai remove mcp ambiguous --force

Will remove 1 mcp:
  - ambiguous

From: team repo + all local AI tool directories

- Removing 1 mcp...
✔ Removed 1 mcp from 1 location(s)
- Creating Pull Request...
✖ Failed to create PR: Invalid Git repo URL: repository paths need an owner/group and a repository name (expected https://host/group/repo.git, ssh://git@host/group/repo.git, or git@host:group/repo.git)
ℹ Branch teamai/push/e2e/20260928-004020 has been pushed. You can create a PR manually.
exit code: 0
removal branch: teamai/push/e2e/20260928-004020
$ git show teamai/push/e2e/20260928-004020:mcp/mcp.yaml
servers:
  - name: db
    transport: http
    url: https://db.example.com

The Failed to create PR line is the sandbox: the fixture's remote URL names no provider repository, so the branch is pushed and the PR step falls back, as in the existing remove-mcp-namespaces e2e fixture.

Related Issues

Closes #862

Notes for Reviewers

The caller's ambiguous flag and the ambiguous kind keep their existing name, although the kind also covers the refusals for an MCP file that does not parse and for a bad --role / --project. Renaming it would widen the diff for no behavior change.

@jeff-r2026 jeff-r2026 self-assigned this Sep 28, 2026
@github-actions

Copy link
Copy Markdown

No findings.

The PR description documents sufficient testing, including a representative real-CLI end-to-end verification. Per instruction, I reviewed the diff only and did not run or install anything.

…fusing it silently (Tencent#862)

mcpRemovalTarget returned string | 'ambiguous' | null, so a root server
named 'ambiguous' came back as its own name and the caller read it as the
refusal sentinel: nothing removed, exit 1, no reason printed. Return a
tagged result and switch on its kind.
@SaulMoro
SaulMoro force-pushed the fix/remove-mcp-ambiguous-name branch from 7526d3f to 9e01eea Compare September 28, 2026 12:34
@github-actions

Copy link
Copy Markdown

No findings.

The PR description documents sufficient testing, including a representative real-CLI end-to-end verification. The tagged union cleanly resolves the sentinel/name collision while preserving existing behavior. Per instruction, I reviewed the diff only and did not run or install anything.

@jeff-r2026
jeff-r2026 merged commit e2fd0ab into Tencent:main Sep 28, 2026
13 checks passed
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…fusing it silently (Tencent#862) (Tencent#864)

mcpRemovalTarget returned string | 'ambiguous' | null, so a root server
named 'ambiguous' came back as its own name and the caller read it as the
refusal sentinel: nothing removed, exit 1, no reason printed. Return a
tagged result and switch on its kind.
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.

[bug] remove mcp refuses a root server named 'ambiguous' without saying why

2 participants