Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4dce299
feat: add toggle functionality for enabling/disabling all global MCP …
seedlord May 20, 2025
6a015ab
Merge branch 'RooVetGit:main' into feat/3676-mcp-reload-on-enable
seedlord May 20, 2025
74384e2
Update src/services/mcp/McpHub.ts
seedlord May 20, 2025
783cbc6
Update McpHub.test.ts
seedlord May 20, 2025
ac26ff6
revert mcp changes
seedlord May 21, 2025
03d96ab
Merge branch 'main' into feat/3676-mcp-reload-on-enable
seedlord May 21, 2025
a7a96fb
Add commands to reload and toggle MCP servers; update UI and localiza…
seedlord May 21, 2025
e8f99e2
Add tests for toggleAllServersDisabled and restartAllMcpServers metho…
seedlord May 21, 2025
7d5dd40
Merge branch 'main' into feat/3676-mcp-reload
seedlord May 21, 2025
cc278a6
Add new commands for reloading and toggling MCP server states
seedlord May 21, 2025
0123cad
Merge branch 'RooCodeInc:main' into feat/3676-mcp-reload-on-enable
seedlord May 22, 2025
8856dab
refactor: update command identifiers to include extension prefix
seedlord May 22, 2025
8d937c3
refactor: optimize server configuration updates using Promise.all
seedlord May 22, 2025
fe0a70e
revert Promise.all for toggleAllServerDisabled
seedlord May 22, 2025
999d27b
fixed Merge branch 'main' of https://github.com/RooVetGit/Roo-Code in…
seedlord May 22, 2025
442ad40
Merge branch 'main' of https://github.com/RooVetGit/Roo-Code into fea…
seedlord May 22, 2025
fe34086
Merge branch 'feat/3676-mcp-reload-on-enable' of https://github.com/s…
seedlord May 22, 2025
f0596ac
revert eslint changes
seedlord May 22, 2025
77e9ae1
Merge branch 'feat/3676-mcp-reload-on-enable' of https://github.com/s…
seedlord May 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 41 additions & 6 deletions src/services/mcp/McpHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -941,20 +941,26 @@ export class McpHub {

// Update the connection object
if (connection) {
try {
connection.server.disabled = disabled
const wasDisabled = connection.server.disabled
connection.server.disabled = disabled

// When the server is activated, reload the configuration
if (wasDisabled && !disabled) {
await this.initializeMcpServers(serverSource)
}

// Only refresh capabilities if connected
if (connection.server.status === "connected") {
// Only refresh capabilities if connected
if (connection.server.status === "connected") {
try {
connection.server.tools = await this.fetchToolsList(serverName, serverSource)
connection.server.resources = await this.fetchResourcesList(serverName, serverSource)
connection.server.resourceTemplates = await this.fetchResourceTemplatesList(
serverName,
serverSource,
)
} catch (error) {
console.error(`Failed to refresh capabilities for ${serverName}:`, error)
}
} catch (error) {
console.error(`Failed to refresh capabilities for ${serverName}:`, error)
}
}

Expand Down Expand Up @@ -1287,4 +1293,33 @@ export class McpHub {
}
this.disposables.forEach((d) => d.dispose())
}

/**
* Enables or disables all global MCP servers at once.
* When activated, the configuration is reloaded.
* @param disabled true = disable all, false = enable all
*/
public async toggleAllServersDisabled(disabled: boolean): Promise<void> {
// Collect all global server names
const globalConnections = this.connections.filter(
(conn) => conn.server.source === "global" || !conn.server.source,
)
const serverNames = globalConnections.map((conn) => conn.server.name)

// Set the Disabled flag for all serversv
for (const name of serverNames) {
await this.updateServerConfig(name, { disabled }, "global")
const conn = this.findConnection(name, "global")
if (conn) {
conn.server.disabled = disabled
}
}

// If activated, reload configuration
if (!disabled) {
await this.initializeMcpServers("global")
}

await this.notifyWebviewOfServerChanges()
}
}
72 changes: 72 additions & 0 deletions src/services/mcp/__tests__/McpHub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,5 +560,77 @@ describe("McpHub", () => {
)
})
})
describe("toggleServerDisabled (Configuration reload)", () => {
it("should reload configuration when enabling a server (calls initializeMcpServers)", async () => {
const mockConfig: any = {
mcpServers: {
"test-server": {
type: "stdio",
command: "node",
args: ["test.js"],
disabled: true,
},
},
}

;(fs.readFile as jest.Mock).mockResolvedValueOnce(JSON.stringify(mockConfig))

mcpHub.connections = [
{
server: {
name: "test-server",
config: JSON.stringify(mockConfig.mcpServers["test-server"]),
status: "connected",
disabled: true,
},
client: { request: jest.fn() },
transport: { close: jest.fn() },
} as any,
]

const spy = jest.spyOn(mcpHub as any, "initializeMcpServers").mockResolvedValue(undefined)

await mcpHub.toggleServerDisabled("test-server", false)
// Expectation: initializeMcpServers was called
expect(spy).toHaveBeenCalledWith("global")
spy.mockRestore()
})
})
describe("toggleAllServersDisabled (global enable/disable)", () => {
it("should reload configuration when globally enabling all servers (calls initializeMcpServers)", async () => {
// Two global servers, both disabled
mcpHub.connections = [
{
server: {
name: "server1",
config: JSON.stringify({ type: "stdio", command: "node", args: ["a.js"], disabled: true }),
status: "disconnected",
disabled: true,
source: "global",
},
client: { request: jest.fn() },
transport: { close: jest.fn() },
} as any,
{
server: {
name: "server2",
config: JSON.stringify({ type: "stdio", command: "node", args: ["b.js"], disabled: true }),
status: "disconnected",
disabled: true,
source: "global",
},
client: { request: jest.fn() },
transport: { close: jest.fn() },
} as any,
]

const spy = jest.spyOn(mcpHub as any, "initializeMcpServers").mockResolvedValue(undefined)

await mcpHub.toggleAllServersDisabled(false) // actiate global

expect(spy).toHaveBeenCalledWith("global")
spy.mockRestore()
})
})
})
})