Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): OpenCode 2 threads get T3 Code's MCP tools #16142

Mergednkoynov(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/16142/headmerged by Yash-Singh1(GitHub profile, opens in a new tab) View on GitHub

Problem

OpenCode 2 threads and delegated OpenCode 2 children never see T3's MCP tools. The adapter registers the server as t3-code-<threadId>, which is 96 characters for a V2 project thread and over 100 for a delegated child. OpenCode skips every tool of a server whose name is over 64 characters (its tool-namespace limit; only its log says so), and its router 404s PUT /api/experimental/mcp/:server for a name over 100, so T3 logs "Could not add T3 Code's MCP server to OpenCode." Fixes #16140.

Change

t3McpServerName keeps a name that fits in 64 characters and otherwise uses t3-code- plus the first 16 hex characters of the thread id's SHA-256 (24 characters). The name is deterministic, so every turn of a thread registers the same server. The session's t3-code-* deny and <name>_* allow rules, mcp.add and mcp.remove all go through this name (removal uses the stored state.mcp.name), so each thread is still limited to its own server. Hashed names have a fixed length, so one thread's <name>_* allow rule can't match another thread's tools.

Scope and approval

This is a very small, focused fix for an obvious bug, and it qualifies for the exception without a prior discussion: one helper in the OpenCode 2 adapter plus tests, no contract, client or behaviour change beyond OpenCode receiving a name it accepts. The intended behaviour is already established, because the adapter registers the server for exactly this purpose. Issue #16140 has the full report. Same class of bug as #8860 (long V2 ids over a 100-character route limit, fixed in T3's own routes by #8898). #15736 also goes through prepareTurn/mcp.add, but it is a different bug.

Verification

Focused tests (in OpenCode2AdapterV2.test.ts):

  • registers a long thread id's MCP server under a name OpenCode accepts replays a delegated child id that used to produce a 120-character name. It checks that mcp.add, the session's allow rule and mcp.remove all use t3-code-aa73fa1e03099934.
  • names each thread's MCP server within OpenCode's limits, one name per thread checks real-format project and delegated ids: each name is 64 characters or fewer and valid, ids that differ only at the end get different names, a name is stable across calls, and a short id keeps its readable name.
  • Against main's adapter, both new tests fail. The first fails because the adapter rewrites the session rules with the 120-character t3-code-thread_delegated-task_…_* allow rule; the second with expected 't3-code-thread_project_ce04e4e2-…' to match /^t3-code-[A-Za-z0-9_-]{1,56}$/.
vp test run apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts apps/server/src/orchestration-v2/OpenCode2OrchestratorV2.integration.test.ts
  Test Files  2 passed (2)   Tests  96 passed (96)
vp lint <2 files>          Found 0 warnings and 0 errors.
vp fmt --check <2 files>   All matched files use the correct format.
vp run --filter t3 typecheck   exit 0

Live, with T3 from source (node apps/server/src/bin.ts serve, scratch home), OpenCode 2.0.22 spawned by T3, no OpenCode plugins, and the free opencode/big-pickle model:

Casemain @ e22c8804this PR
Project thread, Code Mode search({query: "t3_thread_configuration"}) on turn 2[]; 72 Invalid tool namespace errors in opencode.logtools["t3-code-5f396b4d3be75e9c"].t3_thread_configuration, … ; 0 errors
Claude parent → delegate_task → OpenCode child that calls t3_thread_configurationCHILD_NO_T3_TOOLS; T3 logs 404 PUT …/api/experimental/mcp/t3-code-thread_delegated-task_command_3Amcp_3A7ca20ace-…child returns its own id thread:delegated-task:command%3Amcp%3A2124c561-…%3Adelegate-task%3Aoc-child-check-1; no warning
OpenCode parent (Code Mode delegate_task) → OpenCode childparent has no T3 toolschild returns its own thread id

With cursor-opencode-provider 0.8.0 and cursor/claude-opus-5-5-1m, the model called t3-code-6fb4b99c8f0e4cda_t3_thread_configuration and got its own thread id back. On nightly 0.0.46-nightly.20261004.2648, the same model and plugin found no T3 tools, and opencode.log had the same 72 Invalid tool namespace errors.

Rebased onto main @ 3e6b4502 before opening: the same focused tests (96/96), lint and vp run --filter t3 typecheck pass there.

Not covered by this PR: on a thread's first turn the tools can still be missing, because OpenCode registers them about 100 ms after mcp.add returns (debounced) and the first step's catalog is already taken. That is a separate race (reported as #16141, the OpenCode analogue of #13437), and these tables use turn 2 to keep the cases apart. Not tested: an external serverUrl (T3 adds no MCP server there), Windows.

Model: Claude Opus 5.5 (1M). Harness: Claude Code in T3 Code.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. Approvability

      Verdict: Approved at 3267045

      Macroscope's review found this PR approvable — This is a small, self-contained fix for OpenCode 2 MCP servers whose long thread-derived names exceeded provider limits. Existing short names remain unchanged, long names become deterministic and bounded, and registration, permission matching, cleanup, and focused tests all use the same naming function.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 4f7d9f70-9d7f-420c-b472-11f9e3d9b8a5
      📥 Commits

      Reviewing files that changed from the base of the PR and between 3e6b45028ceec5820dacb37dc3852470ebdc9411 and 3267045f236766e265dde5746d0c697a2550f2f5.

      📒 Files selected for processing (2)
      • apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts
      • apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


      📝 Walkthrough

      Walkthrough

      The OpenCode 2 adapter now shortens generated MCP server names when sanitized thread IDs exceed 64 characters. Tests cover name generation and MCP server registration for a long thread ID.

      Changes

      OpenCode 2 MCP server names

      Layer / File(s)Summary
      Bounded MCP name generation
      apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.ts
      The exported t3McpServerName keeps sanitized names up to 64 characters. For longer names, it uses t3-code- plus the first 16 hexadecimal characters of the thread ID’s SHA-256 digest.
      MCP registration replay and name tests
      apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts
      Tests check registration before the prompt and removal when a long-ID thread unloads. They also check the generated name pattern, uniqueness, stability, and preservation of an existing short name.

      Priority: ➖ Normal

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Bug fix · Severity of issue fixed: Medium

      Suggested reviewers: juliusmarminge

      Merge Risk: ⚪ Minimal · up to 32670

      No actionable merge-blocking issue is identified for the OpenCode 2 MCP naming change. It is mergeable after normal checks.

      Architecture Summary

      Architecture risk: 🔵 Low · up to 32670

      The change affects 1 system.

      Changed systems: apps/server

      Architecture concerns No architecture-level concerns identified.

      Review details

      Systems and components

      • observed — apps/server (service) was modified; 2 changed files map to changed impact.

      Before / after behavior

      • observed — Modified behavior in apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts: The test now imports t3McpServerName from OpenCode2AdapterV2.ts alongside OPENCODE_2_STILL_STOPPING.
      • observed — Modified behavior in apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts: Adds a replay test for resuming a long-ID thread with its MCP session registered under t3-code-aa73fa1e03099934; it verifies the server is added before the prompt, removed when the thread unloads, and the turn completes.
      • observed — Modified behavior in apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts: Adds assertions that names generated for several thread IDs fit t3-code-[A-Za-z0-9_-]{1,56}, are unique, and stable across calls, while the existing short thread ID remains readable.
      • observed — Modified behavior in apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.ts: The file adds the Node crypto import used to digest long MCP server names.
      🚥 Pre-merge checks | ✅ 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Linked Issues check✅ PassedIssue [#16140] requires OpenCode 2 project threads and delegated children to access T3 MCP tools. The adapter keeps sanitized names at 64 characters or fewer and uses a deterministic 16-hex SHA-256 su…
      Out of Scope Changes check✅ PassedThe production change only shortens OpenCode 2 MCP server names. The added tests cover the naming behavior and its use during registration and removal. No unrelated changes appear in the pull request …
      Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
      Title check✅ PassedThe title clearly states the main change: OpenCode 2 threads can access T3 Code's MCP tools.
      Description check✅ PassedThe description covers the problem, change, scope and approval rationale, and detailed verification. It also identifies limitations and untested cases.
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Comment `@coderabbitai help` to get the list of available commands.

Sign in to join this conversation.