Skip to content

Commit 1776720

Browse files
committed
fix(server): orchestrator_capabilities defaults to favorite models with slim options
One capabilities call returned ~33.5k chars (~8-10k tokens) on a multi-provider setup: every model repeated full option descriptors with labels and descriptions. Default to the user's favorited models plus the caller's own (full catalog when no favorites are set), project options to ids/values/default/current, and report omittedModels so agents can expand with models:'all' or a provider filter.
1 parent e536bfd commit 1776720

5 files changed

Lines changed: 306 additions & 48 deletions

File tree

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

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
RunId,
1414
ThreadId,
1515
type OrchestrationV2ThreadProjection,
16+
type OrchestratorMcpCapabilitiesInput,
1617
type ServerProvider,
1718
} from "@t3tools/contracts";
1819
import * as DateTime from "effect/DateTime";
@@ -1084,6 +1085,187 @@ describe("OrchestratorMcpService provider resolution", () => {
10841085
}),
10851086
);
10861087

1088+
describe("model scope", () => {
1089+
const claudeInstanceId = ProviderInstanceId.make("claudeAgent");
1090+
const catalog: ReadonlyArray<ServerProvider> = [
1091+
{
1092+
...providerSnapshot({
1093+
instanceId: codexInstanceId,
1094+
driver: ProviderDriverKind.make("codex"),
1095+
}),
1096+
models: [
1097+
// The caller's own model, which is not a favorite.
1098+
{ slug: "gpt-5.4", name: "gpt-5.4", isCustom: false, capabilities: null },
1099+
{
1100+
slug: "gpt-5.5",
1101+
name: "GPT-5.5",
1102+
isCustom: false,
1103+
capabilities: {
1104+
optionDescriptors: [
1105+
{
1106+
id: "effort",
1107+
label: "Reasoning",
1108+
description: "How hard the model thinks.",
1109+
type: "select",
1110+
options: [
1111+
{ id: "low", label: "Low", description: "Fast." },
1112+
{ id: "high", label: "High", isDefault: true },
1113+
],
1114+
currentValue: "high",
1115+
promptInjectedValues: ["high"],
1116+
},
1117+
{ id: "fastMode", label: "Fast mode", type: "boolean", currentValue: false },
1118+
],
1119+
},
1120+
},
1121+
{ slug: "gpt-5.3", name: "gpt-5.3", isCustom: false, capabilities: null },
1122+
// Favorited but hidden: hiding wins.
1123+
{ slug: "gpt-5.4-mini", name: "Mini", isCustom: false, capabilities: null },
1124+
],
1125+
},
1126+
{
1127+
...providerSnapshot({
1128+
instanceId: claudeInstanceId,
1129+
driver: ProviderDriverKind.make("claudeAgent"),
1130+
}),
1131+
models: [
1132+
{ slug: "claude-opus", name: "claude-opus", isCustom: false, capabilities: null },
1133+
{ slug: "claude-sonnet", name: "claude-sonnet", isCustom: false, capabilities: null },
1134+
],
1135+
},
1136+
];
1137+
1138+
const layerFor = (
1139+
favorites: ReadonlyArray<{
1140+
readonly provider: ProviderInstanceId;
1141+
readonly model: string;
1142+
}> | null,
1143+
) =>
1144+
layerOrchestratorService.pipe(
1145+
Layer.provide(
1146+
Layer.mergeAll(
1147+
NodeServices.layer,
1148+
Layer.mock(ThreadManagementService.ThreadManagementService)({
1149+
getThreadRecords: () => Effect.succeed(parentProjection([])),
1150+
}),
1151+
ServerSettings.layerTest({
1152+
favorites,
1153+
providerModelPreferences: {
1154+
[codexInstanceId]: { hiddenModels: ["gpt-5.4-mini"], modelOrder: [] },
1155+
},
1156+
}),
1157+
providerRegistryLayer(catalog),
1158+
adapterRegistryLayer([codexInstanceId, claudeInstanceId]),
1159+
Layer.mock(ProjectService.ProjectService)({}),
1160+
Layer.mock(SecretRequests.SecretRequests)({}),
1161+
Layer.mock(ScheduledTaskService.ScheduledTaskService)({}),
1162+
),
1163+
),
1164+
);
1165+
1166+
const modelIds = (input: {
1167+
readonly favorites: Parameters<typeof layerFor>[0];
1168+
readonly request?: OrchestratorMcpCapabilitiesInput;
1169+
}) =>
1170+
Effect.gen(function* () {
1171+
const service = yield* OrchestratorMcpService.OrchestratorMcpService;
1172+
const capabilities = yield* service.capabilities(scope, input.request);
1173+
return capabilities.providers.map((provider) => ({
1174+
id: provider.providerInstanceId,
1175+
models: provider.models.map((model) => model.id),
1176+
omittedModels: provider.omittedModels,
1177+
}));
1178+
}).pipe(Effect.provide(layerFor(input.favorites)));
1179+
1180+
const favorites = [
1181+
{ provider: codexInstanceId, model: "gpt-5.5" },
1182+
{ provider: codexInstanceId, model: "gpt-5.4-mini" },
1183+
{ provider: claudeInstanceId, model: "claude-opus" },
1184+
];
1185+
1186+
it.effect("lists favorites plus the caller's own model by default", () =>
1187+
Effect.gen(function* () {
1188+
assert.deepEqual(yield* modelIds({ favorites }), [
1189+
{ id: codexInstanceId, models: ["gpt-5.4", "gpt-5.5"], omittedModels: 1 },
1190+
{ id: claudeInstanceId, models: ["claude-opus"], omittedModels: 1 },
1191+
]);
1192+
}),
1193+
);
1194+
1195+
it.effect("lists every visible model when asked for all, optionally for one provider", () =>
1196+
Effect.gen(function* () {
1197+
assert.deepEqual(yield* modelIds({ favorites, request: { models: "all" } }), [
1198+
{
1199+
id: codexInstanceId,
1200+
models: ["gpt-5.4", "gpt-5.5", "gpt-5.3"],
1201+
omittedModels: undefined,
1202+
},
1203+
{
1204+
id: claudeInstanceId,
1205+
models: ["claude-opus", "claude-sonnet"],
1206+
omittedModels: undefined,
1207+
},
1208+
]);
1209+
assert.deepEqual(
1210+
yield* modelIds({
1211+
favorites,
1212+
request: { models: "all", providerInstanceId: claudeInstanceId },
1213+
}),
1214+
[
1215+
{
1216+
id: claudeInstanceId,
1217+
models: ["claude-opus", "claude-sonnet"],
1218+
omittedModels: undefined,
1219+
},
1220+
],
1221+
);
1222+
}),
1223+
);
1224+
1225+
it.effect("lists every visible model when the user has no favorites", () =>
1226+
Effect.gen(function* () {
1227+
const everything = [
1228+
{
1229+
id: codexInstanceId,
1230+
models: ["gpt-5.4", "gpt-5.5", "gpt-5.3"],
1231+
omittedModels: undefined,
1232+
},
1233+
{
1234+
id: claudeInstanceId,
1235+
models: ["claude-opus", "claude-sonnet"],
1236+
omittedModels: undefined,
1237+
},
1238+
];
1239+
assert.deepEqual(yield* modelIds({ favorites: null }), everything);
1240+
assert.deepEqual(yield* modelIds({ favorites: [] }), everything);
1241+
}),
1242+
);
1243+
1244+
it.effect("describes model options by id and value only", () =>
1245+
Effect.gen(function* () {
1246+
const service = yield* OrchestratorMcpService.OrchestratorMcpService;
1247+
const capabilities = yield* service.capabilities(scope);
1248+
const model = capabilities.providers[0]?.models.find((entry) => entry.id === "gpt-5.5");
1249+
assert.deepEqual(model, {
1250+
id: "gpt-5.5",
1251+
label: "GPT-5.5",
1252+
options: [
1253+
{
1254+
id: "effort",
1255+
type: "select",
1256+
values: ["low", "high"],
1257+
default: "high",
1258+
currentValue: "high",
1259+
},
1260+
{ id: "fastMode", type: "boolean", currentValue: false },
1261+
],
1262+
});
1263+
// Labels identical to the id are left out.
1264+
assert.notProperty(capabilities.providers[0]?.models[0], "label");
1265+
}).pipe(Effect.provide(layerFor(null))),
1266+
);
1267+
});
1268+
10871269
it.effect(
10881270
"delegates to an Antigravity instance whose adapter resolves through the registry",
10891271
() =>

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

Lines changed: 80 additions & 38 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,
@@ -49,6 +51,7 @@ import {
4951
type OrchestratorMcpThreadTimelineItem,
5052
type OrchestratorMcpThreadWaitInput,
5153
type OrchestratorMcpThreadWaitResult,
54+
type ProviderInstanceId,
5255
type ProviderInteractionMode,
5356
type ProviderOptionDescriptor,
5457
type ProviderOptionSelection,
@@ -130,6 +133,7 @@ type TerminalTaskStatus = Extract<
130133
export interface OrchestratorMcpServiceShape {
131134
readonly capabilities: (
132135
scope: McpInvocationScope,
136+
input?: OrchestratorMcpCapabilitiesInput,
133137
) => Effect.Effect<OrchestratorMcpCapabilitiesResult, OrchestratorMcpFailure>;
134138
readonly delegateTask: (
135139
scope: McpInvocationScope,
@@ -266,6 +270,25 @@ function scheduledTaskSummary(task: ScheduledTask, mayRun: boolean): Orchestrato
266270
};
267271
}
268272

273+
/** Drops the composer's labels and descriptions; agents only need ids and values. */
274+
function slimOptionDescriptor(descriptor: ProviderOptionDescriptor): OrchestratorMcpModelOption {
275+
if (descriptor.type === "boolean") {
276+
return {
277+
id: descriptor.id,
278+
type: "boolean",
279+
...(descriptor.currentValue === undefined ? {} : { currentValue: descriptor.currentValue }),
280+
};
281+
}
282+
const defaultValue = descriptor.options.find((choice) => choice.isDefault)?.id;
283+
return {
284+
id: descriptor.id,
285+
type: "select",
286+
values: descriptor.options.map((choice) => choice.id),
287+
...(defaultValue === undefined ? {} : { default: defaultValue }),
288+
...(descriptor.currentValue === undefined ? {} : { currentValue: descriptor.currentValue }),
289+
};
290+
}
291+
269292
function providerConstraints(
270293
provider: ServerProvider | undefined,
271294
supportsOrchestrationV2: boolean,
@@ -1915,54 +1938,73 @@ const make = Effect.gen(function* () {
19151938
return { status, secretRef: secretRef.value };
19161939
}).pipe(Effect.withSpan("OrchestratorMcpService.requestSecret")),
19171940

1918-
capabilities: (scope) =>
1941+
capabilities: (scope, input = {}) =>
19191942
Effect.gen(function* () {
19201943
const { parent, limits } = yield* loadCaller(scope);
19211944
const providers = yield* loadProviders;
19221945
const orchestrationCapableInstanceIds = yield* loadOrchestrationCapableInstanceIds();
1923-
// Models the user hid from pickers stay out of the catalog agents choose from.
1924-
const modelPreferences = yield* serverSettings.getSettings.pipe(
1925-
Effect.map((settings) => settings.providerModelPreferences ?? {}),
1946+
const settings = yield* serverSettings.getSettings.pipe(
19261947
Effect.mapError(() => failure("orchestration_error", "Unable to read server settings.")),
19271948
);
1949+
// Models the user hid from pickers stay out of the catalog agents choose from.
1950+
const modelPreferences = settings.providerModelPreferences ?? {};
1951+
// Without any favorites there is nothing to narrow to, so list everything.
1952+
const favorites =
1953+
input.models === "all" || settings.favorites === null || settings.favorites.length === 0
1954+
? null
1955+
: settings.favorites;
1956+
const inherited = parent?.thread.modelSelection;
1957+
const isListed = (instanceId: ProviderInstanceId, slug: string) =>
1958+
favorites === null ||
1959+
(inherited?.instanceId === instanceId && inherited.model === slug) ||
1960+
favorites.some((favorite) => favorite.provider === instanceId && favorite.model === slug);
19281961
return {
19291962
parentThreadId: parent?.thread.id ?? null,
1930-
inheritedProviderInstanceId: parent?.thread.modelSelection.instanceId ?? null,
1931-
inheritedModel: parent?.thread.modelSelection.model ?? null,
1963+
inheritedProviderInstanceId: inherited?.instanceId ?? null,
1964+
inheritedModel: inherited?.model ?? null,
19321965
runtimeMode: limits.runtimeMode,
19331966
interactionMode: limits.interactionMode,
1934-
providers: providers.map((provider) => {
1935-
const constraints = providerConstraints(
1936-
provider,
1937-
orchestrationCapableInstanceIds.has(provider.instanceId),
1938-
);
1939-
return {
1940-
providerInstanceId: provider.instanceId,
1941-
driverKind: provider.driver,
1942-
displayName: provider?.displayName ?? null,
1943-
models:
1944-
provider?.models
1945-
.filter(
1946-
(model) =>
1947-
model.isCustom ||
1948-
!modelPreferences[provider.instanceId]?.hiddenModels.includes(model.slug),
1949-
)
1950-
.map((model) => ({
1951-
id: model.slug,
1952-
label: model.name ?? null,
1953-
...(model.capabilities?.optionDescriptors === undefined
1954-
? {}
1955-
: { options: model.capabilities.optionDescriptors }),
1956-
})) ?? [],
1957-
...(provider.supportedRuntimeModes === undefined ||
1958-
provider.supportedRuntimeModes.length === 0
1959-
? {}
1960-
: { runtimeModes: [...provider.supportedRuntimeModes] }),
1961-
canRunChildTask: constraints.length === 0,
1962-
canRunCrossProviderChildTask: constraints.length === 0,
1963-
constraints: [...constraints],
1964-
};
1965-
}),
1967+
providers: providers
1968+
.filter(
1969+
(provider) =>
1970+
input.providerInstanceId === undefined ||
1971+
provider.instanceId === input.providerInstanceId,
1972+
)
1973+
.map((provider) => {
1974+
const constraints = providerConstraints(
1975+
provider,
1976+
orchestrationCapableInstanceIds.has(provider.instanceId),
1977+
);
1978+
const visibleModels = provider.models.filter(
1979+
(model) =>
1980+
model.isCustom ||
1981+
!modelPreferences[provider.instanceId]?.hiddenModels.includes(model.slug),
1982+
);
1983+
const listedModels = visibleModels.filter((model) =>
1984+
isListed(provider.instanceId, model.slug),
1985+
);
1986+
const omittedModels = visibleModels.length - listedModels.length;
1987+
return {
1988+
providerInstanceId: provider.instanceId,
1989+
driverKind: provider.driver,
1990+
displayName: provider.displayName ?? null,
1991+
models: listedModels.map((model) => ({
1992+
id: model.slug,
1993+
...(model.name === model.slug ? {} : { label: model.name }),
1994+
...(model.capabilities?.optionDescriptors === undefined
1995+
? {}
1996+
: { options: model.capabilities.optionDescriptors.map(slimOptionDescriptor) }),
1997+
})),
1998+
...(omittedModels === 0 ? {} : { omittedModels }),
1999+
...(provider.supportedRuntimeModes === undefined ||
2000+
provider.supportedRuntimeModes.length === 0
2001+
? {}
2002+
: { runtimeModes: [...provider.supportedRuntimeModes] }),
2003+
canRunChildTask: constraints.length === 0,
2004+
canRunCrossProviderChildTask: constraints.length === 0,
2005+
constraints: [...constraints],
2006+
};
2007+
}),
19662008
features: {
19672009
appOwnedSubagents: true,
19682010
asyncPolling: true,

‎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 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. By default only the user's favorited models and your own are listed; omittedModels counts the rest. Pass models='all', optionally with providerInstanceId, when you need an unlisted model. 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)