Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

fix(mcp): keep a custom endpoint's or anthropic@ provider in MCP specs

Jack Rudenko626139593180
diff --git a/ai-docs/architecture/routing.md b/ai-docs/architecture/routing.md
index b2d60206..00e8f24b 100644
--- a/ai-docs/architecture/routing.md
+++ b/ai-docs/architecture/routing.md
@@ -73,9 +73,12 @@ subscription) would have served the bare name.
So `team` (`models`, `judges`), `create_session` and `run_prompt` remove the provider
(`stripUnrequestedProvider`, `mcp-server.ts`) unless the caller lists the spec in
`user_required_provider` (the user named the provider). Only a single `provider@model` whose
-model part is exactly a canonical model id of the cloud models catalog is changed; markers
-(`+pro`, `#fast`) stay. Unchanged: chains, local providers, `custom-url`, legacy syntax, and a
-wire id that is not a catalog model id (`kc@k3`), since its bare form may not route. The
+provider is a BUILT-IN claudish provider and whose model part is exactly a canonical model id of
+the cloud models catalog is changed; markers (`+pro`, `#fast`) stay. Unchanged: chains, local
+providers, `custom-url`, a user's custom endpoint (`corp-proxy@gpt-4o` names a vendor and a bill
+the bare name would not reach), an explicit metered `anthropic@claude-*`, legacy syntax, a wire id
+that is not a catalog model id (`kc@k3`), and two specs that would strip to one name
+(`or@kimi-k3`, `kc@kimi-k3`: a provider comparison keeps both providers and both efforts). The
answer names every removal (`provider_note` / `note`) and the MCP log records it.
`compare_models` is not changed: it is a debug tool, where comparing providers can be the
point.
diff --git a/packages/cli/src/mcp-blackbox/provider-fallback.blackbox.test.ts b/packages/cli/src/mcp-blackbox/provider-fallback.blackbox.test.ts
index 090e0ecd..6b661bb6 100644
--- a/packages/cli/src/mcp-blackbox/provider-fallback.blackbox.test.ts
+++ b/packages/cli/src/mcp-blackbox/provider-fallback.blackbox.test.ts
@@ -637,6 +637,27 @@ describe.skipIf(!MAGMUX_AVAILABLE)(
expect(byModel.get(judge)?.slice(-2)).toEqual(["--effort-override", "high"]);
}, 45_000);
+ test("team preserves colliding provider specs and their independent effort levels", async () => {
+ const mcp = await start();
+ const comparison = `or@${model}`;
+ const answer = await mcp.tool("team", {
+ mode: "run",
+ path: join(layout.cwd, "provider-comparison"),
+ models: [comparison, explicit],
+ input: "Answer this input.",
+ efforts: { [comparison]: "low", [explicit]: "high" },
+ });
+ expect(answer.isError).not.toBe(true);
+ expect(textOf(answer)).not.toContain("Provider removed");
+ const args = await waitFor(() => capturedArgv().length === 2 && capturedArgv(), {
+ what: "two provider-comparison children",
+ });
+ const byModel = new Map(args.map((argv) => [modelOf(argv), argv]));
+ expect([...byModel.keys()].sort()).toEqual([comparison, explicit].sort());
+ expect(byModel.get(comparison)?.slice(-2)).toEqual(["--effort-override", "low"]);
+ expect(byModel.get(explicit)?.slice(-2)).toEqual(["--effort-override", "high"]);
+ }, 45_000);
+
test("team judges use the same provider-intent set as models", async () => {
const mcp = await start();
const firstJudge = `openrouter@${model}`;
diff --git a/packages/cli/src/mcp-provider-strip.test.ts b/packages/cli/src/mcp-provider-strip.test.ts
index f1cee6e9..e662db08 100644
--- a/packages/cli/src/mcp-provider-strip.test.ts
+++ b/packages/cli/src/mcp-provider-strip.test.ts
@@ -12,7 +12,16 @@ const capture = JSON.parse(
"utf8"
)
) as { entries: Array<{ modelId: string; aliases?: string[] }> };
-const canonicalIds = new Set(capture.entries.map((entry) => entry.modelId));
+const wireCapture = JSON.parse(
+ readFileSync(
+ new URL("./test-fixtures/catalog-v3/wire-g-20261012101007285-7770c36e.json", import.meta.url),
+ "utf8"
+ )
+) as { entries: Array<{ modelId: string }> };
+const nativeModel = wireCapture.entries.find((entry) =>
+ entry.modelId.startsWith("claude-")
+)!.modelId;
+const canonicalIds = new Set([...capture.entries.map((entry) => entry.modelId), nativeModel]);
const model = capture.entries[0].modelId;
const secondModel = capture.entries.at(-1)!.modelId;
const wireId = capture.entries[0].aliases!.find((id) => id === "k3")!;
@@ -40,6 +49,24 @@ describe("stripUnrequestedProvider with captured canonical model ids", () => {
required: false,
expected: `kc@${wireId}`,
},
+ {
+ name: "custom endpoint with a canonical id",
+ spec: `corp-proxy@${model}`,
+ required: false,
+ expected: `corp-proxy@${model}`,
+ },
+ {
+ name: "unknown endpoint with a canonical id",
+ spec: `unregistered-endpoint@${model}`,
+ required: false,
+ expected: `unregistered-endpoint@${model}`,
+ },
+ {
+ name: "anthropic vendor is not a builtin claudish provider",
+ spec: `anthropic@${nativeModel}`,
+ required: false,
+ expected: `anthropic@${nativeModel}`,
+ },
{ name: "Ollama", spec: `ollama@${model}`, required: false, expected: `ollama@${model}` },
{
name: "LM Studio",
@@ -145,6 +172,27 @@ describe("strippedProviders", () => {
expect(specs).toEqual(original);
});
+ test("different providers for one canonical id stay distinct without strip notes", () => {
+ const specs = [`or@${model}`, `kc@${model}`, `openrouter@${secondModel}`];
+ const original = [...specs];
+ expect(strippedProviders(specs, new Set(), isCatalogModel)).toEqual({
+ specs: [specs[0], specs[1], secondModel],
+ stripped: [{ from: specs[2], to: secondModel }],
+ });
+ expect(specs).toEqual(original);
+ });
+
+ test("identical duplicate specs still strip with one note per occurrence", () => {
+ const spec = `kc@${model}`;
+ expect(strippedProviders([spec, spec], new Set(), isCatalogModel)).toEqual({
+ specs: [model, model],
+ stripped: [
+ { from: spec, to: model },
+ { from: spec, to: model },
+ ],
+ });
+ });
+
test("all required specs stay unchanged with no note", () => {
const specs = [`kc@${model}`, `openrouter@${secondModel}`];
expect(strippedProviders(specs, new Set(specs), isCatalogModel)).toEqual({
diff --git a/packages/cli/src/mcp-server.ts b/packages/cli/src/mcp-server.ts
index cabb01be..ff985266 100644
--- a/packages/cli/src/mcp-server.ts
+++ b/packages/cli/src/mcp-server.ts
@@ -77,6 +77,7 @@ import {
} from "./providers/preflight-chain.js";
import { probeLink } from "./providers/probe-live.js";
import type { ProbeTarget } from "./providers/probe-runner.js";
+import { BUILTIN_PROVIDERS } from "./providers/provider-definitions.js";
import { createProxyServer } from "./proxy-server.js";
import { renderEffortTableMarkdown, renderRecommendedMarkdown } from "./recommended-listing.js";
import { sanitizeForReport } from "./redact.js";
@@ -656,7 +657,11 @@ export function stripUnrequestedProvider(
if (required || parseModelChain(spec).length !== 1) return spec;
const parsed = parseModelSpec(spec);
if (!parsed.isExplicitProvider || parsed.isLegacySyntax) return spec;
- if (parsed.provider === "custom-url" || isLocalProviderName(parsed.provider)) return spec;
+ // Only a built-in claudish provider: a user's custom endpoint (`corp-proxy@gpt-4o`)
+ // or an explicit metered `anthropic@claude-*` names a vendor and a bill the
+ // bare name would not reach.
+ const builtin = BUILTIN_PROVIDERS.find((p) => p.name === parsed.provider);
+ if (!builtin || builtin.isLocal || isLocalProviderName(parsed.provider)) return spec;
if (!isCatalogModel(parsed.model)) return spec;
return spec.slice(spec.indexOf("@") + 1);
}
@@ -690,10 +695,19 @@ export function strippedProviders(
required: ReadonlySet<string>,
isCatalogModel?: (id: string) => boolean
): { specs: string[]; stripped: Array<{ from: string; to: string }> } {
+ const proposed = specs.map((from) =>
+ stripUnrequestedProvider(from, required.has(from), isCatalogModel)
+ );
+ // Two different specs that would strip to one name (`or@kimi-k3`, `kc@kimi-k3`)
+ // are a provider comparison: both keep their provider, so neither slot loses
+ // its route or its effort to the other.
const stripped: Array<{ from: string; to: string }> = [];
- const out = specs.map((from) => {
- const to = stripUnrequestedProvider(from, required.has(from), isCatalogModel);
- if (to !== from) stripped.push({ from, to });
+ const out = specs.map((from, i) => {
+ const to = proposed[i];
+ if (to === from) return from;
+ const collides = proposed.some((other, j) => j !== i && other === to && specs[j] !== from);
+ if (collides) return from;
+ stripped.push({ from, to });
return to;
});
if (stripped.length > 0) {