@@ -35,6 +35,7 @@ import { describe } from "vite-plus/test";
3535
3636import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter" ;
3737import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions" ;
38+ import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions" ;
3839import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator" ;
3940import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests" ;
4041import {
@@ -3243,9 +3244,10 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
32433244 } ) . pipe ( Effect . scoped ) ,
32443245 ) ;
32453246
3246- it . effect ( "adds T3's MCP server again on every turn, in case OpenCode dropped it " , ( ) =>
3247+ it . effect ( "re-registers T3 MCP each turn and drops its instructions when adding fails " , ( ) =>
32473248 Effect . gen ( function * ( ) {
3248- McpProviderSession . setMcpProviderSession ( {
3249+ const mcpSessions = yield * McpProviderSessions . McpProviderSessions ;
3250+ yield * mcpSessions . set ( {
32493251 environmentId : EnvironmentId . make ( "environment:opencode2-adapter" ) ,
32503252 threadId,
32513253 providerSessionId : "mcp:opencode2-adapter" ,
@@ -3254,36 +3256,37 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
32543256 authorizationHeader : "Bearer thread-credential" ,
32553257 browserToolsAvailable : false ,
32563258 } ) ;
3257- yield * Effect . addFinalizer ( ( ) =>
3258- Effect . sync ( ( ) => McpProviderSession . clearMcpProviderSession ( threadId ) ) ,
3259- ) ;
3259+ yield * Effect . addFinalizer ( ( ) => mcpSessions . clear ( threadId ) ) ;
32603260 const server = "t3-code-thread_opencode2-adapter" ;
3261- const add = [
3262- out ( "mcp.add" , {
3263- server,
3264- "location[directory]" : WORK ,
3265- config : {
3266- type : "remote" ,
3267- url : "http://127.0.0.1:3773/mcp" ,
3268- headers : { Authorization : "Bearer thread-credential" } ,
3269- oauth : false ,
3270- } ,
3271- } ) ,
3272- reply ( "mcp.add" , null ) ,
3273- ] ;
3261+ const add = out ( "mcp.add" , {
3262+ server,
3263+ "location[directory]" : WORK ,
3264+ config : {
3265+ type : "remote" ,
3266+ url : "http://127.0.0.1:3773/mcp" ,
3267+ headers : { Authorization : "Bearer thread-credential" } ,
3268+ oauth : false ,
3269+ } ,
3270+ } ) ;
32743271 const turn = [
32753272 out ( "session.prompt" , { sessionID : SESSION , text : "<any>" } ) ,
32763273 promptAccepted ,
32773274 event ( "session.execution.succeeded" , { sessionID : SESSION } ) ,
32783275 ] ;
3279- // OpenCode keeps runtime-added servers with the Location and forgets them
3280- // when it evicts an idle one, without a reconnect T3 could notice.
3276+ // Idle Location eviction drops OpenCode's runtime MCP servers without a reconnect.
32813277 const { runtime, thread } = yield * resumed ( [
3282- ...add ,
3278+ add ,
3279+ reply ( "mcp.add" , null ) ,
32833280 ...turn ,
3284- ...add ,
3281+ add ,
3282+ reply ( "mcp.add" , { status : 500 , body : { message : "MCP unavailable" } } ) ,
3283+ out ( "session.instructions.entry.put" , {
3284+ sessionID : SESSION ,
3285+ key : "t3-code" ,
3286+ value : buildRuntimeInstructions ( { harness : "OpenCode" , model : bigPickle . model } ) ,
3287+ } ) ,
3288+ reply ( "session.instructions.entry.put" , null ) ,
32853289 ...turn ,
3286- // Removed when the session closes.
32873290 out ( "mcp.remove" , { server, "location[directory]" : WORK } ) ,
32883291 reply ( "mcp.remove" , null ) ,
32893292 ] ) ;
0 commit comments