Skip to content

Commit f0b8591

Browse files
t3dotggclaude
andcommitted
fix(server): orchestrator_capabilities lists a short set of models
Large catalogs such as OpenCode returned every model with full option descriptors, about 55k characters per call. Each provider now lists custom, favorite, and the caller's models plus current Codex, Claude, Muse, and Grok models, or the first 8 current models elsewhere. A search input finds the rest, and model options are reduced to ids, values, and defaults. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 448b8a9 commit f0b8591

7 files changed

Lines changed: 299 additions & 32 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,
@@ -283,6 +288,61 @@ function scheduledTaskSummary(task: ScheduledTask, mayRun: boolean): Orchestrato
283288
};
284289
}
285290

291+
/**
292+
* Large catalogs (OpenCode, Cursor, Pi) can list hundreds of models, so agents
293+
* get a short list by default and search for the rest. These providers have
294+
* small official catalogs, so all their current models are listed.
295+
*/
296+
const FULL_CATALOG_DRIVERS: ReadonlySet<string> = new Set(["codex", "claudeAgent", "muse", "grok"]);
297+
const LISTED_MODEL_LIMIT = 8;
298+
299+
/**
300+
* Picks the models orchestrator_capabilities shows for one provider. Hidden
301+
* models never appear. With search terms, lists matches; otherwise lists pinned
302+
* models (custom, favorite, the caller's own) plus the provider's non-legacy
303+
* models, or only the first few in the user's model order for large catalogs.
304+
*/
305+
function listCapabilityModels(input: {
306+
readonly provider: ServerProvider;
307+
readonly preferences:
308+
| { readonly hiddenModels: ReadonlyArray<string>; readonly modelOrder: ReadonlyArray<string> }
309+
| undefined;
310+
readonly isPinned: (model: ServerProviderModel) => boolean;
311+
readonly searchTerms: ReadonlyArray<string>;
312+
}) {
313+
const rank = new Map(input.preferences?.modelOrder.map((slug, index) => [slug, index]));
314+
const visible = input.provider.models
315+
.filter((model) => model.isCustom || !input.preferences?.hiddenModels.includes(model.slug))
316+
.toSorted((a, b) => (rank.get(a.slug) ?? rank.size) - (rank.get(b.slug) ?? rank.size));
317+
if (input.searchTerms.length > 0) {
318+
const matches = visible.filter((model) => {
319+
const text = `${model.slug} ${model.name} ${model.subProvider ?? ""}`.toLowerCase();
320+
return input.searchTerms.every((term) => text.includes(term));
321+
});
322+
const listed = matches.slice(0, LISTED_MODEL_LIMIT);
323+
return { listed, omitted: matches.length - listed.length };
324+
}
325+
const current = visible.filter((model) => !model.isLegacy);
326+
const shown = new Set(
327+
FULL_CATALOG_DRIVERS.has(input.provider.driver)
328+
? current
329+
: current.slice(0, LISTED_MODEL_LIMIT),
330+
);
331+
const listed = visible.filter((model) => input.isPinned(model) || shown.has(model));
332+
return { listed, omitted: visible.length - listed.length };
333+
}
334+
335+
/** Option ids and allowed values are all a delegating agent needs; labels are UI copy. */
336+
function capabilityModelOption(descriptor: ProviderOptionDescriptor): OrchestratorMcpModelOption {
337+
const defaultValue = getProviderOptionCurrentValue(descriptor);
338+
return {
339+
id: descriptor.id,
340+
values:
341+
descriptor.type === "boolean" ? [false, true] : descriptor.options.map((choice) => choice.id),
342+
...(defaultValue === undefined ? {} : { default: defaultValue }),
343+
};
344+
}
345+
286346
function providerConstraints(
287347
provider: ServerProvider | undefined,
288348
supportsOrchestrationV2: boolean,
@@ -1987,44 +2047,54 @@ const make = Effect.gen(function* () {
19872047
return { status, secretRef: secretRef.value };
19882048
}),
19892049

1990-
capabilities: Effect.fn("OrchestratorMcpService.capabilities")(function* (scope) {
2050+
capabilities: Effect.fn("OrchestratorMcpService.capabilities")(function* (scope, input = {}) {
19912051
const { parent, limits } = yield* loadCaller(scope);
19922052
const providers = yield* loadProviders;
19932053
const orchestrationCapableInstanceIds = yield* loadOrchestrationCapableInstanceIds();
1994-
const modelPreferences = yield* serverSettings.getSettings.pipe(
1995-
Effect.map((settings) => settings.providerModelPreferences ?? {}),
2054+
const settings = yield* serverSettings.getSettings.pipe(
19962055
Effect.mapError(() => failure("orchestration_error", "Unable to read server settings.")),
19972056
);
2057+
const inherited = parent?.thread.modelSelection;
2058+
const searchTerms = input.search?.toLowerCase().split(/\s+/) ?? [];
19982059
return {
19992060
parentThreadId: parent?.thread.id ?? null,
2000-
inheritedProviderInstanceId: parent?.thread.modelSelection.instanceId ?? null,
2001-
inheritedModel: parent?.thread.modelSelection.model ?? null,
2002-
inheritedOptions: parent?.thread.modelSelection.options ?? [],
2061+
inheritedProviderInstanceId: inherited?.instanceId ?? null,
2062+
inheritedModel: inherited?.model ?? null,
2063+
inheritedOptions: inherited?.options ?? [],
20032064
runtimeMode: limits.runtimeMode,
20042065
interactionMode: limits.interactionMode,
20052066
providers: providers.map((provider) => {
20062067
const constraints = providerConstraints(
20072068
provider,
20082069
orchestrationCapableInstanceIds.has(provider.instanceId),
20092070
);
2071+
const { listed, omitted } = listCapabilityModels({
2072+
provider,
2073+
preferences: settings.providerModelPreferences?.[provider.instanceId],
2074+
searchTerms,
2075+
isPinned: (model) =>
2076+
model.isCustom ||
2077+
(inherited?.instanceId === provider.instanceId && inherited.model === model.slug) ||
2078+
(settings.favorites ?? []).some(
2079+
(favorite) =>
2080+
favorite.provider === provider.instanceId && favorite.model === model.slug,
2081+
),
2082+
});
20102083
return {
20112084
providerInstanceId: provider.instanceId,
20122085
driverKind: provider.driver,
2013-
displayName: provider?.displayName ?? null,
2014-
models:
2015-
provider?.models
2016-
.filter(
2017-
(model) =>
2018-
model.isCustom ||
2019-
!modelPreferences[provider.instanceId]?.hiddenModels.includes(model.slug),
2020-
)
2021-
.map((model) => ({
2022-
id: model.slug,
2023-
label: model.name ?? null,
2024-
...(model.capabilities?.optionDescriptors === undefined
2025-
? {}
2026-
: { options: model.capabilities.optionDescriptors }),
2027-
})) ?? [],
2086+
displayName: provider.displayName ?? null,
2087+
models: listed.map((model) => {
2088+
const options = model.capabilities?.optionDescriptors ?? [];
2089+
return {
2090+
id: model.slug,
2091+
...(model.name.toLowerCase() === model.slug.toLowerCase()
2092+
? {}
2093+
: { label: model.name }),
2094+
...(options.length === 0 ? {} : { options: options.map(capabilityModelOption) }),
2095+
};
2096+
}),
2097+
...(omitted === 0 ? {} : { omittedModels: omitted }),
20282098
...(provider.supportedRuntimeModes === undefined ||
20292099
provider.supportedRuntimeModes.length === 0
20302100
? {}

‎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. 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",

‎docs/orchestration-v2/orchestrator-mcp-server.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ Returns:
207207
Unavailable providers include model-visible constraints such as missing V2
208208
adapter support, disabled state, missing executable, or missing authentication.
209209

210+
The model list is short on purpose: catalogs such as OpenCode can hold hundreds
211+
of models, and every call lands in the agent's context. Each provider lists
212+
custom, favorite, and the caller's own models, plus all current (non-legacy)
213+
models for Codex, Claude, Muse, and Grok, or the first 8 current models in the
214+
user's model order for other providers. `omittedModels` counts the rest, and the
215+
`search` input finds them, legacy models included. `delegate_task` still accepts
216+
any catalog model.
217+
210218
### `delegate_task`
211219

212220
Creates a T3-owned child thread and immediately dispatches the supplied task

0 commit comments

Comments
 (0)