@@ -258,10 +258,13 @@ Run these research agents:
258258 const githubRoot = path . join ( tempRoot , ".github" )
259259 await fs . mkdir ( githubRoot , { recursive : true } )
260260
261- // User has their own MCP server (not managed by the plugin )
261+ // User has their own MCP server alongside plugin- managed ones (tracking key present )
262262 await fs . writeFile (
263263 path . join ( githubRoot , "copilot-mcp-config.json" ) ,
264- JSON . stringify ( { mcpServers : { "user-tool" : { type : "local" , command : "my-tool" , tools : [ "*" ] } } } ) ,
264+ JSON . stringify ( {
265+ mcpServers : { "user-tool" : { type : "local" , command : "my-tool" , tools : [ "*" ] } } ,
266+ _compound_managed_mcp : [ ] ,
267+ } ) ,
265268 )
266269
267270 const bundle : CopilotBundle = {
@@ -278,6 +281,38 @@ Run these research agents:
278281 expect ( result . mcpServers . plugin ) . toBeDefined ( )
279282 } )
280283
284+ test ( "prunes stale servers from legacy config without tracking key" , async ( ) => {
285+ const tempRoot = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "copilot-legacy-" ) )
286+ const githubRoot = path . join ( tempRoot , ".github" )
287+ await fs . mkdir ( githubRoot , { recursive : true } )
288+
289+ // Simulate old writer output: has mcpServers but no _compound_managed_mcp
290+ await fs . writeFile (
291+ path . join ( githubRoot , "copilot-mcp-config.json" ) ,
292+ JSON . stringify ( {
293+ mcpServers : {
294+ old : { type : "local" , command : "old-server" , tools : [ "*" ] } ,
295+ renamed : { type : "local" , command : "renamed-server" , tools : [ "*" ] } ,
296+ } ,
297+ } ) ,
298+ )
299+
300+ const bundle : CopilotBundle = {
301+ agents : [ ] ,
302+ generatedSkills : [ ] ,
303+ skillDirs : [ ] ,
304+ mcpConfig : { fresh : { type : "local" , command : "new-server" , tools : [ "*" ] } } ,
305+ }
306+
307+ await writeCopilotBundle ( githubRoot , bundle )
308+
309+ const result = JSON . parse ( await fs . readFile ( path . join ( githubRoot , "copilot-mcp-config.json" ) , "utf8" ) )
310+ expect ( result . mcpServers . fresh ) . toBeDefined ( )
311+ expect ( result . mcpServers . old ) . toBeUndefined ( )
312+ expect ( result . mcpServers . renamed ) . toBeUndefined ( )
313+ expect ( result . _compound_managed_mcp ) . toEqual ( [ "fresh" ] )
314+ } )
315+
281316 test ( "creates skill directories with SKILL.md" , async ( ) => {
282317 const tempRoot = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "copilot-genskill-" ) )
283318 const bundle : CopilotBundle = {
0 commit comments