1- import { createRoot , getOwner , onCleanup , runWithOwner , type Owner } from "solid-js"
1+ import { createRoot , createSignal , getOwner , onCleanup , runWithOwner , type Owner } from "solid-js"
22import { createStore , type SetStoreFunction , type Store } from "solid-js/store"
33import { Persist , persisted } from "@/utils/persist"
44import type { VcsInfo } from "@opencode-ai/sdk/v2/client"
@@ -24,6 +24,7 @@ export function createChildStoreManager(input: {
2424 isBooting : ( directory : string ) => boolean
2525 isLoadingSessions : ( directory : string ) => boolean
2626 onBootstrap : ( directory : string ) => void
27+ onMcp : ( directory : string , setStore : SetStoreFunction < State > ) => void
2728 onDispose : ( directory : string ) => void
2829 translate : ( key : string , vars ?: Record < string , string | number > ) => string
2930 queryOptions : QueryOptionsApi
@@ -39,6 +40,8 @@ export function createChildStoreManager(input: {
3940 const pins = new Map < string , number > ( )
4041 const ownerPins = new WeakMap < object , Set < string > > ( )
4142 const disposers = new Map < string , ( ) => void > ( )
43+ const mcpDirectories = new Set < string > ( )
44+ const mcpToggles = new Map < string , ( enabled : boolean ) => void > ( )
4245
4346 const markKey = ( key : DirectoryKey ) => {
4447 if ( ! key ) return
@@ -99,6 +102,8 @@ export function createChildStoreManager(input: {
99102 metaCache . delete ( key )
100103 iconCache . delete ( key )
101104 lifecycle . delete ( key )
105+ mcpDirectories . delete ( key )
106+ mcpToggles . delete ( key )
102107 disposers . delete ( key )
103108 delete children [ key ]
104109 input . onDispose ( key )
@@ -184,11 +189,12 @@ export function createChildStoreManager(input: {
184189 createRoot ( ( dispose ) => {
185190 const initialMeta = meta [ 0 ] . value
186191 const initialIcon = icon [ 0 ] . value
192+ const [ mcpEnabled , setMcpEnabled ] = createSignal ( false )
187193
188194 const [ pathQuery , mcpQuery , lspQuery , providerQuery ] = useQueries ( ( ) => ( {
189195 queries : [
190196 input . queryOptions . path ( key ) ,
191- input . queryOptions . mcp ( key ) ,
197+ { ... input . queryOptions . mcp ( key ) , enabled : mcpEnabled } ,
192198 input . queryOptions . lsp ( key ) ,
193199 input . queryOptions . providers ( key ) ,
194200 ] ,
@@ -247,6 +253,7 @@ export function createChildStoreManager(input: {
247253 } )
248254 children [ key ] = child
249255 disposers . set ( key , dispose )
256+ mcpToggles . set ( key , setMcpEnabled )
250257
251258 const onPersistedInit = ( init : Promise < string > | string | null , run : ( ) => void ) => {
252259 if ( ! ( init instanceof Promise ) ) return
@@ -285,6 +292,7 @@ export function createChildStoreManager(input: {
285292 const key = directoryKey ( directory )
286293 const childStore = ensureChild ( directory )
287294 pinForOwner ( key )
295+ if ( options . mcp ) enableMcp ( directory , key , childStore )
288296 const shouldBootstrap = options . bootstrap ?? true
289297 if ( shouldBootstrap && childStore [ 0 ] . status === "loading" ) {
290298 input . onBootstrap ( directory )
@@ -295,13 +303,27 @@ export function createChildStoreManager(input: {
295303 function peek ( directory : string , options : ChildOptions = { } ) {
296304 const key = directoryKey ( directory )
297305 const childStore = ensureChild ( directory )
306+ if ( options . mcp ) enableMcp ( directory , key , childStore )
298307 const shouldBootstrap = options . bootstrap ?? true
299308 if ( shouldBootstrap && childStore [ 0 ] . status === "loading" ) {
300309 input . onBootstrap ( directory )
301310 }
302311 return childStore
303312 }
304313
314+ function enableMcp ( directory : string , key : DirectoryKey , childStore : [ Store < State > , SetStoreFunction < State > ] ) {
315+ if ( mcpDirectories . has ( key ) ) return
316+ mcpDirectories . add ( key )
317+ mcpToggles . get ( key ) ?.( true )
318+ if ( childStore [ 0 ] . status !== "loading" ) input . onMcp ( directory , childStore [ 1 ] )
319+ }
320+
321+ function disableMcp ( directory : string ) {
322+ const key = directoryKey ( directory )
323+ if ( ! mcpDirectories . delete ( key ) ) return
324+ mcpToggles . get ( key ) ?.( false )
325+ }
326+
305327 function projectMeta ( directory : string , patch : ProjectMeta ) {
306328 const key = directoryKey ( directory )
307329 const [ store , setStore ] = ensureChild ( directory )
@@ -341,6 +363,8 @@ export function createChildStoreManager(input: {
341363 pin,
342364 unpin,
343365 pinned,
366+ mcp : ( directory : string ) => mcpDirectories . has ( directoryKey ( directory ) ) ,
367+ disableMcp,
344368 disposeDirectory,
345369 disposeAll,
346370 runEviction,
0 commit comments