Skip to content

MCP profiles: T3 tool groups on T3's MCP server, for every provider - #827

Merged
scuttletoby merged 5 commits into
mainfrom
fork/mcp-profile-t3-tool-groups
Nov 22, 2026
Merged

scuttletoby merged 5 commits into
mainfrom
fork/mcp-profile-t3-tool-groups

Conversation

@scuttletoby

@scuttletoby scuttletoby commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

MCP profile design PR 4 (code; step 2 after the announce PR #806). Part of #814.

What and why

A profile's t3Tools now applies, for every provider. One global rule on T3's MCP server:

  • hides a T3 tool outside the calling thread's groups from tools/list;
  • keeps it out of tool_search before ranking, so a search never finds or loads a tool the thread cannot call;
  • refuses it on tools/call with a plain reason and its fix (ask the user to add the group). Alias, case-changed or padded names do not match; a JSON-RPC batch with a refused call is refused whole.

The groups are fixed as each turn starts (Claude: as its query opens; other providers: turn start, resume and compaction through the turn check), so a running turn keeps its set and a change applies from the next turn. Fails closed: a missing or broken profile, an unreadable parent or a deleted thread keeps only request_secret, send_to_user and tool_search. A child is never wider than its parent.

Claude and Codex no longer refuse a profile whose t3Tools is a list, and a Claude group change gives its next turn a fresh process. On any other provider, a turn refuses only a profile that leaves out an outside server.

After the fix round (#806 lenses): a drift test holds the filter's table to exactly the toolkit folders' tools, each in its folder's group, and every group of MCP_T3_TOOL_GROUPS must have a tool there (dropping a toolkit or adding an empty group fails CI). A tool in no group is still refused by any profile but all, and its refusal says it is a T3 bug to report. docs/fork: profiles are not a sandbox (requests with no thread, such as the t3 thread CLI, are not filtered); the sets live per thread.

Up to date with main: the turn-check split (#814 item 1)

Main now has #826 (Codex applies a profile's outside servers) and #809 (the playtest tool). This PR merged main (merge commits, no rebase) and does the split #814 asks for:

  • mcpProfileTurnCheck fixes the thread's T3 tool set on every driver except Claude (Claude's adapter fixes its own as its query opens, unchanged). It refuses a profile that leaves out an outside server only on drivers not in MCP_PROFILE_DRIVERS. So a Codex turn (start, resume, compaction) is now checked: its set is fixed, and its outside servers are left to Codex.
  • Codex's own "refuse t3Tools other than all" guard is lifted. Why it is safe: T3 tools are cut on T3's own MCP server by the thread's credential (both of T3's Codex servers send it), not by Codex config, so a narrowed t3Tools needs nothing from Codex. Every turn T3 starts fixes the set through the turn check, and every turn Codex starts itself (a goal's next turn, a sub-agent turn, which uses its parent's T3 thread) fixes it on turn/started in codexMcpProfile. With no set fixed (for example after a restart), the filter works it out from settings and fails closed.
  • Drift: playtest keeps its own group (playtest), is in all, and is not in waits; the filter test now provides the playtest service main's MCP server needs.

New tests: a Codex thread with a narrowed t3Tools gets exactly that set on start, resume and compaction, while OpenCode (outside MCP_PROFILE_DRIVERS) refuses the same profile's outside servers; Claude's turn check fixes no set; a profile change applies from the next turn; a profile that is gone refuses on Codex and OpenCode and keeps only the ungrouped tools; Codex loads a profile that limits only T3 tools with no extra config and fixes its set on turn/started. Without the split, 4 of the turn-check tests fail.

State question:

  • Profile changed mid-turn: the running turn keeps its set; the next turn (or Codex's next turn/started) fixes the new one.
  • App-server restart: the per-thread sets are in memory only; after a restart the first request works the set out from settings (fails closed), and the next turn fixes it again.
  • Old threads with no profile: they resolve to all as before, with no extra Codex requests or config.

Tests

On this head: server typecheck clean; mcpProfileTurnCheck, codexMcpProfile, mcpT3ToolFilter, claudeMcpProfile, personOnlySettings and holdWork.boot tests pass (154). vp fmt --check, lint and knip pass. Seam check: only the pinned seams (the two McpToolExposure.ts lines announced in #806 move from announced to added). Before the merge: 85 files / 1585 tests passed; 6 of 9 new transport tests fail on the old code; 15 fix lines each turn a test red when removed. Fork lines in McpHttpServer.ts stay at 10.

Limits: a non-Claude provider may keep an old tool list until it lists again (the call is still refused). A Codex sub-agent's turn/started fixes its parent's set again. Delegating to a non-Claude provider on another machine refuses any profile narrower than all.

General vs project

General: T3's own MCP server and the profile rules; no project facts.

Upstream fit

Builds on upstream's MCP server, tool_search and toolkit registration; two pinned lines in McpToolExposure.ts, everything else in fork files.

MCP profile design row PR 4.

🤖 Generated with Claude Code

scuttletoby and others added 2 commits November 21, 2026 21:50
MCP profile design PR 4. A profile's t3Tools now applies: one global
rule on T3's MCP server hides a T3 tool outside the calling thread's
groups from tools/list, refuses it on tools/call with a plain reason and
its fix, and keeps it out of tool_search. The groups are fixed as each
turn starts (Claude: as its query opens; other providers: the turn
check), so a running turn keeps its set and a change applies from the
next turn. A profile that cannot be worked out, or a thread T3 cannot
read, keeps only request_secret, send_to_user and tool_search.

Claude no longer refuses a profile whose t3Tools is a list, and a group
change gives its next turn a fresh process. Off Claude, a turn now
refuses only a profile that leaves out an outside server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…up is refused as a T3 bug

- personOnlySettings.test.ts: the T3 tool filter's table must hold exactly the toolkit folders'
  tools, each in its folder's group, and every group of MCP_T3_TOOL_GROUPS must have a tool there.
  Dropping a toolkit from the filter's hand list, or adding a group with no toolkit, fails CI.
- A tool in no group is still refused by any profile but all, but its refusal now says it is a T3
  bug to report, not a setting to change.
- docs/fork: profiles are not a sandbox (requests with no thread, such as the t3 thread CLI, are not
  filtered); the sets live per thread, not per credential.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
scuttletoby and others added 3 commits November 22, 2026 04:30
…n check

Main gained MCP part 5 (Codex applies a profile's outside servers) and the
playtest tool. The turn check now fixes the thread's T3 tool set on every
provider except Claude (whose adapter fixes its own), and refuses a profile
that leaves out outside servers only on providers that cannot apply them.
Codex no longer refuses a narrowed t3Tools: T3's own MCP server cuts the
tools per thread, and every Codex turn, including the ones Codex starts
itself, fixes the set first. The playtest tool keeps its own group.

Part of #814.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…widths

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: security · reviewer: lens agent (Opus 5.5) · read at: 5084fd5
verdict: safe to merge
covered: the diff against main: mcpT3ToolFilter.ts, mcpT3ToolSets.ts, mcpProfileTurnCheck.ts (the split), codexMcpProfile.ts (guard removal, check/watchTurn/adoptChildren), claudeMcpProfile.ts (set fixed in planFor, planKey), mcpProfile.ts groups, the two McpToolExposure.ts lines, the McpHttpServer.ts wiring; plus the code they rely on: per-thread credentials in ProviderSessionManager.prepareMcpSession, Codex's per-thread Authorization header in codexThreadRuntimeParams (start, resume, fork), layerDeferredListing, and how effect 4.1.5 McpServer runs global visibility gates (the stack is read per request; every gate must pass, on lists and on calls).
checks: ran the 6 changed test files (154 passed) and the server typecheck (0 errors) on this head. Attacks, each with its result:

  • Codex guard removal: T3 tools are cut on T3's server by the thread in the credential. Codex gets that credential only in per-thread config (mcp_servers.t3-code / t3-code-direct headers), never in the shared app-server's env, so thread X's set cannot reach thread Y. Codex sub-agents copy the parent's config, so they call as the parent and get the parent's set. A Codex thread T3 did not load (no credential in its config) has no thread credential, so it gets no thread's tools. With only t3Tools narrowed, narrowed stays false; that is safe, because Codex config plays no part in T3 tools.
  • Turns T3 starts (start, resume, compaction, turn/start, thread/goal/set): the set is fixed before the request is sent, in both the turn check (mcpProfileTurnCheck.ts:93) and Codex's intercept. Claude fixes it in planFor on every turn, before the live-query reuse decision.
  • Credential missing or reused: each credential is bound to one thread id and rechecked on reuse. Sets are kept per thread, so a reused credential gets the thread's current set.
  • Restart or no set yet: setFor reads the settings before it answers (lineage cut, refusal = only the 3 ungrouped tools). tool_search's synchronous filter sees the set the gate just remembered; with no set it falls back to "refused", never "all". A settings or store error that is not a profile refusal fails the whole request, which is also closed.
  • Tool names: a new tool in a known folder joins that folder's group. A new folder, an extra tool in message/toolSearch, a name two toolkits put in different groups, or a name outside the table: refused for every profile but all. Only all passes unknown names, as before.
  • Other ways in: T3 serves no resources or prompts. Calls are matched by exact name and refused before the handler. Linked-environment calls are filtered locally by the tool's name before they are forwarded. The deferred-listing gate and this filter must both pass.
    state: runs again: each turn re-reads the settings and fixes the set again (same result for the same settings; tests cover start, resume and compaction twice). Stops half-way: set fixed but turn refused (OpenCode with narrowed servers, or a later Codex listing failure) leaves the current profile's set, never wider. The profile read interrupted: forgetT3ToolSet, so the next request works it out again from the settings. Turn started but no set fixed (a Codex-started turn whose forked check has not finished, or a thread not in known): it keeps the previous set; see minors 1 and 3. Old or empty state (no profile anywhere): every thread resolves to all, as before, with no extra Codex requests; after a restart, sets are worked out from the settings, failing closed.
    blocker: none
    major: none
    minor: (1) apps/server/src/fork/codexMcpProfile.ts:340-353: a turn Codex starts itself (a goal's next turn, a sub-agent turn) fixes its set in a forked fiber after turn/started. If the owner narrowed t3Tools between turns, the first model step can call a T3 tool with the previous turn's set until the check lands. The window is milliseconds (one settings read). It is never wider than what the settings allowed at the previous turn. docs/fork says these turns fix the set "as it starts": say "just after it starts", or hold the first tool call of a watched turn (MCP profiles part 5 (Codex): follow-ups from the lens reviews #814's orchestrator follow-up, now also for T3 tools); (2) codexMcpProfile.ts:289: a Codex sub-agent's turn/started re-fixes its parent's set while the parent's turn is running. This can apply the owner's newest settings, wider or narrower, to the running turn early. It is never wider than the parent's current settings (lineage cut applies), so it is not a security widening, but it breaks the documented "a running turn keeps its set"; name it in the PR's limits or docs; (3) codexMcpProfile.ts:341: a turn on a Codex thread not in known re-fixes nothing and runs with the last set fixed for the credential's thread. Same bound as (1); (4) by design and documented ("Profiles are not a sandbox"): requests with no thread (OAuth clients, the t3 CLI from an agent's shell with the owner's access) get every T3 tool, so a narrowed thread with a shell can still reach them. This is noted here only so the owner knows the profile is not a boundary against such a thread.

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: state · reviewer: lens agent (Opus, lens B correctness + state) · read at: 5084fd5
verdict: safe to merge
covered: git diff origin/main HEAD (19 files: the #827 filter, sets and tests, plus the split), compared with #827's old head 3e42ee7 and #826's merged codexMcpProfile.ts; issue #814 item 1; every toolkit under src/mcp/toolkits against T3_TOOL_GROUPS (playtest in its own group, t3_thread_send and schedule_task both in orchestration); how Codex (per-thread Authorization on both T3 servers) and OpenCode (per-thread server name, other threads' T3 servers denied) carry the thread credential; .github/fork-seams.json; the docs/fork/README.md and FORK_CHANGES.md text against the code.
checks: the 6 changed test files pass (154 tests); the server typecheck is clean; the seam check (--no-upstream origin/main HEAD) passes with only the pinned seams. With the split undone (appliesMcpProfiles back in the wrap, no driver test in the refusal), 4 turn-check tests fail. With the fixT3ToolSet line in Codex's check removed, 1 Codex test fails (it covers a Codex-started turn/started). The tests use a real SQLite store, upstream's settings service and the real registry wrap, and mock only the provider runtime, not the check.
state: runs again: each turn start fixes the set again from the current settings, and the same set comes out. Stopped half-way: an interrupted turn check or Claude query open forgets the set, so the next request works it out again. Profile changed mid-turn: the running turn keeps its set and the next turn (or Codex's next turn/started) fixes the new one, except as in minor 1. App-server restart: Codex's known map starts empty and its first resume and turn fix the set again; T3's sets are kept in T3's memory, not the app-server's. T3 restart: the sets are empty, so the first request works the set out from the settings and the store, and fails closed. Settings unreadable: the profile is refused, the set keeps only the ungrouped tools, and the turn is refused on every driver, as Claude already was on main. Old threads with no profile: they resolve to all; Claude's plan key is unchanged, so there is no fresh process; Codex gets no new app-server request (config/read and the server list only run when servers is not all). The one extra cost is one settings and store read per Codex turn in the turn check.
blocker: none
major: none
minor: apps/server/src/fork/codexMcpProfile.ts:283-289 (via watchTurn :340-342 and thread/goal/set in startsWork :322-324): a Codex sub-agent's turn/started, or a goal set to active, fixes the parent T3 thread's set while the parent's turn is still running, so a profile change reaches that running turn early (narrower or wider). The PR body lists this under Limits, but docs/fork/README.md says a running turn keeps its set. Say so in the docs, or skip the fix when the turn is a known sub-agent's.
minor: apps/server/src/fork/mcpT3ToolFilter.ts:234-239: a request that comes before any turn (for example Codex listing tools as it loads a thread) remembers a Refused set if the store or settings read fails just then. A provider that lists tools only once keeps the narrower list after the next turn fixes the real set. Calls still work, but the agent does not see the tools until the provider lists them again. The window is small, because on main the same failure during Codex's own load refused the load. Consider not remembering a Refused set (work it out again on the next request).
minor: apps/server/src/fork/mcpProfileTurnCheck.ts:121: now that Codex is wrapped, one Codex turn works out its profile three times (the turn check, Codex's turn/start check and its turn/started watch), each reading settings.json and the store. This is not a correctness problem; it is one more read per turn than main.

@scuttletoby
scuttletoby merged commit 4a3f63a into main Nov 22, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant