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): every T3 MCP tool declares who may call it by juliusmarminge · Pull Request #16335 · pingdotgg/t3code

feat(server): every T3 MCP tool declares who may call it #16335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
juliusmarminge merged 14 commits into main from t3code/mcp/declared-access
Oct 6, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

feat(server): every T3 MCP tool declares who may call it #16335

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
c73e903
fix(server): MCP launches bind only the project's own worktrees
juliusmarminge Oct 5, 2026
d16f002
feat(server): every T3 MCP tool declares who may call it
juliusmarminge Oct 6, 2026
5f68c43
fix(server): MCP access checks can't be skipped or outlived
juliusmarminge Oct 6, 2026
8206787
docs(server): agents learn they may launch within their own modes
juliusmarminge Oct 6, 2026
0dc83e6
fix(server): only McpToolAccess can build a declaration
juliusmarminge Oct 6, 2026
f88e3d2
fix(server): task_cancel checks the child's modes, and declarations r…
juliusmarminge Oct 6, 2026
97e689d
fix(lint): every way of registering on /mcp goes through McpToolAccess
juliusmarminge Oct 6, 2026
89fee81
fix(server): task_cancel checks every task it stops, and McpServer st…
juliusmarminge Oct 6, 2026
dab39ce
fix(server): task_cancel also checks the tasks under a deleted child
juliusmarminge Oct 6, 2026
46d2e68
fix(lint): tests import McpServer only by its own name
juliusmarminge Oct 6, 2026
0efd36c
fix(server): MCP writes need thread control, and launches skip remove…
juliusmarminge Oct 6, 2026
1402469
fix(server): MCP writes re-check a thread's modes under its command lock
juliusmarminge Oct 6, 2026
94af7c4
Merge remote-tracking branch 'origin/main' into t3code/mcp/declared-a…
juliusmarminge Oct 6, 2026
5b50653
fix(server): check a fork's source modes on the copy it makes
juliusmarminge Oct 6, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Prev Previous commit
Next Next commit
fix(server): only McpToolAccess can build a declaration
Review found the access classes still had public `make` methods, so any
module could wrap an unchecked handler in a Declaration, or a raw toolkit
layer in a HandlersLayer, and register it. Both constructors are now
reachable only from module-scoped functions set in the classes' static
blocks; outside the module there is no way to build either.

Webhook URLs also went to a thread caller whose turn had ended. They now
need a live turn, like any other way of starting work.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@juliusmarminge @claude
juliusmarminge and claude committed Oct 6, 2026
commit 0dc83e6d190c6e96509e828e8127e1974c8ac2c4

Some comments aren't visible on the classic Files Changed page.

There are no files selected for viewing

6 changes: 6 additions & 0 deletions 6 apps/server/src/mcp/McpToolAccess.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ export const refusedAtCompileTime = () => {
McpToolAccess.reads(() => ran),
),
});
// @ts-expect-error a declaration built outside McpToolAccess
McpToolAccess.Declaration.make(unchecked);
// @ts-expect-error a declaration constructed directly
new McpToolAccess.Declaration(unchecked);
// @ts-expect-error a handlers layer built outside McpToolAccess
McpToolAccess.HandlersLayer.make(Layer.empty);
// The refused layer below types its error and services as unknown, which is fine here.
// @effect-diagnostics-next-line anyUnknownInErrorContext:off
McpHttpServer.toolkitRegistration(
Expand Down
43 changes: 43 additions & 0 deletions 43 apps/server/src/mcp/McpToolAccess.testkit.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
type OrchestrationV2ThreadProjection,
type OrchestrationV2ThreadShell,
ProjectId,
type ProviderInteractionMode,
Expand Down Expand Up @@ -70,3 +71,45 @@ export const liveThreadShell = (
export const liveThreadsLayer = Layer.mock(ThreadManagement.ThreadManagementService)({
getThreadShell: (threadId) => Effect.succeed(liveThreadShell(threadId)),
});

/**
* The thread of `shell` with no runs, messages or other records: what a
* caller looks like once its turn has ended.
*/
export const idleThreadProjection = (
shell: OrchestrationV2ThreadShell,
): OrchestrationV2ThreadProjection => {
const {
status: _status,
activeRunId: _activeRunId,
latestRunId: _latestRunId,
pendingRuntimeRequest: _pendingRuntimeRequest,
latestVisibleMessage: _latestVisibleMessage,
latestUserMessageAt: _latestUserMessageAt,
hasActionableProposedPlan: _hasActionableProposedPlan,
itemCount: _itemCount,
visibleItemCount: _visibleItemCount,
lastVisitedAt,
...thread
} = shell;
return {
thread: { ...thread, lastVisitedAt: lastVisitedAt ?? null },
runs: [],
attempts: [],
nodes: [],
subagents: [],
providerSessions: [],
providerThreads: [],
providerTurns: [],
runtimeRequests: [],
messages: [],
plans: [],
turnItems: [],
checkpointScopes: [],
checkpoints: [],
contextHandoffs: [],
contextTransfers: [],
visibleTurnItems: [],
updatedAt: shell.updatedAt,
};
};
70 changes: 39 additions & 31 deletions 70 apps/server/src/mcp/McpToolAccess.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,28 @@ import {
unavailable,
} from "./threadAccess.ts";

// Only the classes below assign these, from their static blocks, so nothing
// outside this module can build a declaration or a handlers layer.

/** Builds a declaration; only the declaration functions below call it. */
let declare: <P, A, E, R>(
handle: (params: P) => Effect.Effect<A, E, R>,
) => Declaration<(params: P) => Effect.Effect<A, E, R>>;

type CheckedHandlerOf<D> = D extends Declaration<infer Handler> ? Handler : never;

/** Turns each declaration back into the handler it checks, keeping its type. */
interface CheckedHandler extends Struct.Lambda {
<Handler>(declaration: Declaration<Handler>): Handler;
readonly "~lambda.out": CheckedHandlerOf<this["~lambda.in"]>;
}
let checkedHandler: CheckedHandler;

/** Only `toLayer` below builds one. */
let handlersLayer: <Tools extends Record<string, Tool.Any>, EX, RX>(
layer: Layer.Layer<Tool.HandlersFor<Tools>, EX, RX>,
) => HandlersLayer<Tools, EX, RX>;

/**
* Who may call a T3 MCP tool. Every handler is built by one of the
* declarations below, which say what the tool does. `toLayer` accepts only
Expand All @@ -41,20 +63,17 @@ import {
* check what only they can see, such as a queued run belonging to its thread.
*/
export class Declaration<out Handler> {
// A private field makes the class nominal: only `make` below produces one,
// and copying a declaration's fields onto anything else fails to typecheck
// and, at runtime, to run.
// A private field makes the class nominal, and only this module can build
// one: its constructor is private and the static block hands the only way
// in to module-scoped functions. Copying a declaration's fields onto
// anything else fails to typecheck and, at runtime, to run.
readonly #handle: Handler;
private constructor(handle: Handler) {
this.#handle = handle;
}
/** @internal Builds a declaration; only the functions below call it. */
static make<P, A, E, R>(handle: (params: P) => Effect.Effect<A, E, R>) {
return new Declaration(handle);
}
/** @internal The checked handler, for `toLayer`. */
static handler<Handler>(declaration: Declaration<Handler>): Handler {
return declaration.#handle;
static {
declare = (handle) => new Declaration(handle);
checkedHandler = Struct.lambda<CheckedHandler>((declaration) => declaration.#handle);
}
}

Expand All @@ -67,19 +86,19 @@ const requireThreadCaller = McpInvocationContext.McpInvocationContext.pipe(

/** Changes nothing, so every caller may call it. */
export const reads = <P, A, E, R>(handle: (params: P) => Effect.Effect<A, E, R>) =>
Declaration.make((params: P) => handle(params));
declare((params: P) => handle(params));

/** Reads what belongs to the calling T3 thread, such as its preview tabs or devices. */
export const readsAsCaller = <P, A, E, R>(handle: (params: P) => Effect.Effect<A, E, R>) =>
Declaration.make((params: P) => requireThreadCaller.pipe(Effect.flatMap(() => handle(params))));
declare((params: P) => requireThreadCaller.pipe(Effect.flatMap(() => handle(params))));

/**
* Acts as the calling T3 thread (its subagents, preview tabs, devices,
* worktree) while that thread's run is live. Only an agent running inside a
* T3 thread has one.
*/
export const actsAsCaller = <P, A, E, R>(handle: (params: P) => Effect.Effect<A, E, R>) =>
Declaration.make((params: P) =>
declare((params: P) =>
requireThreadCaller.pipe(
Effect.flatMap(() => writingCaller),
Effect.flatMap(() => handle(params)),
Expand All @@ -88,7 +107,7 @@ export const actsAsCaller = <P, A, E, R>(handle: (params: P) => Effect.Effect<A,

/** Changes something that belongs to no thread, such as a pending upload or a scheduled task. */
export const writes = <P, A, E, R>(handle: (params: P) => Effect.Effect<A, E, R>) =>
Declaration.make((params: P) => writingCaller.pipe(Effect.flatMap(() => handle(params))));
declare((params: P) => writingCaller.pipe(Effect.flatMap(() => handle(params))));

/**
* Changes the threads `threads` names. An omitted id is the caller's own
Expand All @@ -99,7 +118,7 @@ export const writesThreads = <P, A, E, R>(
threads: (params: P) => ReadonlyArray<ThreadId | undefined>,
handle: (params: P) => Effect.Effect<A, E, R>,
) =>
Declaration.make((params: P) =>
declare((params: P) =>
Effect.gen(function* () {
const caller = yield* writingCaller;
for (const threadId of threads(params)) {
Expand Down Expand Up @@ -129,7 +148,7 @@ export const startsThreads = <P, A, E, R>(
},
handle: (params: P, modes: StartedModes) => Effect.Effect<A, E, R>,
) =>
Declaration.make((params: P) =>
declare((params: P) =>
Effect.gen(function* () {
const { limits } = yield* writingCaller;
const requested = modes(params);
Expand Down Expand Up @@ -161,7 +180,7 @@ export const writesEnvironment = <P, A, E, R>(
const check = writingCaller.pipe(
Effect.tap((caller) => assertFullAccess(caller, fullAccessRequired)),
);
return Declaration.make((params: P) => check.pipe(Effect.flatMap(() => handle(params, check))));
return declare((params: P) => check.pipe(Effect.flatMap(() => handle(params, check))));
};

/** What a declaration's own check needs. */
Expand Down Expand Up @@ -193,11 +212,8 @@ export class HandlersLayer<Tools extends Record<string, Tool.Any>, EX = never, R
private constructor(layer: Layer.Layer<Tool.HandlersFor<Tools>, EX, RX>) {
this.#layer = layer;
}
/** @internal Only `toLayer` below builds one. */
static make<Tools extends Record<string, Tool.Any>, EX, RX>(
layer: Layer.Layer<Tool.HandlersFor<Tools>, EX, RX>,
) {
return new HandlersLayer(layer);
static {
handlersLayer = (layer) => new HandlersLayer(layer);
}
/** The handlers, for registering this toolkit on the MCP server. */
static layer<Tools extends Record<string, Tool.Any>, EX, RX>(
Expand All @@ -207,14 +223,6 @@ export class HandlersLayer<Tools extends Record<string, Tool.Any>, EX = never, R
}
}

type CheckedHandlerOf<D> = D extends Declaration<infer Handler> ? Handler : never;

/** Turns each declaration back into the handler it checks, keeping its type. */
interface CheckedHandler extends Struct.Lambda {
<Handler>(declaration: Declaration<Handler>): Handler;
readonly "~lambda.out": CheckedHandlerOf<this["~lambda.in"]>;
}
const checkedHandler = Struct.lambda<CheckedHandler>(Declaration.handler);
const checkedHandlers = <Handlers>(declarations: Declarations<Handlers>): Handlers =>
Struct.map(declarations, checkedHandler);

Expand All @@ -223,7 +231,7 @@ export const toLayer = <Tools extends Record<string, Tool.Any>, EX = never, RX =
toolkit: Toolkit.Toolkit<Tools>,
build: Handlers<Tools> | Effect.Effect<Handlers<Tools>, EX, RX>,
): HandlersLayer<Tools, EX, Exclude<RX, Scope.Scope>> =>
HandlersLayer.make(
handlersLayer(
toolkit.toLayer(
Effect.isEffect(build)
? Effect.map(build, checkedHandlers<Toolkit.HandlersFrom<Tools>>)
Expand Down
52 changes: 51 additions & 1 deletion 52 apps/server/src/mcp/OrchestratorMcpService.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import * as ProjectService from "../project/ProjectService.ts";
import * as ScheduledTaskService from "../scheduledTasks/ScheduledTaskService.ts";
import * as SecretRequests from "../secrets/SecretRequests.ts";
import type { McpInvocationScope } from "./McpInvocationContext.ts";
import { liveThreadShell } from "./McpToolAccess.testkit.ts";
import { idleThreadProjection, liveThreadShell } from "./McpToolAccess.testkit.ts";
import * as OrchestratorMcpService from "./OrchestratorMcpService.ts";

describe("OrchestratorMcpService", () => {
Expand Down Expand Up @@ -1393,6 +1393,56 @@ describe("OrchestratorMcpService provider resolution", () => {
}),
);

it.effect("hides a webhook URL from a thread whose turn has ended", () =>
Effect.gen(function* () {
const callerId = ThreadId.make("thread:scheduled-ended");
const shell = liveThreadShell(callerId, { activeRunId: null });
const listed = yield* OrchestratorMcpService.OrchestratorMcpService.pipe(
Effect.flatMap((mcp) =>
mcp.listScheduledTasks(
{
...supervisedClient,
requestNamespace: "provider:scheduled-ended",
thread: {
threadId: callerId,
providerSessionId: "provider:scheduled-ended",
providerInstanceId: shell.providerInstanceId,
},
client: undefined,
},
{ projectId },
),
),
Effect.provide(
OrchestratorMcpService.layer.pipe(
Layer.provide(
Layer.mergeAll(
NodeServices.layer,
Layer.mock(ThreadManagementService.ThreadManagementService)({
getThreadShell: () => Effect.succeed(null),
// Its turn ended: no run is active.
getThreadRecords: () => Effect.succeed(idleThreadProjection(shell)),
}),
Layer.mock(ProviderRegistry.ProviderRegistry)({
getProviders: Effect.succeed([]),
}),
Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({
list: () => Effect.succeed([]),
}),
Layer.mock(ProjectService.ProjectService)({}),
Layer.mock(SecretRequests.SecretRequests)({}),
Layer.mock(ScheduledTaskService.ScheduledTaskService)({
list: () => Effect.succeed({ tasks: [task({})] }),
}),
),
),
),
),
);
assert.equal(listed.tasks[0]?.webhookUrl, undefined);
}),
);

it.effect("checks a bound task against its thread's current modes", () =>
Effect.gen(function* () {
const upserted = yield* Ref.make(0);
Expand Down
51 changes: 31 additions & 20 deletions 51 apps/server/src/mcp/OrchestratorMcpService.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1368,11 +1368,6 @@ const make = Effect.gen(function* () {
);
}).pipe(Effect.timeoutOption(Duration.millis(timeoutMs)), Effect.map(Option.flatten));

/**
* A scheduled task the caller may change: one whose modes are no broader
* than the caller's own, so editing its prompt cannot run work above the
* caller's limits.
*/
/**
* The modes a task's runs execute at: its own, or for a task bound to a
* thread, also that thread's modes as they are now, since its runs are
Expand All @@ -1398,22 +1393,38 @@ const make = Effect.gen(function* () {
runtimeModeRank(modes.runtimeMode) <= runtimeModeRank(limits.runtimeMode) &&
interactionModeRank(modes.interactionMode) <= interactionModeRank(limits.interactionMode);

/**
* A task as the caller may see it. Its webhook URL starts runs, so only a
* caller that may start one sees it: a thread caller with a live turn, at
* modes covering every mode the task runs at.
*/
const summarizeScheduledTask = (
task: ScheduledTask,
limits: {
readonly runtimeMode: RuntimeMode;
readonly interactionMode: ProviderInteractionMode;
scope: McpInvocationScope,
caller: {
readonly parent: Pick<OrchestrationV2ThreadProjection, "thread" | "runs"> | undefined;
readonly limits: {
readonly runtimeMode: RuntimeMode;
readonly interactionMode: ProviderInteractionMode;
};
},
task: ScheduledTask,
) =>
scheduledTaskRunModes(task).pipe(
Effect.map((modes) =>
scheduledTaskSummary(
task,
modes.every((mode) => withinLimits(limits, mode)),
),
),
);
Effect.gen(function* () {
const live =
caller.parent === undefined ||
Exit.isSuccess(yield* Effect.exit(assertLiveCaller(scope, caller.parent)));
const modes = yield* scheduledTaskRunModes(task);
return scheduledTaskSummary(
task,
live && modes.every((mode) => withinLimits(caller.limits, mode)),
);
});

/**
* A scheduled task the caller may change: one whose runs execute at modes no
* broader than the caller's own, so editing its prompt cannot run work above
* the caller's limits.
*/
const loadScheduledTask = (
scheduledTaskId: ScheduledTask["id"],
limits: {
Expand Down Expand Up @@ -1499,7 +1510,7 @@ const make = Effect.gen(function* () {
failure("orchestration_error", `Could not schedule task: ${error.message}`),
),
);
return yield* summarizeScheduledTask(task, limits);
return yield* summarizeScheduledTask(scope, { parent, limits }, task);
}),
listScheduledTasks: (scope, input) =>
Effect.gen(function* () {
Expand All @@ -1515,7 +1526,7 @@ const make = Effect.gen(function* () {
return {
tasks: yield* Effect.forEach(
tasks.filter((task) => projectId === undefined || task.projectId === projectId),
(task) => summarizeScheduledTask(task, limits),
(task) => summarizeScheduledTask(scope, { parent, limits }, task),
),
};
}),
Expand Down Expand Up @@ -1570,7 +1581,7 @@ const make = Effect.gen(function* () {
failure("orchestration_error", `Could not update scheduled task: ${error.message}`),
),
);
return yield* summarizeScheduledTask(task, limits);
return yield* summarizeScheduledTask(scope, { parent, limits }, task);
}),
deleteScheduledTask: (scope, input) =>
Effect.gen(function* () {
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402809 — 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.