@devries-cameron20 / t3code Mirror · read-only / commits / 89081d046c
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 00:30 UTC

fix(codex): launch-arg MCP servers survive the thread's t3-code server (#15839)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Lars Nieuwenhuis committed Oct 20, 2026 at 02:28 UTC 89081d046c5fe18f777d757663d031f2e9789962
3 files changed +129 -52
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
+117 -43
@@ -723,49 +723,6 @@ describe("CodexAdapterV2 runtime policy", () => {
723 });
724
725 describe("CodexAdapterV2 process spawning", () => {
726 - it("injects cwd, model, and MCP authorization into thread-scoped params", () => {
727 - const threadId = ThreadId.make("thread-codex-mcp");
728 - const mcpSession = {
729 - environmentId: EnvironmentId.make("environment-codex-mcp"),
730 - threadId,
731 - providerSessionId: "mcp-session-codex",
732 - providerInstanceId: ProviderInstanceId.make("codex"),
733 - endpoint: "http://127.0.0.1:43123/mcp",
734 - authorizationHeader: "Bearer secret-codex-token",
735 - browserToolsAvailable: true,
736 - };
737 -
738 - assert.deepEqual(
739 - CodexAdapterV2.codexThreadRuntimeParams({
740 - mcpSession,
741 - modelSelection: { model: "gpt-5.4" },
742 - runtimePolicy: {
743 - runtimeMode: "full-access",
744 - interactionMode: "default",
745 - cwd: "/workspace/thread-codex-mcp",
746 - },
747 - }),
748 - {
749 - cwd: "/workspace/thread-codex-mcp",
750 - model: "gpt-5.4",
751 - config: {
752 - "tools.update_plan.enabled": true,
753 - // Codex waits up to 10 s, not 1 s, for MCP servers before the first request (#13437).
754 - mcp_optional_startup_grace_ms: 10_000,
755 - mcp_servers: {
756 - "t3-code": {
757 - url: "http://127.0.0.1:43123/mcp",
758 - tool_timeout_sec: 3_900,
759 - http_headers: {
760 - Authorization: "Bearer secret-codex-token",
761 - },
762 - },
763 - },
764 - },
765 - },
766 - );
767 - });
768 -
726 it.effect("resolves Windows command shims through the shared spawn policy", () =>
727 Effect.gen(function* () {
728 const command = yield* CodexAdapterV2.makeCodexAppServerSpawnCommand({
@@ -2275,6 +2232,123 @@ describe("CodexAdapterV2 post-settle continuation", () => {
2232 ),
2233 );
2234
2235 + it.effect("adds the session MCP server without replacing launch-argument servers", () =>
2236 + Effect.gen(function* () {
2237 + const scenario = "launch-mcp-servers";
2238 + yield* (yield* McpProviderSessions.McpProviderSessions).set({
2239 + environmentId: EnvironmentId.make("environment-codex-mcp"),
2240 + threadId: ThreadId.make(`thread-${scenario}`),
2241 + providerSessionId: `provider-session-${scenario}`,
2242 + providerInstanceId: ProviderInstanceId.make("codex"),
2243 + endpoint: "http://127.0.0.1:43123/mcp",
2244 + authorizationHeader: "Bearer secret-codex-token",
2245 + browserToolsAvailable: true,
2246 + });
2247 + const requests: Array<unknown> = [];
2248 + yield* makeCodexReplayHarness(
2249 + makeCodexReplayTranscript({
2250 + scenario,
2251 + entries: codexReplayPreamble({
2252 + nativeThreadId: "launch-mcp-thread",
2253 + nativeTurnId: "unused",
2254 + prompt: "unused",
2255 + }).slice(0, 5),
2256 + }),
2257 + () => Effect.void,
2258 + (method, params) =>
2259 + Effect.sync(() => {
2260 + if (method === "thread/start") requests.push(params);
2261 + }),
2262 + );
2263 + assert.deepEqual(requests, [
2264 + {
2265 + cwd: "/workspace",
2266 + model: "gpt-5.4",
2267 + config: {
2268 + "tools.update_plan.enabled": true,
2269 + mcp_optional_startup_grace_ms: 10_000,
2270 + "mcp_servers.t3-code": {
2271 + url: "http://127.0.0.1:43123/mcp",
2272 + tool_timeout_sec: 3_900,
2273 + http_headers: { Authorization: "Bearer secret-codex-token" },
2274 + },
2275 + },
2276 + },
2277 + ]);
2278 + }).pipe(
2279 + Effect.scoped,
2280 + Effect.provide(
2281 + Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
2282 + ),
2283 + ),
2284 + );
2285 +
2286 + it.effect("replays historical and dotted MCP config while enforcing other thread config", () =>
2287 + Effect.gen(function* () {
2288 + const recordedServer = {
2289 + url: "http://127.0.0.1:41000/mcp",
2290 + http_headers: { Authorization: "Bearer recorded-token" },
2291 + };
2292 + const currentConfig = {
2293 + "tools.update_plan.enabled": true,
2294 + "mcp_servers.t3-code": {
2295 + url: "http://127.0.0.1:42000/mcp",
2296 + http_headers: { Authorization: "Bearer current-token" },
2297 + },
2298 + "mcp_servers.extra.command": "cat",
2299 + };
2300 + for (const recordedMcp of [
2301 + { mcp_servers: { "t3-code": recordedServer } },
2302 + { "mcp_servers.t3-code": recordedServer, "mcp_servers.extra.command": "echo" },
2303 + ]) {
2304 + const entries = codexReplayPreamble({
2305 + nativeThreadId: "replayed-mcp-thread",
2306 + nativeTurnId: "unused",
2307 + prompt: "unused",
2308 + })
2309 + .slice(3, 5)
2310 + .map((entry) => withReplayRequestId(entry, 1));
2311 + entries[0] = {
2312 + type: "expect_outbound",
2313 + frame: {
2314 + id: 1,
2315 + method: "thread/start",
2316 + params: { config: { "tools.update_plan.enabled": true, ...recordedMcp } },
2317 + },
2318 + };
2319 + entries.push({
2320 + ...entries[0],
2321 + frame: {
2322 + id: 2,
2323 + method: "thread/start",
2324 + params: { config: { "tools.update_plan.enabled": true, ...recordedMcp } },
2325 + },
2326 + });
2327 + const driver = yield* CodexReplay.makeReplayDriver(
2328 + makeCodexReplayTranscript({
2329 + scenario: "mcp-config-normalization",
2330 + entries,
2331 + }),
2332 + );
2333 + yield* Effect.gen(function* () {
2334 + const client = yield* CodexClient.CodexAppServerClient;
2335 + const response = yield* client.request("thread/start", { config: currentConfig });
2336 + assert.equal(response.thread.id, "replayed-mcp-thread");
2337 + assert.isNull((yield* Ref.get(driver.state)).failure);
2338 + yield* client
2339 + .request("thread/start", {
2340 + config: { ...currentConfig, "tools.update_plan.enabled": false },
2341 + })
2342 + .pipe(Effect.flip);
2343 + assert.instanceOf(
2344 + (yield* Ref.get(driver.state)).failure,
2345 + CodexReplay.CodexAppServerReplayFrameMismatchError,
2346 + );
2347 + }).pipe(Effect.provide(CodexReplay.layerReplayWithDriver(driver)));
2348 + }
2349 + }).pipe(Effect.scoped),
2350 + );
2351 +
2352 it.effect("identifies sessions to Codex with the same client info as main", () =>
2353 Effect.gen(function* () {
2354 const transcript = makeCodexReplayTranscript({
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+7 -8
@@ -1303,7 +1303,7 @@ export const CODEX_THREAD_CONFIG = {
1303 // that limit so the server's own wait timeout ends a long call.
1304 const CODEX_T3_MCP_TOOL_TIMEOUT_SEC = 65 * 60;
1305
1306 -export function codexThreadRuntimeParams(input: {
1306 +function codexThreadRuntimeParams(input: {
1307 readonly mcpSession: McpProviderSession.McpProviderSessionConfig | undefined;
1308 readonly modelSelection?: { readonly model: string };
1309 readonly runtimePolicy?: ProviderAdapter.ProviderAdapterV2RuntimePolicy;
@@ -1321,13 +1321,12 @@ export function codexThreadRuntimeParams(input: {
1321 ...(mcpSession === undefined
1322 ? {}
1323 : {
1324 - mcp_servers: {
1325 - "t3-code": {
1326 - url: mcpSession.endpoint,
1327 - tool_timeout_sec: CODEX_T3_MCP_TOOL_TIMEOUT_SEC,
1328 - http_headers: {
1329 - Authorization: mcpSession.authorizationHeader,
1330 - },
1324 + // Override only T3's server so launch-argument MCP servers survive.
1325 + "mcp_servers.t3-code": {
1326 + url: mcpSession.endpoint,
1327 + tool_timeout_sec: CODEX_T3_MCP_TOOL_TIMEOUT_SEC,
1328 + http_headers: {
1329 + Authorization: mcpSession.authorizationHeader,
1330 },
1331 },
1332 }),
packages/effect-codex-app-server/src/replay.ts
+5 -1
@@ -268,7 +268,11 @@ function normalizeThreadRequest(frame: unknown, ignoredConfigKeys: ReadonlySet<s
268 }
269 const { cwd: _cwd, model: _model, config, ...params } = record.params as Record<string, unknown>;
270 if (typeof config !== "object" || config === null) return { ...record, params };
271 - const { mcp_servers: _mcpServers, ...owned } = config as Record<string, unknown>;
271 + const owned = Object.fromEntries(
272 + Object.entries(config as Record<string, unknown>).filter(
273 + ([key]) => key !== "mcp_servers" && !key.startsWith("mcp_servers."),
274 + ),
275 + );
276 for (const key of ignoredConfigKeys) delete owned[key];
277 return { ...record, params: { ...params, config: owned } };
278 }