Skip to content

Commit 41fade7

Browse files
committed
fix: refresh mcp server functionality
1 parent 3345baa commit 41fade7

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ export class AgenticChatController implements ChatHandlers {
414414
list: groups,
415415
}
416416
}
417+
417418
async onMcpServerClick(params: McpServerClickParams) {
418419
return {
419420
id: params.id,

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/mcp/mcpManager.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,3 +556,49 @@ describe('close()', () => {
556556
expect(() => McpManager.instance).to.throw()
557557
})
558558
})
559+
560+
// reinitializeMcpServers()
561+
describe('reinitializeMcpServers()', () => {
562+
let loadStub: sinon.SinonStub
563+
564+
beforeEach(() => {
565+
loadStub = sinon.stub(mcpUtils, 'loadMcpServerConfigs')
566+
})
567+
568+
afterEach(async () => {
569+
sinon.restore()
570+
try {
571+
await McpManager.instance.close()
572+
} catch {}
573+
})
574+
575+
it('calls necessary methods during reinitialization', async () => {
576+
const cfg: MCPServerConfig = {
577+
command: 'cmd',
578+
args: [],
579+
env: {},
580+
disabled: false,
581+
autoApprove: false,
582+
toolOverrides: {},
583+
__configPath__: 'cfg.json',
584+
}
585+
loadStub.resolves(new Map([['srv', cfg]]))
586+
587+
const mgr = await McpManager.init(['cfg.json'], features)
588+
589+
const closeStub = sinon.stub(mgr, 'close').resolves()
590+
const initStub = sinon.stub(McpManager, 'init').resolves(mgr)
591+
592+
loadStub.resetHistory()
593+
594+
await mgr.reinitializeMcpServers()
595+
596+
expect(closeStub.calledOnce).to.be.true
597+
expect(initStub.calledOnce).to.be.true
598+
expect(initStub.firstCall.args[0]).to.deep.equal(['cfg.json'])
599+
expect(initStub.firstCall.args[1]).to.equal(features)
600+
601+
closeStub.restore()
602+
initStub.restore()
603+
})
604+
})

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/mcp/mcpManager.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,24 @@ export class McpManager {
412412
McpManager.#instance = undefined
413413
}
414414

415+
/**
416+
* Reinitialize all MCP servers by closing existing connections and rediscovering servers
417+
*/
418+
public async reinitializeMcpServers(): Promise<void> {
419+
this.features.logging.info('Reinitializing MCP servers')
420+
421+
try {
422+
await this.close()
423+
await McpManager.init(this.configPaths, this.features)
424+
425+
const reinitializedServerCount = McpManager.#instance?.mcpServers.size
426+
this.features.logging.info(`MCP servers reinitialized completed with length of ${reinitializedServerCount}`)
427+
} catch (err: any) {
428+
this.features.logging.error(`Error reinitializing MCP servers: ${err.message}`)
429+
throw err
430+
}
431+
}
432+
415433
/**
416434
* Check if a tool requires approval.
417435
*/

0 commit comments

Comments
 (0)