@@ -25,8 +25,13 @@ interface IServerCacheEntry {
25
25
26
26
const _mcpExtensionPoint = extensionsRegistry . ExtensionsRegistry . registerExtensionPoint ( mcpContributionPoint ) ;
27
27
28
+ const enum PersistWhen {
29
+ CollectionExists ,
30
+ Always ,
31
+ }
32
+
28
33
export class ExtensionMcpDiscovery extends Disposable implements IMcpDiscovery {
29
- private readonly _extensionCollectionIdsToPersist = new Set < string > ( ) ;
34
+ private readonly _extensionCollectionIdsToPersist = new Map < string , PersistWhen > ( ) ;
30
35
private readonly cachedServers : { [ collcetionId : string ] : IServerCacheEntry } ;
31
36
32
37
constructor (
@@ -39,13 +44,17 @@ export class ExtensionMcpDiscovery extends Disposable implements IMcpDiscovery {
39
44
40
45
this . _register ( storageService . onWillSaveState ( ( ) => {
41
46
let updated = false ;
42
- for ( const collectionId of this . _extensionCollectionIdsToPersist ) {
47
+ for ( const [ collectionId , behavior ] of this . _extensionCollectionIdsToPersist . entries ( ) ) {
43
48
const collection = this . _mcpRegistry . collections . get ( ) . find ( c => c . id === collectionId ) ;
49
+ let defs = collection ?. serverDefinitions . get ( ) ;
44
50
if ( ! collection || collection . lazy ) {
45
- continue ;
51
+ if ( behavior === PersistWhen . Always ) {
52
+ defs = [ ] ;
53
+ } else {
54
+ continue ;
55
+ }
46
56
}
47
57
48
- const defs = collection . serverDefinitions . get ( ) ;
49
58
if ( defs ) {
50
59
updated = true ;
51
60
this . cachedServers [ collectionId ] = { servers : defs . map ( McpServerDefinition . toSerialized ) } ;
@@ -77,7 +86,7 @@ export class ExtensionMcpDiscovery extends Disposable implements IMcpDiscovery {
77
86
78
87
for ( const coll of collections . value ) {
79
88
const id = extensionPrefixedIdentifier ( collections . description . identifier , coll . id ) ;
80
- this . _extensionCollectionIdsToPersist . add ( id ) ;
89
+ this . _extensionCollectionIdsToPersist . set ( id , PersistWhen . CollectionExists ) ;
81
90
82
91
const serverDefs = this . cachedServers . hasOwnProperty ( id ) ? this . cachedServers [ id ] . servers : undefined ;
83
92
const dispo = this . _mcpRegistry . registerCollection ( {
@@ -90,7 +99,10 @@ export class ExtensionMcpDiscovery extends Disposable implements IMcpDiscovery {
90
99
serverDefinitions : observableValue < McpServerDefinition [ ] > ( this , serverDefs ?. map ( McpServerDefinition . fromSerialized ) || [ ] ) ,
91
100
lazy : {
92
101
isCached : ! ! serverDefs ,
93
- load : ( ) => this . _activateExtensionServers ( coll . id ) ,
102
+ load : ( ) => this . _activateExtensionServers ( coll . id ) . then ( ( ) => {
103
+ // persist (an empty collection) in case the extension doesn't end up publishing one
104
+ this . _extensionCollectionIdsToPersist . set ( id , PersistWhen . Always ) ;
105
+ } ) ,
94
106
removed : ( ) => extensionCollections . deleteAndDispose ( id ) ,
95
107
} ,
96
108
source : collections . description . identifier
0 commit comments