migrateEnableAllProjectMcpServersToSettings.ts
migrations/migrateEnableAllProjectMcpServersToSettings.ts
119
Lines
3977
Bytes
1
Exports
4
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with mcp. It contains 119 lines, 4 detected imports, and 1 detected exports.
Important relationships
- migrations/migrateAutoUpdatesToSettings.ts
- migrations/migrateBypassPermissionsAcceptedToSettings.ts
- migrations/migrateFennecToOpus.ts
- migrations/migrateLegacyOpusToCurrent.ts
- migrations/migrateOpusToOpus1m.ts
- migrations/migrateReplBridgeEnabledToRemoteControlAtStartup.ts
- migrations/migrateSonnet1mToSonnet45.ts
- migrations/migrateSonnet45ToSonnet46.ts
Detected exports
migrateEnableAllProjectMcpServersToSettings
Keywords
enabledmcpjsonserversenableallprojectmcpserversdisabledmcpjsonserversprojectconfigfieldstoremoveupdatessettingsconfigexistshasenableall
Detected imports
src/services/analytics/index.js../utils/config.js../utils/log.js../utils/settings/settings.js
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
import { logEvent } from 'src/services/analytics/index.js'
import {
getCurrentProjectConfig,
saveCurrentProjectConfig,
} from '../utils/config.js'
import { logError } from '../utils/log.js'
import {
getSettingsForSource,
updateSettingsForSource,
} from '../utils/settings/settings.js'
/**
* Migration: Move MCP server approval fields from project config to local settings
* This migrates both enableAllProjectMcpServers and enabledMcpjsonServers to the
* settings system for better management and consistency.
*/
export function migrateEnableAllProjectMcpServersToSettings(): void {
const projectConfig = getCurrentProjectConfig()
// Check if any field exists in project config
const hasEnableAll = projectConfig.enableAllProjectMcpServers !== undefined
const hasEnabledServers =
projectConfig.enabledMcpjsonServers &&
projectConfig.enabledMcpjsonServers.length > 0
const hasDisabledServers =
projectConfig.disabledMcpjsonServers &&
projectConfig.disabledMcpjsonServers.length > 0
if (!hasEnableAll && !hasEnabledServers && !hasDisabledServers) {
return
}
try {
const existingSettings = getSettingsForSource('localSettings') || {}
const updates: Partial<{
enableAllProjectMcpServers: boolean
enabledMcpjsonServers: string[]
disabledMcpjsonServers: string[]
}> = {}
const fieldsToRemove: Array<
| 'enableAllProjectMcpServers'
| 'enabledMcpjsonServers'
| 'disabledMcpjsonServers'
> = []
// Migrate enableAllProjectMcpServers if it exists and hasn't been migrated
if (
hasEnableAll &&
existingSettings.enableAllProjectMcpServers === undefined
) {
updates.enableAllProjectMcpServers =
projectConfig.enableAllProjectMcpServers
fieldsToRemove.push('enableAllProjectMcpServers')
} else if (hasEnableAll) {
// Already migrated, just mark for removal
fieldsToRemove.push('enableAllProjectMcpServers')
}
// Migrate enabledMcpjsonServers if it exists
if (hasEnabledServers && projectConfig.enabledMcpjsonServers) {
const existingEnabledServers =
existingSettings.enabledMcpjsonServers || []
// Merge the servers (avoiding duplicates)
updates.enabledMcpjsonServers = [
...new Set([
...existingEnabledServers,
...projectConfig.enabledMcpjsonServers,
]),
]
fieldsToRemove.push('enabledMcpjsonServers')
}
// Migrate disabledMcpjsonServers if it exists
if (hasDisabledServers && projectConfig.disabledMcpjsonServers) {
const existingDisabledServers =
existingSettings.disabledMcpjsonServers || []
// Merge the servers (avoiding duplicates)
updates.disabledMcpjsonServers = [
...new Set([
...existingDisabledServers,
...projectConfig.disabledMcpjsonServers,
]),
]
fieldsToRemove.push('disabledMcpjsonServers')
}
// Update settings if there are any updates
if (Object.keys(updates).length > 0) {
updateSettingsForSource('localSettings', updates)
}
// Remove migrated fields from project config
if (
fieldsToRemove.includes('enableAllProjectMcpServers') ||
fieldsToRemove.includes('enabledMcpjsonServers') ||
fieldsToRemove.includes('disabledMcpjsonServers')
) {
saveCurrentProjectConfig(current => {
const {
enableAllProjectMcpServers: _enableAll,
enabledMcpjsonServers: _enabledServers,
disabledMcpjsonServers: _disabledServers,
...configWithoutFields
} = current
return configWithoutFields
})
}
// Log the migration event
logEvent('tengu_migrate_mcp_approval_fields_success', {
migratedCount: fieldsToRemove.length,
})
} catch (e: unknown) {
// Log migration failure but don't throw to avoid breaking startup
logError(e)
logEvent('tengu_migrate_mcp_approval_fields_error', {})
}
}