GeezerVison is showing github.com — MCP profile carry: Claude-only docs, no empty name, fail closed, requ… · scuttletoby/t3code@24186d4
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/fork/claudeMcpProfile.test.ts +44-2Lines changed: 44 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -163,6 +163,7 @@ describe("makeClaudeMcpProfiles", () => { | 163 | 163 | reads: ReadonlyArray<Record<string, unknown> | "fails">, | 164 | 164 | file: string | undefined | "unreadable" = undefined, | 165 | 165 | policy?: unknown, | | 166 | + self: LineageThread = thread("t"), | 166 | 167 | ) => | 167 | 168 | Effect.gen(function* () { | 168 | 169 | const { settingsPath } = yield* ServerConfig.ServerConfig; | @@ -184,10 +185,14 @@ describe("makeClaudeMcpProfiles", () => { | 184 | 185 | const outcomes: Array<string> = []; | 185 | 186 | for (const _ of reads) { | 186 | 187 | outcomes.push( | 187 | | - yield* plan(thread("t"), {}).pipe( | | 188 | + yield* plan(self, {}).pipe( | 188 | 189 | Effect.match({ | 189 | 190 | onFailure: (refusal) => refusal.message, | 190 | | - onSuccess: (result) => result.name, | | 191 | + // A carried profile cuts an `all` thread without renaming it. | | 192 | + onSuccess: (result) => | | 193 | + result.name === "all" && result.servers !== "all" | | 194 | + ? `all cut to ${JSON.stringify(result.servers)}` | | 195 | + : result.name, | 191 | 196 | }), | 192 | 197 | ), | 193 | 198 | ); | @@ -233,6 +238,43 @@ describe("makeClaudeMcpProfiles", () => { | 233 | 238 | }), | 234 | 239 | ); | 235 | 240 |
| | 241 | + it.effect( | | 242 | + "a failed read with a settings.json that does not decode refuses a narrower carried task (#653)", | | 243 | + () => | | 244 | + Effect.gen(function* () { | | 245 | + // The file may say mcpCarriedProfiles "refuse", so it is not read as the default apply. | | 246 | + const task: LineageThread = { | | 247 | + ...thread("task"), | | 248 | + delegatedFrom: { | | 249 | + environmentId: "environment-there" as never, | | 250 | + threadId: ThreadId.make("thread-there"), | | 251 | + title: "Parent there", | | 252 | + mcpProfile: { name: "t3-only", servers: [], t3Tools: "all" }, | | 253 | + }, | | 254 | + }; | | 255 | + const broken = "{ not json"; | | 256 | + const runs = yield* plansFor(["fails", "fails"], broken, undefined, task); | | 257 | + assert.strictEqual(runs.length, 2); | | 258 | + for (const run of runs) assert.include(run, "set to refuse such tasks"); | | 259 | + // Settings read in full, a file that decodes, or no file: the default apply cuts it. | | 260 | + const cut = ["all cut to []"]; | | 261 | + assert.deepStrictEqual(yield* plansFor([{}], broken, undefined, task), cut); | | 262 | + assert.deepStrictEqual(yield* plansFor(["fails"], "{}", undefined, task), cut); | | 263 | + assert.deepStrictEqual(yield* plansFor(["fails"], undefined, undefined, task), cut); | | 264 | + // A task carrying all cuts nothing, so it is taken; a thread of this machine's own gets | | 265 | + // the defaults, as before. | | 266 | + const all: LineageThread = { | | 267 | + ...task, | | 268 | + delegatedFrom: { | | 269 | + ...task.delegatedFrom!, | | 270 | + mcpProfile: { name: "all", servers: "all", t3Tools: "all" }, | | 271 | + }, | | 272 | + }; | | 273 | + assert.deepStrictEqual(yield* plansFor(["fails"], broken, undefined, all), ["all"]); | | 274 | + assert.deepStrictEqual(yield* plansFor(["fails"], broken), ["all"]); | | 275 | + }), | | 276 | + ); | | 277 | + | 236 | 278 | it.effect("refuses when settings.json cannot be read either, even after a read with none", () => | 237 | 279 | Effect.gen(function* () { | 238 | 280 | const [first, second] = yield* plansFor([{}, "fails"], "unreadable"); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/fork/claudeMcpProfile.ts +9-5Lines changed: 9 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,6 +12,7 @@ import type { | 12 | 12 | } from "@anthropic-ai/claude-agent-sdk"; | 13 | 13 | import { | 14 | 14 | DEFAULT_SERVER_SETTINGS, | | 15 | + MCP_CARRIED_PROFILES_REFUSE, | 15 | 16 | MCP_PROFILE_ALL, | 16 | 17 | type OrchestrationV2AppThread, | 17 | 18 | type ServerSettings, | @@ -312,10 +313,9 @@ const planKey = (plan: ClaudeMcpProfilePlan): string | undefined => | 312 | 313 | plan.servers === "all" ? undefined : ["mcp", ...plan.servers].join("\u0000"); | 313 | 314 |
| 314 | 315 | /** | 315 | | - * The settings as a load decodes them from settings.json, without reading provider secrets: the | 316 | | - * MCP profile keys hold none. `undefined` when this server has no settings file to read here. | 317 | | - * As the load: no file means the policy's defaults, a file that does not decode loads as them too | 318 | | - * (upstream's rule), and the policy's locks are laid over either. A file that cannot be read fails. | | 316 | + * settings.json as a load decodes it (no provider secrets: MCP keys hold none); `undefined` with no | | 317 | + * file to read here. No file gives the policy's defaults; a file that does not decode gives them | | 318 | + * with `mcpCarriedProfiles` `refuse`, as it may say so. Locks are laid over both; a read error fails. | 319 | 319 | */ | 320 | 320 | const settingsFileReader = Effect.gen(function* () { | 321 | 321 | const config = yield* Effect.serviceOption(ServerConfig.ServerConfig); | @@ -333,7 +333,11 @@ const settingsFileReader = Effect.gen(function* () { | 333 | 333 | const decoded = ServerSettingsService.decodeSettingsFileText(raw, managed.withDefaults); | 334 | 334 | const readable = | 335 | 335 | Exit.isSuccess(decoded) && !ServerSettingsService.settingsFileLegacyKeysUnreadable(raw); | 336 | | - return managed.applyLocks(readable ? decoded.value : managed.defaults); | | 336 | + return managed.applyLocks( | | 337 | + readable | | 338 | + ? decoded.value | | 339 | + : { ...managed.defaults, mcpCarriedProfiles: MCP_CARRIED_PROFILES_REFUSE }, | | 340 | + ); | 337 | 341 | }); | 338 | 342 | }); | 339 | 343 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/fork/mcpProfile.test.ts +43Lines changed: 43 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,6 +5,7 @@ import { describe, expect, it } from "vite-plus/test"; | 5 | 5 | import { | 6 | 6 | MCP_PROFILE_MAX_LINEAGE, | 7 | 7 | type McpProfileResolution, | | 8 | + type McpProfileSettings, | 8 | 9 | type McpProfileThread, | 9 | 10 | isEveryMcpTool, | 10 | 11 | resolveMcpProfile, | @@ -489,6 +490,48 @@ describe("MCP profile resolver: a machine set to refuse carried profiles (#640)" | 489 | 490 | } | 490 | 491 | }); | 491 | 492 |
| | 493 | + it("names no empty profile in a refusal: it says the profile cannot be read (#653)", () => { | | 494 | + // Not an object, or no name: the carried value has no name to show. | | 495 | + for (const value of [ | | 496 | + "t3-only", | | 497 | + 7, | | 498 | + null, | | 499 | + { servers: [], t3Tools: "all" }, | | 500 | + carried([], "all", " "), | | 501 | + ]) { | | 502 | + for (const file of [REFUSE, {}]) { | | 503 | + const settings = fromFile(file); | | 504 | + const task = refused(resolveMcpProfile(settings, [child("task")], value)); | | 505 | + const sub = refused(resolveMcpProfile(settings, [child("sub"), child("task")], value)); | | 506 | + for (const message of [task.message, sub.message]) { | | 507 | + expect(message).not.toMatch(/profile\s*"\s*"/); | | 508 | + expect(message).not.toContain('""'); | | 509 | + } | | 510 | + expect(sub.message).toContain("The parent thread's MCP profile cannot be applied"); | | 511 | + if (file === REFUSE) { | | 512 | + expect(task.message).toContain( | | 513 | + "delegated here with an MCP profile this version cannot read, and", | | 514 | + ); | | 515 | + } else { | | 516 | + expect(task.message).toMatch(/^The MCP profile of the thread on another machine/); | | 517 | + } | | 518 | + } | | 519 | + } | | 520 | + // A carried name is still shown. | | 521 | + const named = refused(resolveMcpProfile(fromFile(REFUSE), [child("task")], carried([]))); | | 522 | + expect(named.message).toContain('with its MCP profile "remote", and'); | | 523 | + }); | | 524 | + | | 525 | + it("makes every caller say what this machine does with a carried profile (#653)", () => { | | 526 | + const { mcpCarriedProfiles, ...rest } = fromFile(REFUSE); | | 527 | + expect(mcpCarriedProfiles).toBe("refuse"); | | 528 | + // Typecheck: settings without the key are not resolver settings, so no caller gets apply by | | 529 | + // leaving it out. | | 530 | + // @ts-expect-error mcpCarriedProfiles is required | | 531 | + const partial: McpProfileSettings = rest; | | 532 | + expect(partial).not.toHaveProperty("mcpCarriedProfiles"); | | 533 | + }); | | 534 | + | 492 | 535 | it("takes a task that carries all, which cuts nothing, as apply would", () => { | 493 | 536 | const value = carried("all", "all", "all"); | 494 | 537 | const refuse = resolved(resolveMcpProfile(fromFile(REFUSE), [child("task")], value)); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/fork/mcpProfile.ts +14-10Lines changed: 14 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,14 +17,13 @@ import { | 17 | 17 | } from "@t3tools/contracts"; | 18 | 18 |
| 19 | 19 | /** | 20 | | - * The settings the resolver reads: the server's MCP profile keys. `mcpCarriedProfiles` absent is | 21 | | - * its default, `apply`. | | 20 | + * The settings the resolver reads: the server's MCP profile keys. Each is required, so a caller | | 21 | + * must say what this machine does with a carried profile rather than get `apply` by leaving it out. | 22 | 22 | */ | 23 | 23 | export type McpProfileSettings = Pick< | 24 | 24 | ServerSettings, | 25 | | - "mcpProfiles" | "mcpProfile" | "mcpSubagentProfile" | "mcpThreadProfiles" | 26 | | -> & | 27 | | - Partial<Pick<ServerSettings, "mcpCarriedProfiles">>; | | 25 | + "mcpProfiles" | "mcpProfile" | "mcpSubagentProfile" | "mcpThreadProfiles" | "mcpCarriedProfiles" | | 26 | +>; | 28 | 27 |
| 29 | 28 | /** One thread of a lineage, as the resolver needs it. */ | 30 | 29 | export interface McpProfileThread { | @@ -351,28 +350,33 @@ const sameList = (a: "all" | ReadonlyArray<string>, b: "all" | ReadonlyArray<str | 351 | 350 |
| 352 | 351 | const FIX = `pick "${MCP_PROFILE_ALL}" for this thread, or fix the profile in Settings`; | 353 | 352 |
| | 353 | +/** ` "name"` for a message, or nothing when the name is empty (a carried value it cannot read). */ | | 354 | +const quoted = (profileName: string): string => | | 355 | + profileName.trim() === "" ? "" : ` "${profileName}"`; | | 356 | + | 354 | 357 | function cannotApply( | 355 | 358 | problem: McpProfileProblem, | 356 | 359 | thread: McpProfileThread, | 357 | 360 | profileName: string, | 358 | 361 | issue: string, | 359 | 362 | ): McpProfileCannotApply { | | 363 | + const name = quoted(profileName); | 360 | 364 | const message = | 361 | 365 | problem === "missing" | 362 | | - ? `MCP profile "${profileName}" is not set up, so this thread cannot start: ${FIX}.` | | 366 | + ? `MCP profile${name} is not set up, so this thread cannot start: ${FIX}.` | 363 | 367 | : problem === "broken" | 364 | | - ? `MCP profile "${profileName}" cannot be read by this version (${issue}), so this thread cannot start: ${ | | 368 | + ? `MCP profile${name} cannot be read by this version (${issue}), so this thread cannot start: ${ | 365 | 369 | // Only an entry under its name breaks a built-in; picking it again would not help. | 366 | 370 | isBuiltInMcpProfileName(profileName) | 367 | 371 | ? `remove or rename that entry in the settings file` | 368 | 372 | : FIX | 369 | 373 | }.` | 370 | 374 | : problem === "parent" | 371 | | - ? `The parent thread's MCP profile "${profileName}" cannot be applied, so this thread cannot start: ${FIX}.` | | 375 | + ? `The parent thread's MCP profile${name} cannot be applied, so this thread cannot start: ${FIX}.` | 372 | 376 | : problem === "carried" | 373 | | - ? `The MCP profile "${profileName}" of the thread on another machine that delegated this one cannot be read by this version (${issue}), so this thread cannot start: update T3 here, or pick a profile for this thread in Settings.` | | 377 | + ? `The MCP profile${name} of the thread on another machine that delegated this one cannot be read by this version (${issue}), so this thread cannot start: update T3 here, or pick a profile for this thread in Settings.` | 374 | 378 | : problem === "carried-refused" | 375 | | - ? `This thread is a task another machine delegated here with its MCP profile "${profileName}", and this machine is set to refuse such tasks (mcpCarriedProfiles is "${MCP_CARRIED_PROFILES_REFUSE}"), so it cannot start: delegate the task on that machine, set mcpCarriedProfiles to "apply" here, or pick a profile for this thread in Settings.` | | 379 | + ? `This thread is a task another machine delegated here with ${name === "" ? "an MCP profile this version cannot read" : `its MCP profile${name}`}, and this machine is set to refuse such tasks (mcpCarriedProfiles is "${MCP_CARRIED_PROFILES_REFUSE}"), so it cannot start: delegate the task on that machine, set mcpCarriedProfiles to "apply" here, or pick a profile for this thread in Settings.` | 376 | 380 | : `This thread's parent threads ${issue}, so its MCP profile cannot be worked out: ${FIX}.`; | 377 | 381 | return { _tag: "CannotApply", problem, profileName, threadId: thread.threadId, message }; | 378 | 382 | } | |
Collapse file Copy file name to clipboardExpand all lines: docs/fork/README.md +9-3Lines changed: 9 additions & 3 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -473,13 +473,19 @@ Whether this machine takes tasks that another machine delegated with a profile n | 473 | 473 | ([#640](https://github.com/scuttletoby/t3code/issues/640)). `apply` (the default) cuts such a task | 474 | 474 | down to the carried profile, as `server.mcpProfiles` says. `refuse` takes no part in carrying: the | 475 | 475 | features route answers `mcpProfileCarry: false`, so a narrower-profile thread on another machine is | 476 | | -refused before it sends, and a task that arrives with one anyway (sent before the setting changed) | 477 | | -does not start its turn, nor do its sub-agents, and says why. Neither value gives a task more than | | 476 | +refused before it sends. A task that arrives with one anyway (sent before the setting changed), or | | 477 | +with a profile this machine cannot read, does not start its turn on Claude, nor do its sub-agents, | | 478 | +and says why. On Codex or any other provider such a task still runs, with every tool: only Claude | | 479 | +threads apply profiles (see `server.mcpProfiles`). Neither value gives a task more than | 478 | 480 | it would get: there is no "ignore the carried profile" value, as a thread could then get more tools | 479 | 481 | by delegating to this machine. A task that carries `all`, or nothing (from an older T3), runs as | 480 | 482 | before, and the owner's pick for a task here (`mcpThreadProfiles`) still stands. It is read again | 481 | 483 | for each turn and each ask, so a change counts from the next one. A value it does not know reads as | 482 | | -`apply`. Only the person can change it; agents cannot. | | 484 | +`apply`. When a Claude turn cannot read the settings in full and falls back to `settings.json` | | 485 | +alone, and that file does not decode either, it reads as `refuse`: the file may say `refuse`, so a | | 486 | +narrower carried task is refused rather than cut. A file that did not decode when the server loaded | | 487 | +it gives every setting its default, this one `apply` (a narrower carried task is still cut, never | | 488 | +given more). Only the person can change it; agents cannot. | 483 | 489 |
| 484 | 490 | ```json | 485 | 491 | { "mcpCarriedProfiles": "refuse" } | |
|