diff --git a/apps/server/src/mcp/OrchestratorMcpService.ts b/apps/server/src/mcp/OrchestratorMcpService.ts index c52716f2ba2d4..b47dc90177d9e 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.ts @@ -127,6 +127,7 @@ import { taskPrompt, } from "./delegatedTaskModes.ts"; import { isLiveCallerShell, threadNotFound } from "./threadAccess.ts"; +import { invalidOptionSelections } from "./modelOptionValidation.ts"; import * as SecretRequests from "../secrets/SecretRequests.ts"; import * as PeerForwarding from "../peer/PeerForwarding.ts"; import * as RemoteDelegation from "../peer/RemoteDelegation.ts"; @@ -410,41 +411,6 @@ function knownOptions( return options.filter((option) => descriptors.some((descriptor) => descriptor.id === option.id)); } -/** Skip checks without descriptors; reject duplicate IDs because consumers disagree on precedence. */ -function invalidOptionSelections( - selections: ReadonlyArray, - descriptors: ReadonlyArray | undefined, -): ReadonlyArray { - const problems: Array = []; - const seen = new Set(); - for (const selection of selections) { - if (seen.has(selection.id)) { - problems.push(`Option ${selection.id} was specified more than once.`); - continue; - } - seen.add(selection.id); - if (descriptors === undefined) continue; - const descriptor = descriptors.find((candidate) => candidate.id === selection.id); - if (descriptor === undefined) { - const known = descriptors.map((candidate) => candidate.id).join(", "); - problems.push(`Unknown option ${selection.id}; supported options: ${known || "none"}.`); - continue; - } - if (descriptor.type === "boolean" && typeof selection.value !== "boolean") { - problems.push(`Option ${selection.id} expects a boolean value.`); - continue; - } - if ( - descriptor.type === "select" && - !descriptor.options.some((choice) => choice.id === selection.value) - ) { - const choices = descriptor.options.map((choice) => choice.id).join(", "); - problems.push(`Option ${selection.id} must be one of: ${choices}.`); - } - } - return problems; -} - function taskStatusForRun( run: Pick | undefined, ): OrchestratorMcpDelegateTaskResult["status"] { diff --git a/apps/server/src/mcp/modelOptionValidation.ts b/apps/server/src/mcp/modelOptionValidation.ts new file mode 100644 index 0000000000000..ec1c7ec237dce --- /dev/null +++ b/apps/server/src/mcp/modelOptionValidation.ts @@ -0,0 +1,36 @@ +import type { ProviderOptionDescriptor, ProviderOptionSelection } from "@t3tools/contracts"; + +/** Skip checks without descriptors; reject duplicate IDs because consumers disagree on precedence. */ +export function invalidOptionSelections( + selections: ReadonlyArray, + descriptors: ReadonlyArray | undefined, +): ReadonlyArray { + const problems: Array = []; + const seen = new Set(); + for (const selection of selections) { + if (seen.has(selection.id)) { + problems.push(`Option ${selection.id} was specified more than once.`); + continue; + } + seen.add(selection.id); + if (descriptors === undefined) continue; + const descriptor = descriptors.find((candidate) => candidate.id === selection.id); + if (descriptor === undefined) { + const known = descriptors.map((candidate) => candidate.id).join(", "); + problems.push(`Unknown option ${selection.id}; supported options: ${known || "none"}.`); + continue; + } + if (descriptor.type === "boolean" && typeof selection.value !== "boolean") { + problems.push(`Option ${selection.id} expects a boolean value.`); + continue; + } + if ( + descriptor.type === "select" && + !descriptor.options.some((choice) => choice.id === selection.value) + ) { + const choices = descriptor.options.map((choice) => choice.id).join(", "); + problems.push(`Option ${selection.id} must be one of: ${choices}.`); + } + } + return problems; +} diff --git a/apps/server/src/mcp/toolkits/project/handlers.test.ts b/apps/server/src/mcp/toolkits/project/handlers.test.ts index b2ba460d0c8b7..0798b432ebe8b 100644 --- a/apps/server/src/mcp/toolkits/project/handlers.test.ts +++ b/apps/server/src/mcp/toolkits/project/handlers.test.ts @@ -719,6 +719,91 @@ it.effect("a retried worktree launch replays after its base ref is gone", () => }), ); +it.effect("strict launches reject unsupported provider options before creating a thread", () => + Effect.gen(function* () { + const launched: ThreadLaunch.ThreadLaunchInput[] = []; + const instanceId = ProviderInstanceId.make("codex"); + const model = "gpt-5.6-luna"; + const providers: ServerProvider[] = [ + { + instanceId, + driver: ProviderDriverKind.make("codex"), + enabled: true, + installed: true, + status: "ready", + version: null, + auth: { status: "authenticated" }, + checkedAt: "2026-01-01T00:00:00Z", + models: [ + { + slug: model, + name: "Luna", + isCustom: false, + capabilities: { + optionDescriptors: [ + { + id: "reasoningEffort", + label: "Reasoning", + type: "select", + options: [{ id: "low", label: "Low" }], + }, + ], + }, + }, + ], + slashCommands: [], + skills: [], + }, + ]; + const { projectId, dependencies } = clientLaunchHarness({ + runtimeModeCeiling: "full-access", + launched, + providers, + }); + const toolkit = yield* ProjectToolkit.pipe( + Effect.provide( + McpToolAccess.HandlersLayer.layer(ProjectHandlers.layer).pipe(Layer.provide(dependencies)), + ), + ); + const launch = ( + id: string, + value: string, + strictModelOptions?: boolean, + clientRequestId?: string, + ) => + toolkit + .handle("t3_thread_launch", { + projectId, + title: "Review", + modelSelection: { instanceId, model, options: [{ id, value }] }, + ...(strictModelOptions === undefined ? {} : { strictModelOptions }), + ...(clientRequestId === undefined ? {} : { clientRequestId }), + }) + .pipe(Stream.unwrap, Stream.runCollect, Effect.provide(dependencies)); + + const wrongKey = yield* launch("effort", "low", true); + expect(wrongKey.at(-1)?.result).toMatchObject({ + code: "invalid_request", + message: expect.stringContaining("Unknown option effort"), + }); + const wrongValue = yield* launch("reasoningEffort", "high", true); + expect(wrongValue.at(-1)?.result).toMatchObject({ code: "invalid_request" }); + expect(launched).toHaveLength(0); + + yield* launch("effort", "low"); + expect(launched[0]?.modelSelection.options).toEqual([{ id: "effort", value: "low" }]); + + const accepted = yield* launch("reasoningEffort", "low", true, "strict-review"); + expect(accepted.at(-1)?.result).toMatchObject({ projectId }); + expect(launched[1]?.modelSelection.options).toEqual([{ id: "reasoningEffort", value: "low" }]); + + providers.length = 0; + const replayed = yield* launch("reasoningEffort", "low", true, "strict-review"); + expect(replayed.at(-1)?.result).toMatchObject({ projectId }); + expect(launched[2]?.threadId).toBe(launched[1]?.threadId); + }), +); + it.effect("a client launches with the fallback for an exhausted default", () => Effect.gen(function* () { const launched: ThreadLaunch.ThreadLaunchInput[] = []; diff --git a/apps/server/src/mcp/toolkits/project/handlers.ts b/apps/server/src/mcp/toolkits/project/handlers.ts index 2ad7161cb630b..7cc7d6ef270b1 100644 --- a/apps/server/src/mcp/toolkits/project/handlers.ts +++ b/apps/server/src/mcp/toolkits/project/handlers.ts @@ -30,6 +30,7 @@ import { resolveRuntimeMode } from "../../delegatedTaskModes.ts"; import * as McpInvocationContext from "../../McpInvocationContext.ts"; import * as McpToolAccess from "../../McpToolAccess.ts"; import * as OrchestrationMcp from "../../OrchestratorMcpService.ts"; +import { invalidOptionSelections } from "../../modelOptionValidation.ts"; import { newCommandId, readCaller, resolveProjectId, unavailable } from "../../threadAccess.ts"; import { ProjectToolkit } from "./tools.ts"; @@ -247,11 +248,27 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, { : runtimeMode; if (!replaying) { const providers = yield* (yield* ProviderRegistry.ProviderRegistry).getProviders; + const provider = providers.find( + (candidate) => candidate.instanceId === modelSelection.instanceId, + ); + const options = input.modelSelection?.options; + if (input.strictModelOptions && options && options.length > 0) { + const model = provider?.models.find( + (candidate) => candidate.slug === modelSelection.model, + ); + const invalid = invalidOptionSelections( + options, + model?.capabilities?.optionDescriptors ?? [], + ); + if (invalid.length > 0) + return yield* new OrchestratorMcpFailure({ + code: "invalid_request", + message: `Model ${modelSelection.model} rejected options: ${invalid.join(" ")} No thread was created.`, + }); + } startedRuntimeMode = yield* resolveRuntimeMode(startedRuntimeMode, input.runtimeMode, { modelSelection, - supportedRuntimeModes: providers.find( - (provider) => provider.instanceId === modelSelection.instanceId, - )?.supportedRuntimeModes, + supportedRuntimeModes: provider?.supportedRuntimeModes, }); } const result = yield* ThreadMessageIntake.launchThread({ diff --git a/apps/server/src/mcp/toolkits/project/tools.ts b/apps/server/src/mcp/toolkits/project/tools.ts index 56799959f6cd8..10058de83e91b 100644 --- a/apps/server/src/mcp/toolkits/project/tools.ts +++ b/apps/server/src/mcp/toolkits/project/tools.ts @@ -136,6 +136,12 @@ const ThreadLaunchTool = Tool.make("t3_thread_launch", { ), title: TrimmedNonEmptyString, modelSelection: Schema.optional(ModelSelection), + strictModelOptions: Schema.optional( + Schema.Boolean.annotate({ + description: + "Reject explicit model options that are not advertised for the selected model. Applies only to new launches.", + }), + ), runtimeMode: Schema.optional(RuntimeMode), interactionMode: Schema.optional(ProviderInteractionMode), workspaceStrategy: Schema.optional( diff --git a/docs/orchestration-v2/orchestrator-mcp-server.md b/docs/orchestration-v2/orchestrator-mcp-server.md index 74700c2d006a2..6bd30983040b6 100644 --- a/docs/orchestration-v2/orchestrator-mcp-server.md +++ b/docs/orchestration-v2/orchestrator-mcp-server.md @@ -383,8 +383,12 @@ its own under the environment's Scratch project. For stacked PRs, use the parent `startFromOrigin: false`. The new thread may not run with broader runtime or interaction modes than the caller. As for `delegate_task`, a runtime mode the provider does not offer is refused, and an inherited or default one steps down -to the broadest mode it offers. Launch has no retry key, so inspect existing threads after a failed or lost response before -launching again. `create_threads` remains the batch option for a shared checkout. +to the broadest mode it offers. With `strictModelOptions: true`, explicit model +options must match the selected model's advertised option IDs and values. +An invalid option is rejected before a thread is created. Retry a failed or lost +response with the same `clientRequestId` and caller. An accepted launch replays +without revalidating its options against the current catalog. +`create_threads` remains the batch option for a shared checkout. ### `t3_thread_list`