GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(server): honor withheld agent browser access in the v2 runtime · pingdotgg/t3code@19587e3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src
    • mcp
      • McpProviderSession.ts
      • McpSessionRegistry.testkit.ts
      • McpSessionRegistry.ts
    • orchestration-v2
      • Adapters
        • AcpAdapterV2.test.ts
        • ClaudeAdapterV2.test.ts
        • CodexAdapterV2.test.ts
        • CodexAdapterV2.ts
        • CursorAdapterV2.test.ts
      • ProviderSessionManager.test.ts
      • ProviderSessionManager.ts
    • provider
      • CodexDeveloperInstructions.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/mcp/McpProviderSession.ts
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ export interface McpProviderSessionConfig {
77
readonly providerInstanceId: ProviderInstanceId;
88
readonly endpoint: string;
99
readonly authorizationHeader: string;
10+
/**
11+
* Whether this credential includes the "preview" capability. Adapters read
12+
* it to keep developer instructions truthful: when the user withholds agent
13+
* browser access, the prompt must not advertise `preview_*` tools that every
14+
* call would reject.
15+
*/
16+
readonly browserToolsAvailable: boolean;
1017
}
1118

1219
const sessionsByThread = new Map<ThreadId, McpProviderSessionConfig>();
Collapse file

‎apps/server/src/mcp/McpSessionRegistry.testkit.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/mcp/McpSessionRegistry.testkit.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const layer = Layer.succeed(
1616
providerInstanceId,
1717
endpoint: "http://127.0.0.1/mcp",
1818
authorizationHeader: `Bearer mcp-test:${threadId}`,
19+
browserToolsAvailable: true,
1920
},
2021
}),
2122
resolve: () => Effect.succeed(undefined),
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/mcp/McpSessionRegistry.ts
+15-1Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ import * as McpProviderSession from "./McpProviderSession.ts";
1414
export interface McpCredentialRequest {
1515
readonly threadId: ThreadId;
1616
readonly providerInstanceId: ProviderInstanceId;
17+
/**
18+
* When false, the credential is minted without the "preview" capability so
19+
* the user's choice to withhold agent browser access holds everywhere the
20+
* token is honored (#7083). Defaults to full access.
21+
*/
22+
readonly browserToolsAvailable?: boolean;
1723
}
1824

1925
export interface McpIssuedCredential {
@@ -123,12 +129,19 @@ const makeWithOptions = Effect.fn("McpSessionRegistry.make")(function* (
123129
const providerSessionId = yield* crypto.randomUUIDv4.pipe(Effect.orDie);
124130
const rawToken = yield* crypto.randomBytes(32).pipe(Effect.map(tokenFromBytes), Effect.orDie);
125131
const tokenHash = yield* hashToken(rawToken);
132+
const browserToolsAvailable = request.browserToolsAvailable ?? true;
126133
const scope: McpInvocationContext.McpInvocationScope = {
127134
environmentId,
128135
threadId: ThreadId.make(request.threadId),
129136
providerSessionId,
130137
providerInstanceId: ProviderInstanceId.make(request.providerInstanceId),
131-
capabilities: new Set(McpInvocationContext.ALL_MCP_CAPABILITIES),
138+
capabilities: new Set(
139+
browserToolsAvailable
140+
? McpInvocationContext.ALL_MCP_CAPABILITIES
141+
: McpInvocationContext.ALL_MCP_CAPABILITIES.filter(
142+
(capability) => capability !== "preview",
143+
),
144+
),
132145
issuedAt,
133146
};
134147
yield* SynchronizedRef.update(state, ({ records }) => {
@@ -144,6 +157,7 @@ const makeWithOptions = Effect.fn("McpSessionRegistry.make")(function* (
144157
providerInstanceId: scope.providerInstanceId,
145158
endpoint,
146159
authorizationHeader: `Bearer ${rawToken}`,
160+
browserToolsAvailable,
147161
},
148162
};
149163
},
Collapse file

‎apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,7 @@ describe("AcpAdapterV2", () => {
11491149
providerInstanceId: instanceId,
11501150
endpoint: "http://127.0.0.1:43123/mcp",
11511151
authorizationHeader: "Bearer target-thread-token",
1152+
browserToolsAvailable: true,
11521153
});
11531154
yield* Effect.addFinalizer(() =>
11541155
Effect.sync(() => McpProviderSession.clearMcpProviderSession(targetThreadId)),
Collapse file

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ describe("ClaudeAdapterV2 MCP query overrides", () => {
345345
providerInstanceId: ProviderInstanceId.make("claudeAgent"),
346346
endpoint: "http://127.0.0.1:43123/mcp",
347347
authorizationHeader: "Bearer secret-claude-token",
348+
browserToolsAvailable: true,
348349
});
349350
try {
350351
run();
@@ -480,6 +481,7 @@ describe("ClaudeAdapterV2 MCP query overrides", () => {
480481
providerInstanceId: ProviderInstanceId.make("claudeAgent"),
481482
endpoint: "http://127.0.0.1:43123/mcp",
482483
authorizationHeader: "Bearer rotated-claude-token",
484+
browserToolsAvailable: true,
483485
});
484486

485487
const rotatedKey = claudeEffectiveQueryPolicyKey(
@@ -510,6 +512,7 @@ describe("ClaudeAdapterV2 native protocol logging", () => {
510512
providerInstanceId: ProviderInstanceId.make("claudeAgent"),
511513
endpoint: "http://127.0.0.1:43123/mcp",
512514
authorizationHeader: "Bearer secret-claude-token",
515+
browserToolsAvailable: true,
513516
});
514517

515518
try {
Collapse file

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ describe("CodexAdapterV2 process spawning", () => {
469469
providerInstanceId: ProviderInstanceId.make("codex"),
470470
endpoint: "http://127.0.0.1:43123/mcp",
471471
authorizationHeader: "Bearer secret-codex-token",
472+
browserToolsAvailable: true,
472473
});
473474

474475
try {
Collapse file

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+8-6Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ import { resolveAttachmentPath } from "../../attachmentStore.ts";
5151
import { getCodexServiceTierOptionValue } from "../../codexModelOptions.ts";
5252
import { ServerConfig } from "../../config.ts";
5353
import {
54-
CODEX_DEFAULT_MODE_DEVELOPER_INSTRUCTIONS,
55-
CODEX_PLAN_MODE_DEVELOPER_INSTRUCTIONS,
54+
codexDefaultModeDeveloperInstructions,
55+
codexPlanModeDeveloperInstructions,
5656
} from "../../provider/CodexDeveloperInstructions.ts";
5757
import {
5858
materializeCodexShadowHome,
@@ -578,6 +578,7 @@ export function buildCodexTurnStartParams(input: {
578578
readonly runtimePolicy: ProviderAdapterV2RuntimePolicy;
579579
readonly modelSelection: ModelSelection;
580580
readonly hasT3Mcp?: boolean;
581+
readonly browserToolsAvailable?: boolean;
581582
}) {
582583
return Effect.gen(function* () {
583584
const runtimeModeDefaults = codexRuntimeModeTurnDefaults(input.runtimePolicy.runtimeMode);
@@ -600,8 +601,8 @@ export function buildCodexTurnStartParams(input: {
600601
input.hasT3Mcp !== true
601602
? undefined
602603
: input.runtimePolicy.interactionMode === "plan"
603-
? CODEX_PLAN_MODE_DEVELOPER_INSTRUCTIONS
604-
: CODEX_DEFAULT_MODE_DEVELOPER_INSTRUCTIONS;
604+
? codexPlanModeDeveloperInstructions(input.browserToolsAvailable ?? true)
605+
: codexDefaultModeDeveloperInstructions(input.browserToolsAvailable ?? true);
605606
const collaborationMode: CodexSchema.ClientRequest__CollaborationMode | undefined =
606607
input.runtimePolicy.interactionMode !== "plan" && developerInstructions === undefined
607608
? undefined
@@ -4393,13 +4394,14 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi
43934394
const threadId = yield* getNativeThreadId(turnInput.providerThread);
43944395

43954396
const codexInput = yield* toCodexInput(turnInput);
4397+
const mcpSession = McpProviderSession.readMcpProviderSession(turnInput.threadId);
43964398
const turnStartParams = yield* buildCodexTurnStartParams({
43974399
nativeThreadId: threadId,
43984400
codexInput,
43994401
runtimePolicy: turnInput.runtimePolicy,
44004402
modelSelection: turnInput.modelSelection,
4401-
hasT3Mcp:
4402-
McpProviderSession.readMcpProviderSession(turnInput.threadId) !== undefined,
4403+
hasT3Mcp: mcpSession !== undefined,
4404+
browserToolsAvailable: mcpSession?.browserToolsAvailable ?? true,
44034405
});
44044406
yield* Ref.update(pendingRootTurns, (current) => {
44054407
const updated = new Map(current);
Collapse file

‎apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.test.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ describe("CursorAdapterV2", () => {
119119
providerInstanceId: ProviderInstanceId.make("cursor"),
120120
endpoint: "http://127.0.0.1:43123/mcp",
121121
authorizationHeader: "Bearer secret-cursor-mcp-token",
122+
browserToolsAvailable: true,
122123
});
123124

124125
try {
Collapse file

‎apps/server/src/orchestration-v2/ProviderSessionManager.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProviderSessionManager.test.ts
+56Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { ServerEnvironment } from "../environment/ServerEnvironment.ts";
2929
import * as McpProviderSession from "../mcp/McpProviderSession.ts";
3030
import * as McpSessionRegistry from "../mcp/McpSessionRegistry.ts";
3131
import { SqlitePersistenceMemory } from "../persistence/Layers/Sqlite.ts";
32+
import * as ServerSettings from "../serverSettings.ts";
3233
import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts";
3334
import { EventSinkV2, EventSinkWriteError, layer as eventSinkLayer } from "./EventSink.ts";
3435
import { layer as eventStoreLayer } from "./EventStore.ts";
@@ -338,6 +339,7 @@ function makeTestLayer(input: {
338339
readonly failReleaseEventWrites?: boolean;
339340
readonly hasPendingBackgroundWork?: Effect.Effect<boolean>;
340341
readonly hangSessionScopeClose?: boolean;
342+
readonly serverSettingsLayer?: Layer.Layer<ServerSettings.ServerSettingsService>;
341343
}) {
342344
const configuredEventSinkLayer = input.failReleaseEventWrites
343345
? FailingReleaseEventSinkLayer
@@ -372,6 +374,7 @@ function makeTestLayer(input: {
372374
idAllocatorLayer,
373375
TestMcpRegistryLayer,
374376
TestStoresLayer,
377+
...(input.serverSettingsLayer === undefined ? [] : [input.serverSettingsLayer]),
375378
),
376379
),
377380
),
@@ -784,6 +787,59 @@ it.effect(
784787
}),
785788
);
786789

790+
it.effect(
791+
"ProviderSessionManagerV2 withholds the preview capability when agent browser access is off",
792+
() =>
793+
Effect.gen(function* () {
794+
const state = yield* Ref.make(emptyState);
795+
const mcpConfigs = yield* Ref.make<
796+
ReadonlyArray<McpProviderSession.McpProviderSessionConfig | undefined>
797+
>([]);
798+
const effect = Effect.gen(function* () {
799+
const eventSink = yield* EventSinkV2;
800+
const idAllocator = yield* IdAllocatorV2;
801+
const manager = yield* ProviderSessionManagerV2;
802+
const registry = yield* McpSessionRegistry.McpSessionRegistry;
803+
const now = yield* DateTime.now;
804+
const threadId = ThreadId.make("thread-provider-session-manager-no-browser");
805+
const providerSessionId = yield* idAllocator.allocate.providerSession({
806+
providerInstanceId: modelSelection.instanceId,
807+
threadId,
808+
});
809+
810+
yield* eventSink.write({
811+
events: [yield* makeThreadCreatedEvent({ idAllocator, threadId, now })],
812+
});
813+
yield* manager.open({
814+
threadId,
815+
providerSessionId,
816+
modelSelection,
817+
runtimePolicy,
818+
});
819+
820+
const captured = (yield* Ref.get(mcpConfigs))[0];
821+
assert.isDefined(captured);
822+
assert.equal(captured?.browserToolsAvailable, false);
823+
const token = captured?.authorizationHeader.replace(/^Bearer\s+/, "");
824+
const resolved = yield* registry.resolve(token!);
825+
assert.deepEqual(resolved?.capabilities, new Set(["orchestration", "worktree"]));
826+
827+
yield* manager.close(providerSessionId);
828+
});
829+
830+
yield* effect.pipe(
831+
Effect.provide(
832+
makeTestLayer({
833+
state,
834+
idleTimeoutMs: 1_000,
835+
mcpConfigs,
836+
serverSettingsLayer: ServerSettings.layerTest({ enableAgentBrowserAccess: false }),
837+
}),
838+
),
839+
);
840+
}),
841+
);
842+
787843
it.effect("ProviderSessionManagerV2 revokes MCP credentials when release persistence fails", () =>
788844
Effect.gen(function* () {
789845
const state = yield* Ref.make(emptyState);
Collapse file

‎apps/server/src/orchestration-v2/ProviderSessionManager.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProviderSessionManager.ts
+29-1Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import * as Scope from "effect/Scope";
2424
import * as Stream from "effect/Stream";
2525

2626
import * as McpProviderSession from "../mcp/McpProviderSession.ts";
27+
import * as ServerSettings from "../serverSettings.ts";
2728
import * as McpSessionRegistry from "../mcp/McpSessionRegistry.ts";
2829
import { EventSinkV2 } from "./EventSink.ts";
2930
import { IdAllocatorV2 } from "./IdAllocator.ts";
@@ -264,6 +265,28 @@ export const layerWithOptions = (
264265
Effect.gen(function* () {
265266
const registry = yield* ProviderAdapterRegistryV2;
266267
const mcpSessionRegistry = yield* McpSessionRegistry.McpSessionRegistry;
268+
/**
269+
* Optional so the many focused tests that assemble this layer by hand do
270+
* not each need a settings stub; the production composition always
271+
* provides it. When present, an unreadable settings file withholds
272+
* browser access rather than granting it — an explicit "off" silently
273+
* becoming "on" would violate the user's stated choice, whereas the
274+
* reverse costs an agent one toolset and is visible immediately (#7083).
275+
*/
276+
const serverSettings = yield* Effect.serviceOption(ServerSettings.ServerSettingsService);
277+
const agentBrowserAccessEnabled = Option.match(serverSettings, {
278+
onNone: () => Effect.succeed(true),
279+
onSome: (settings) =>
280+
settings.getSettings.pipe(
281+
Effect.map((resolved) => resolved.enableAgentBrowserAccess),
282+
Effect.catch((cause) =>
283+
Effect.logWarning(
284+
"Could not read server settings; withholding agent browser access for this session.",
285+
{ cause },
286+
).pipe(Effect.as(false)),
287+
),
288+
),
289+
});
267290
const eventSink = yield* EventSinkV2;
268291
const idAllocator = yield* IdAllocatorV2;
269292
const projectionStore = yield* ProjectionStoreV2;
@@ -330,6 +353,7 @@ export const layerWithOptions = (
330353
// the credential it started with, so a thread that detaches and
331354
// re-attaches across a workspace handoff must come back to the
332355
// same token or the process's tool calls fail auth.
356+
const browserToolsAvailable = yield* agentBrowserAccessEnabled;
333357
const existing = McpProviderSession.readMcpProviderSession(threadId);
334358
if (existing !== undefined) {
335359
// Reserve before the async resolve so a release cannot
@@ -340,7 +364,10 @@ export const layerWithOptions = (
340364
if (
341365
resolved !== undefined &&
342366
resolved.threadId === threadId &&
343-
resolved.providerInstanceId === providerInstanceId
367+
resolved.providerInstanceId === providerInstanceId &&
368+
// A flipped browser-access setting must not survive through
369+
// credential reuse: rotate so the new scope reflects it.
370+
resolved.capabilities.has("preview") === browserToolsAvailable
344371
) {
345372
return { mcpCredentialId: existing.providerSessionId, issued: false };
346373
}
@@ -350,6 +377,7 @@ export const layerWithOptions = (
350377
const credential = yield* mcpSessionRegistry.issue({
351378
threadId,
352379
providerInstanceId,
380+
browserToolsAvailable,
353381
});
354382
McpProviderSession.setMcpProviderSession(credential.config);
355383
reserveMcpCredential(threadId, credential.config.providerSessionId);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.