Skip to content

Commit 680152e

Browse files
t3dotggclaude
andauthored
fix(server): agents get a short, current model list instead of a 55k-character catalog dump (#22889)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 810e8f6 commit 680152e

11 files changed

Lines changed: 440 additions & 56 deletions

File tree

‎apps/server/src/mcp/OrchestratorMcpService.test.ts‎

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
EnvironmentId,
66
MessageId,
77
NodeId,
8+
type OrchestratorMcpCapabilitiesResult,
89
OrchestratorMcpTarget,
910
type OrchestrationV2ThreadShell,
1011
type ScheduledTask,
@@ -1156,6 +1157,176 @@ describe("OrchestratorMcpService provider resolution", () => {
11561157
}),
11571158
);
11581159

1160+
describe("listed models", () => {
1161+
const opencodeInstanceId = ProviderInstanceId.make("opencode");
1162+
const model = (slug: string, extra: Partial<ServerProvider["models"][number]> = {}) => ({
1163+
slug,
1164+
name: slug,
1165+
isCustom: false,
1166+
capabilities: null,
1167+
...extra,
1168+
});
1169+
const opencodeSlugs = Array.from(
1170+
{ length: 12 },
1171+
(_, index) => `oc/m${String(index + 1).padStart(2, "0")}`,
1172+
);
1173+
const catalog: ReadonlyArray<ServerProvider> = [
1174+
{
1175+
...providerSnapshot({
1176+
instanceId: codexInstanceId,
1177+
driver: ProviderDriverKind.make("codex"),
1178+
}),
1179+
models: [
1180+
model("gpt-6", {
1181+
name: "Sol",
1182+
capabilities: {
1183+
optionDescriptors: [
1184+
{
1185+
id: "effort",
1186+
label: "Reasoning",
1187+
description: "How hard the model thinks.",
1188+
type: "select",
1189+
options: [
1190+
{ id: "low", label: "Low", description: "Fast." },
1191+
{ id: "high", label: "High", isDefault: true },
1192+
],
1193+
promptInjectedValues: ["high"],
1194+
},
1195+
{ id: "fastMode", label: "Fast", type: "boolean" },
1196+
{
1197+
id: "agent",
1198+
label: "Agent",
1199+
type: "select",
1200+
options: [{ id: "build", label: "Build" }],
1201+
currentValue: "build",
1202+
},
1203+
],
1204+
},
1205+
}),
1206+
model("gpt-5", { isLegacy: true }),
1207+
model("gpt-4", { isLegacy: true }),
1208+
model("gpt-3", { name: "GPT-3", isLegacy: true }),
1209+
model("my-alpha", { isCustom: true }),
1210+
],
1211+
},
1212+
{
1213+
...providerSnapshot({
1214+
instanceId: opencodeInstanceId,
1215+
driver: ProviderDriverKind.make("opencode"),
1216+
}),
1217+
models: [
1218+
...opencodeSlugs.map((slug) => model(slug, { isLegacy: slug === "oc/m03" })),
1219+
model("oc-custom", { isCustom: true }),
1220+
],
1221+
},
1222+
];
1223+
1224+
const capabilitiesWith = (search?: string) =>
1225+
Effect.gen(function* () {
1226+
const service = yield* OrchestratorMcpService.OrchestratorMcpService;
1227+
return yield* service.capabilities(scope, search === undefined ? {} : { search });
1228+
}).pipe(
1229+
Effect.provide(
1230+
layerOrchestratorService.pipe(
1231+
Layer.provide(
1232+
Layer.mergeAll(
1233+
NodeServices.layer,
1234+
Layer.mock(ThreadManagementService.ThreadManagementService)({
1235+
getThreadRecords: () =>
1236+
Effect.succeed(
1237+
parentProjection([], { instanceId: codexInstanceId, model: "gpt-3" }),
1238+
),
1239+
}),
1240+
ServerSettings.layerTest({
1241+
favorites: [
1242+
{ provider: codexInstanceId, model: "gpt-4" },
1243+
{ provider: opencodeInstanceId, model: "oc/m10" },
1244+
],
1245+
providerModelPreferences: {
1246+
[opencodeInstanceId]: { hiddenModels: ["oc/m02"], modelOrder: ["oc/m12"] },
1247+
},
1248+
}),
1249+
providerRegistryLayer(catalog),
1250+
adapterRegistryLayer([codexInstanceId, opencodeInstanceId]),
1251+
Layer.mock(ProjectService.ProjectService)({}),
1252+
Layer.mock(SecretRequests.SecretRequests)({}),
1253+
Layer.mock(ScheduledTaskService.ScheduledTaskService)({}),
1254+
),
1255+
),
1256+
),
1257+
),
1258+
);
1259+
1260+
const listing = (capabilities: OrchestratorMcpCapabilitiesResult) =>
1261+
capabilities.providers.map((provider) => ({
1262+
id: provider.providerInstanceId,
1263+
models: provider.models.map((entry) => entry.id),
1264+
omitted: provider.omittedModels ?? 0,
1265+
}));
1266+
1267+
it.effect(
1268+
"skips legacy models, lists the first 8 of large catalogs, and keeps pinned models",
1269+
() =>
1270+
Effect.gen(function* () {
1271+
assert.deepEqual(listing(yield* capabilitiesWith()), [
1272+
// gpt-4 is a favorite and gpt-3 is the caller's model; legacy gpt-5 is left out.
1273+
{ id: codexInstanceId, models: ["gpt-6", "gpt-4", "gpt-3", "my-alpha"], omitted: 1 },
1274+
{
1275+
id: opencodeInstanceId,
1276+
models: [
1277+
"oc/m12",
1278+
"oc/m01",
1279+
"oc/m04",
1280+
"oc/m05",
1281+
"oc/m06",
1282+
"oc/m07",
1283+
"oc/m08",
1284+
"oc/m09",
1285+
"oc/m10",
1286+
"oc-custom",
1287+
],
1288+
omitted: 2,
1289+
},
1290+
]);
1291+
}),
1292+
);
1293+
1294+
it.effect("search matches every word and caps each provider's matches", () =>
1295+
Effect.gen(function* () {
1296+
assert.deepEqual(listing(yield* capabilitiesWith("GPT 5")), [
1297+
{ id: codexInstanceId, models: ["gpt-5"], omitted: 0 },
1298+
{ id: opencodeInstanceId, models: [], omitted: 0 },
1299+
]);
1300+
const opencode = listing(yield* capabilitiesWith("oc/m"))[1];
1301+
assert.deepEqual(opencode, {
1302+
id: opencodeInstanceId,
1303+
models: ["oc/m12", "oc/m01", "oc/m03", "oc/m04", "oc/m05", "oc/m06", "oc/m07", "oc/m08"],
1304+
omitted: 3,
1305+
});
1306+
}),
1307+
);
1308+
1309+
it.effect("describes models by id, distinct label, and option values", () =>
1310+
Effect.gen(function* () {
1311+
const codex = (yield* capabilitiesWith()).providers[0];
1312+
assert.deepEqual(codex?.models.slice(0, 4), [
1313+
{
1314+
id: "gpt-6",
1315+
label: "Sol",
1316+
options: [
1317+
{ id: "effort", values: ["low", "high"], default: "high" },
1318+
{ id: "fastMode", values: [false, true] },
1319+
{ id: "agent", values: ["build"], default: "build" },
1320+
],
1321+
},
1322+
{ id: "gpt-4" },
1323+
{ id: "gpt-3" },
1324+
{ id: "my-alpha" },
1325+
]);
1326+
}),
1327+
);
1328+
});
1329+
11591330
it.effect("rejects delegation to a provider without a registered adapter", () =>
11601331
Effect.gen(function* () {
11611332
const forkOnlyInstanceId = ProviderInstanceId.make("forkOnly");

‎apps/server/src/mcp/OrchestratorMcpService.ts‎

Lines changed: 91 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import {
1313
type OrchestrationV2ThreadLaunchWorkspaceStrategy,
1414
type OrchestrationV2TurnItem,
1515
OrchestratorMcpFailure,
16+
type OrchestratorMcpCapabilitiesInput,
1617
type OrchestratorMcpCapabilitiesResult,
18+
type OrchestratorMcpModelOption,
1719
type OrchestratorMcpCreateThreadsInput,
1820
type OrchestratorMcpCreateThreadsResult,
1921
type OrchestratorMcpCreatedThread,
@@ -59,9 +61,11 @@ import {
5961
type ScheduledTask,
6062
type ScheduledTaskUpsertInput,
6163
type ServerProvider,
64+
type ServerProviderModel,
6265
ThreadId,
6366
isOrchestrationV2WorkActive,
6467
} from "@t3tools/contracts";
68+
import { getProviderOptionCurrentValue } from "@t3tools/shared/model";
6569
import { runRanAfter } from "@t3tools/shared/orchestrationV2ThreadError";
6670
import {
6771
normalizeThreadPullRequestKey,
@@ -136,6 +140,7 @@ type TerminalTaskStatus = Extract<
136140
export interface OrchestratorMcpServiceShape {
137141
readonly capabilities: (
138142
scope: McpInvocationScope,
143+
input?: OrchestratorMcpCapabilitiesInput,
139144
) => Effect.Effect<OrchestratorMcpCapabilitiesResult, OrchestratorMcpFailure>;
140145
readonly delegateTask: (
141146
scope: McpInvocationScope,
@@ -303,6 +308,61 @@ function scheduledTaskSummary(task: ScheduledTask, mayRun: boolean): Orchestrato
303308
};
304309
}
305310

311+
/**
312+
* Large catalogs (OpenCode, Cursor, Pi) can list hundreds of models, so agents
313+
* get a short list by default and search for the rest. These providers have
314+
* small official catalogs, so all their current models are listed.
315+
*/
316+
const FULL_CATALOG_DRIVERS: ReadonlySet<string> = new Set(["codex", "claudeAgent", "muse", "grok"]);
317+
const LISTED_MODEL_LIMIT = 8;
318+
319+
/**
320+
* Picks the models orchestrator_capabilities shows for one provider. Hidden
321+
* models never appear. With search terms, lists matches; otherwise lists pinned
322+
* models (custom, favorite, the caller's own) plus the provider's non-legacy
323+
* models, or only the first few in the user's model order for large catalogs.
324+
*/
325+
function listCapabilityModels(input: {
326+
readonly provider: ServerProvider;
327+
readonly preferences:
328+
| { readonly hiddenModels: ReadonlyArray<string>; readonly modelOrder: ReadonlyArray<string> }
329+
| undefined;
330+
readonly isPinned: (model: ServerProviderModel) => boolean;
331+
readonly searchTerms: ReadonlyArray<string>;
332+
}) {
333+
const rank = new Map(input.preferences?.modelOrder.map((slug, index) => [slug, index]));
334+
const visible = input.provider.models
335+
.filter((model) => model.isCustom || !input.preferences?.hiddenModels.includes(model.slug))
336+
.toSorted((a, b) => (rank.get(a.slug) ?? rank.size) - (rank.get(b.slug) ?? rank.size));
337+
if (input.searchTerms.length > 0) {
338+
const matches = visible.filter((model) => {
339+
const text = `${model.slug} ${model.name} ${model.subProvider ?? ""}`.toLowerCase();
340+
return input.searchTerms.every((term) => text.includes(term));
341+
});
342+
const listed = matches.slice(0, LISTED_MODEL_LIMIT);
343+
return { listed, omitted: matches.length - listed.length };
344+
}
345+
const current = visible.filter((model) => !model.isLegacy);
346+
const shown = new Set(
347+
FULL_CATALOG_DRIVERS.has(input.provider.driver)
348+
? current
349+
: current.slice(0, LISTED_MODEL_LIMIT),
350+
);
351+
const listed = visible.filter((model) => input.isPinned(model) || shown.has(model));
352+
return { listed, omitted: visible.length - listed.length };
353+
}
354+
355+
/** Option ids and allowed values are all a delegating agent needs; labels are UI copy. */
356+
function capabilityModelOption(descriptor: ProviderOptionDescriptor): OrchestratorMcpModelOption {
357+
const defaultValue = getProviderOptionCurrentValue(descriptor);
358+
return {
359+
id: descriptor.id,
360+
values:
361+
descriptor.type === "boolean" ? [false, true] : descriptor.options.map((choice) => choice.id),
362+
...(defaultValue === undefined ? {} : { default: defaultValue }),
363+
};
364+
}
365+
306366
function providerConstraints(
307367
provider: ServerProvider | undefined,
308368
supportsOrchestrationV2: boolean,
@@ -2011,44 +2071,54 @@ const make = Effect.gen(function* () {
20112071
return { status, secretRef: secretRef.value };
20122072
}),
20132073

2014-
capabilities: Effect.fn("OrchestratorMcpService.capabilities")(function* (scope) {
2074+
capabilities: Effect.fn("OrchestratorMcpService.capabilities")(function* (scope, input = {}) {
20152075
const { parent, limits } = yield* loadCaller(scope);
20162076
const providers = yield* loadProviders;
20172077
const orchestrationCapableInstanceIds = yield* loadOrchestrationCapableInstanceIds();
2018-
const modelPreferences = yield* serverSettings.getSettings.pipe(
2019-
Effect.map((settings) => settings.providerModelPreferences ?? {}),
2078+
const settings = yield* serverSettings.getSettings.pipe(
20202079
Effect.mapError(() => failure("orchestration_error", "Unable to read server settings.")),
20212080
);
2081+
const inherited = parent?.thread.modelSelection;
2082+
const searchTerms = input.search?.toLowerCase().split(/\s+/) ?? [];
20222083
return {
20232084
parentThreadId: parent?.thread.id ?? null,
2024-
inheritedProviderInstanceId: parent?.thread.modelSelection.instanceId ?? null,
2025-
inheritedModel: parent?.thread.modelSelection.model ?? null,
2026-
inheritedOptions: parent?.thread.modelSelection.options ?? [],
2085+
inheritedProviderInstanceId: inherited?.instanceId ?? null,
2086+
inheritedModel: inherited?.model ?? null,
2087+
inheritedOptions: inherited?.options ?? [],
20272088
runtimeMode: limits.runtimeMode,
20282089
interactionMode: limits.interactionMode,
20292090
providers: providers.map((provider) => {
20302091
const constraints = providerConstraints(
20312092
provider,
20322093
orchestrationCapableInstanceIds.has(provider.instanceId),
20332094
);
2095+
const { listed, omitted } = listCapabilityModels({
2096+
provider,
2097+
preferences: settings.providerModelPreferences?.[provider.instanceId],
2098+
searchTerms,
2099+
isPinned: (model) =>
2100+
model.isCustom ||
2101+
(inherited?.instanceId === provider.instanceId && inherited.model === model.slug) ||
2102+
(settings.favorites ?? []).some(
2103+
(favorite) =>
2104+
favorite.provider === provider.instanceId && favorite.model === model.slug,
2105+
),
2106+
});
20342107
return {
20352108
providerInstanceId: provider.instanceId,
20362109
driverKind: provider.driver,
2037-
displayName: provider?.displayName ?? null,
2038-
models:
2039-
provider?.models
2040-
.filter(
2041-
(model) =>
2042-
model.isCustom ||
2043-
!modelPreferences[provider.instanceId]?.hiddenModels.includes(model.slug),
2044-
)
2045-
.map((model) => ({
2046-
id: model.slug,
2047-
label: model.name ?? null,
2048-
...(model.capabilities?.optionDescriptors === undefined
2049-
? {}
2050-
: { options: model.capabilities.optionDescriptors }),
2051-
})) ?? [],
2110+
displayName: provider.displayName ?? null,
2111+
models: listed.map((model) => {
2112+
const options = model.capabilities?.optionDescriptors ?? [];
2113+
return {
2114+
id: model.slug,
2115+
...(model.name.toLowerCase() === model.slug.toLowerCase()
2116+
? {}
2117+
: { label: model.name }),
2118+
...(options.length === 0 ? {} : { options: options.map(capabilityModelOption) }),
2119+
};
2120+
}),
2121+
...(omitted === 0 ? {} : { omittedModels: omitted }),
20522122
...(provider.supportedRuntimeModes === undefined ||
20532123
provider.supportedRuntimeModes.length === 0
20542124
? {}

‎apps/server/src/mcp/toolkits/orchestrator/handlers.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import * as OrchestratorMcpService from "../../OrchestratorMcpService.ts";
99
import * as ThreadMetadataMcpService from "../../ThreadMetadataMcpService.ts";
1010

1111
const handlers = {
12-
orchestrator_capabilities: McpToolAccess.reads(() =>
12+
orchestrator_capabilities: McpToolAccess.reads((input) =>
1313
Effect.gen(function* () {
1414
const scope = yield* McpInvocationContext.McpInvocationContext;
1515
const service = yield* OrchestratorMcpService.OrchestratorMcpService;
16-
return yield* service.capabilities(scope);
16+
return yield* service.capabilities(scope, input);
1717
}),
1818
),
1919
delegate_task: McpToolAccess.actsAsCaller((input) =>

‎apps/server/src/mcp/toolkits/orchestrator/tools.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
OrchestratorMcpCapabilitiesInput,
23
OrchestratorMcpCapabilitiesResult,
34
OrchestrationV2StopWorkflowInput,
45
OrchestratorMcpCreateThreadsInput,
@@ -52,7 +53,8 @@ const threadMetadataDependencies = [
5253

5354
const OrchestratorCapabilitiesTool = Tool.make("orchestrator_capabilities", {
5455
description:
55-
"List the V2 provider instances and their current models from the same live catalog as the composer, including configured custom models, inherited runtime settings, and app-owned orchestration features available to this caller. For a separate top-level thread in a new or existing worktree, use t3_thread_launch with workspaceStrategy.",
56+
"List the V2 provider instances, a short list of their models from the same live catalog as the composer, inherited runtime settings, and app-owned orchestration features available to this caller. The list has the user's favorite and custom models, your own model, every current Codex, Claude, Muse and Grok model, and the first 8 current models of other providers. Other legacy models are left out. omittedModels counts models left out; pass search, such as 'sonnet 4.6', to find them. delegate_task accepts any catalog model, listed or not. For a separate top-level thread in a new or existing worktree, use t3_thread_launch with workspaceStrategy.",
57+
parameters: OrchestratorMcpCapabilitiesInput,
5658
success: OrchestratorMcpCapabilitiesResult,
5759
failure: OrchestratorMcpFailure,
5860
failureMode: "return",

0 commit comments

Comments
 (0)