diff --git a/apps/server/src/mcp/McpToolAccess.ts b/apps/server/src/mcp/McpToolAccess.ts index 20a9274798d0f..3115d776ba4d8 100644 --- a/apps/server/src/mcp/McpToolAccess.ts +++ b/apps/server/src/mcp/McpToolAccess.ts @@ -23,7 +23,12 @@ import { type DispatchModeRefusal, } from "../orchestration-v2/DispatchModeLimit.ts"; import * as PeerForwarding from "../peer/PeerForwarding.ts"; -import { assertNotLinked, assertSameLink, callerLinkOrigin } from "./linkOrigin.ts"; +import { + assertFullAccessNamingLink, + assertNotLinked, + assertSameLink, + callerLinkOrigin, +} from "./linkOrigin.ts"; import * as McpInvocationContext from "./McpInvocationContext.ts"; import { resolveInteractionMode, resolveRuntimeMode } from "./delegatedTaskModes.ts"; import { @@ -320,6 +325,7 @@ export const afterForwarding = ( const fullAccessRequired = "Changing projects or environment settings needs a live full-access/default calling thread or a full-access client."; +const changesEnvironment = "change projects or environment settings"; /** Recheck after waits before writing; caller modes may have changed. */ export const writesEnvironment = ( @@ -339,9 +345,11 @@ export const writesEnvironment = ( Effect.tap((caller) => options?.linkedCallers === "allowed" ? Effect.void - : assertNotLinked(caller, "change projects or environment settings"), + : assertNotLinked(caller, changesEnvironment), + ), + Effect.tap((caller) => + assertFullAccessNamingLink(caller, fullAccessRequired, changesEnvironment), ), - Effect.tap((caller) => assertFullAccess(caller, fullAccessRequired)), ); return declare( (params: P) => check.pipe(Effect.flatMap(() => handle(params, check))), diff --git a/apps/server/src/mcp/linkOrigin.ts b/apps/server/src/mcp/linkOrigin.ts index 742ac2cea3624..25763b759a36b 100644 --- a/apps/server/src/mcp/linkOrigin.ts +++ b/apps/server/src/mcp/linkOrigin.ts @@ -6,7 +6,7 @@ import { } from "@t3tools/contracts"; import * as Effect from "effect/Effect"; -import type { Caller } from "./threadAccess.ts"; +import { assertFullAccess, type Caller } from "./threadAccess.ts"; /** * Below full access, work a link starts here (all of it carries that session in `linkOrigin`) @@ -34,10 +34,13 @@ export const fencingLinkOrigin = (caller: Pick) => { return origin !== undefined && linkOriginIsFenced(origin) ? origin : undefined; }; +const outsideLinkMessage = (origin: OrchestrationV2LinkOrigin, message: string) => + `This work was started from ${origin.label} through a linked environment, so ${message} A link paired with full access is not limited this way.`; + const outsideLink = (origin: OrchestrationV2LinkOrigin, message: string) => new OrchestratorMcpFailure({ code: "capability_denied", - message: `This work was started from ${origin.label} through a linked environment, so ${message} A link paired with full access is not limited this way.`, + message: outsideLinkMessage(origin, message), }); /** A thread a fenced caller may change: one its own link started. */ @@ -58,3 +61,17 @@ export const assertNotLinked = (caller: Pick, what: ? Effect.void : Effect.fail(outsideLink(origin, `it cannot ${what}.`)); }; + +/** A fenced caller is held below full access by its link, not its thread, so the refusal names the link. */ +export const assertFullAccessNamingLink = (caller: Caller, message: string, what: string) => { + const origin = fencingLinkOrigin(caller); + return assertFullAccess( + caller, + origin === undefined + ? message + : outsideLinkMessage( + origin, + `it has that link's ${origin.access === undefined ? "" : `${origin.access} `}access, which is below the full access needed to ${what}.`, + ), + ); +}; diff --git a/apps/server/src/mcp/toolkits/project/handlers.test.ts b/apps/server/src/mcp/toolkits/project/handlers.test.ts index 8dff0fc012643..fe153de931ff6 100644 --- a/apps/server/src/mcp/toolkits/project/handlers.test.ts +++ b/apps/server/src/mcp/toolkits/project/handlers.test.ts @@ -922,6 +922,36 @@ it.effect("a client launches with the fallback for an exhausted default", () => }), ); +it.effect("creating a project through MCP refuses a model default instead of dropping it", () => + Effect.gen(function* () { + const harness = clientLaunchHarness({ runtimeModeCeiling: "full-access", launched: [] }); + const dependencies = Layer.merge( + harness.dependencies, + Layer.mock(Project.ProjectService)({ + create: () => Effect.die("the project was created without its model default"), + }), + ); + const toolkit = yield* ProjectToolkit.pipe( + Effect.provide( + McpToolAccess.HandlersLayer.layer(ProjectHandlers.layer).pipe(Layer.provide(dependencies)), + ), + ); + + const refused = yield* toolkit + .handle("t3_project_create", { + title: "client-target", + workspaceRoot: "/projects/client-target", + defaultModelSelection: harness.modelSelection, + }) + .pipe(Stream.unwrap, Stream.runCollect, Effect.provide(dependencies)); + + expect(refused.at(-1)?.result).toMatchObject({ + code: "invalid_request", + message: expect.stringContaining("t3_project_update"), + }); + }), +); + it.effect("an agent's clone is not cut off while git is still transferring", () => Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; diff --git a/apps/server/src/mcp/toolkits/project/handlers.ts b/apps/server/src/mcp/toolkits/project/handlers.ts index 845a570b4e1c7..3a16a09545b7d 100644 --- a/apps/server/src/mcp/toolkits/project/handlers.ts +++ b/apps/server/src/mcp/toolkits/project/handlers.ts @@ -513,6 +513,12 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, { ...(created.commitError === undefined ? {} : { commitError: created.commitError }), }; } + if (input.defaultModelSelection !== undefined && input.defaultModelSelection !== null) + return yield* new OrchestratorMcpFailure({ + code: "invalid_request", + message: + "Creating a project does not set its default model; set defaultModelSelection afterwards with t3_project_update.", + }); const commandId = yield* newCommandId(); return yield* projects .create({ ...input, workspaceRoot, commandId, projectId: ProjectId.make(commandId) }) diff --git a/apps/server/src/peer/PeerForwarding.test.ts b/apps/server/src/peer/PeerForwarding.test.ts index 5f53bfdf5b9dd..a70c0d25792b8 100644 --- a/apps/server/src/peer/PeerForwarding.test.ts +++ b/apps/server/src/peer/PeerForwarding.test.ts @@ -593,7 +593,11 @@ it.effect("brings a repository to a linked environment, only through full access environmentId: box.environmentId, ...args, }); - expect(failureOf(refused), name).toMatchObject({ code: "capability_denied" }); + const failure = failureOf(refused); + expect(failure, name).toMatchObject({ code: "capability_denied" }); + // The agent's thread is full access; what holds it is the link's access. + expect(failure.message, name).toContain("linked environment"); + expect(failure.message, name).not.toContain("calling thread"); } expect((yield* Ref.get(seen)).clones).toHaveLength(1); expect((yield* Ref.get(seen)).projects).toHaveLength(1);