MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / toggleServerDisabled

Method toggleServerDisabled

src/services/mcp/McpHub.ts:1892–1948  ·  view source on GitHub ↗
(
		serverName: string,
		disabled: boolean,
		source?: "global" | "project",
	)

Source from the content-addressed store, hash-verified

1890 }
1891
1892 public async toggleServerDisabled(
1893 serverName: string,
1894 disabled: boolean,
1895 source?: "global" | "project",
1896 ): Promise<void> {
1897 try {
1898 // Find the connection to determine if it's a global or project server
1899 const connection = this.findConnection(serverName, source)
1900 if (!connection) {
1901 throw new Error(`Server ${serverName}${source ? ` with source ${source}` : ""} not found`)
1902 }
1903
1904 const serverSource = connection.server.source || "global"
1905 // Update the server config in the appropriate file
1906 await this.updateServerConfig(serverName, { disabled }, serverSource)
1907
1908 // Update the connection object
1909 if (connection) {
1910 try {
1911 connection.server.disabled = disabled
1912
1913 // If disabling a connected server, disconnect it
1914 if (disabled && connection.server.status === "connected") {
1915 // Clean up file watchers when disabling
1916 this.removeFileWatchersForServer(serverName)
1917 await this.deleteConnection(serverName, serverSource)
1918 // Re-add as a disabled connection
1919 // Re-read config from file to get updated disabled state
1920 const updatedConfig = await this.readServerConfigFromFile(serverName, serverSource)
1921 await this.connectToServer(serverName, updatedConfig, serverSource)
1922 } else if (!disabled && connection.server.status === "disconnected") {
1923 // If enabling a disabled server, connect it
1924 // Re-read config from file to get updated disabled state
1925 const updatedConfig = await this.readServerConfigFromFile(serverName, serverSource)
1926 await this.deleteConnection(serverName, serverSource)
1927 // When re-enabling, file watchers will be set up in connectToServer
1928 await this.connectToServer(serverName, updatedConfig, serverSource)
1929 } else if (connection.server.status === "connected") {
1930 // Only refresh capabilities if connected
1931 connection.server.tools = await this.fetchToolsList(serverName, serverSource)
1932 connection.server.resources = await this.fetchResourcesList(serverName, serverSource)
1933 connection.server.resourceTemplates = await this.fetchResourceTemplatesList(
1934 serverName,
1935 serverSource,
1936 )
1937 }
1938 } catch (error) {
1939 console.error(`Failed to refresh capabilities for ${serverName}:`, error)
1940 }
1941 }
1942
1943 await this.notifyWebviewOfServerChanges()
1944 } catch (error) {
1945 this.showErrorMessage(`Failed to update server ${serverName} state`, error)
1946 throw error
1947 }
1948 }
1949

Callers 2

webviewMessageHandlerFunction · 0.80
McpHub.spec.tsFile · 0.80

Calls 12

findConnectionMethod · 0.95
updateServerConfigMethod · 0.95
deleteConnectionMethod · 0.95
connectToServerMethod · 0.95
fetchToolsListMethod · 0.95
fetchResourcesListMethod · 0.95
showErrorMessageMethod · 0.95
errorMethod · 0.65

Tested by

no test coverage detected