From 64dcc3fc89ec1b0cd330f5c4aa141e5c39c5d76a Mon Sep 17 00:00:00 2001 From: celestial-vault <58194240+celestial-vault@users.noreply.github.com> Date: Tue, 4 Nov 2025 13:50:50 -0800 Subject: [PATCH] filter mcp marketplace results based on remote config (#7277) --- src/core/controller/index.ts | 25 +++++++++++++++++-------- src/core/storage/StateManager.ts | 7 ++++--- src/core/storage/remote-config/utils.ts | 17 +++++++++-------- src/shared/storage/state-keys.ts | 7 +++++++ 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/core/controller/index.ts b/src/core/controller/index.ts index d2ab237e..5ef2af17 100644 --- a/src/core/controller/index.ts +++ b/src/core/controller/index.ts @@ -12,7 +12,7 @@ import { ApiProvider, ModelInfo } from "@shared/api" import { ChatContent } from "@shared/ChatContent" import { ExtensionState, Platform } from "@shared/ExtensionMessage" import { HistoryItem } from "@shared/HistoryItem" -import { McpMarketplaceCatalog } from "@shared/mcp" +import { McpMarketplaceCatalog, McpMarketplaceItem } from "@shared/mcp" import { Settings } from "@shared/storage/state-keys" import { Mode } from "@shared/storage/types" import { TelemetrySetting } from "@shared/TelemetrySetting" @@ -657,15 +657,24 @@ export class Controller { throw new Error("Invalid response from MCP marketplace API") } - const catalog: McpMarketplaceCatalog = { - items: (response.data || []).map((item: any) => ({ - ...item, - githubStars: item.githubStars ?? 0, - downloadCount: item.downloadCount ?? 0, - tags: item.tags ?? [], - })), + // Get allowlist from remote config + const allowedMCPServers = this.stateManager.getRemoteConfigSettings().allowedMCPServers + + let items: McpMarketplaceItem[] = (response.data || []).map((item: McpMarketplaceItem) => ({ + ...item, + githubStars: item.githubStars ?? 0, + downloadCount: item.downloadCount ?? 0, + tags: item.tags ?? [], + })) + + // Filter by allowlist if configured + if (allowedMCPServers) { + const allowedIds = new Set(allowedMCPServers.map((server) => server.id)) + items = items.filter((item: McpMarketplaceItem) => allowedIds.has(item.mcpId)) } + const catalog: McpMarketplaceCatalog = { items } + // Store in cache file await writeMcpMarketplaceCatalogToCache(catalog) return catalog diff --git a/src/core/storage/StateManager.ts b/src/core/storage/StateManager.ts index 5cf9beca..c775db0b 100644 --- a/src/core/storage/StateManager.ts +++ b/src/core/storage/StateManager.ts @@ -6,6 +6,7 @@ import { GlobalStateKey, LocalState, LocalStateKey, + RemoteConfigFields, SecretKey, Secrets, Settings, @@ -37,7 +38,7 @@ export class StateManager { private globalStateCache: GlobalStateAndSettings = {} as GlobalStateAndSettings private taskStateCache: Partial = {} - private remoteConfigCache: Partial & { remoteConfiguredProviders?: string[] } = {} + private remoteConfigCache: Partial = {} as RemoteConfigFields private secretsCache: Secrets = {} as Secrets private workspaceStateCache: LocalState = {} as LocalState private context: ExtensionContext @@ -314,7 +315,7 @@ export class StateManager { * Set method for remote config field - updates cache immediately (no persistence) * Remote config is read-only from the extension's perspective and only stored in memory */ - setRemoteConfigField(key: K, value: GlobalStateAndSettings[K]): void { + setRemoteConfigField(key: K, value: RemoteConfigFields[K]): void { if (!this.isInitialized) { throw new Error(STATE_MANAGER_NOT_INITIALIZED) } @@ -327,7 +328,7 @@ export class StateManager { * Get method for remote config settings - returns cache immediately (no persistence) * Remote config is read-only from the extension's perspective and only stored in memory */ - getRemoteConfigSettings(): Partial & { remoteConfiguredProviders?: string[] } { + getRemoteConfigSettings(): Partial { if (!this.isInitialized) { throw new Error(STATE_MANAGER_NOT_INITIALIZED) } diff --git a/src/core/storage/remote-config/utils.ts b/src/core/storage/remote-config/utils.ts index 356d1b12..eaff5971 100644 --- a/src/core/storage/remote-config/utils.ts +++ b/src/core/storage/remote-config/utils.ts @@ -1,16 +1,14 @@ import { RemoteConfig } from "@shared/remote-config/schema" -import { GlobalStateAndSettings } from "@shared/storage/state-keys" +import { RemoteConfigFields } from "@shared/storage/state-keys" import { StateManager } from "../StateManager" /** - * Transforms RemoteConfig schema to GlobalStateAndSettings shape + * Transforms RemoteConfig schema to RemoteConfigFields shape * @param remoteConfig The remote configuration object - * @returns Partial containing only the fields present in remote config, plus availableProviders + * @returns Partial containing only the fields present in remote config */ -export function transformRemoteConfigToStateShape( - remoteConfig: RemoteConfig, -): Partial & { remoteConfiguredProviders?: string[] } { - const transformed: Partial & { remoteConfiguredProviders?: string[] } = {} +export function transformRemoteConfigToStateShape(remoteConfig: RemoteConfig): Partial { + const transformed: Partial = {} // Map top-level settings if (remoteConfig.telemetryEnabled !== undefined) { @@ -19,6 +17,9 @@ export function transformRemoteConfigToStateShape( if (remoteConfig.mcpMarketplaceEnabled !== undefined) { transformed.mcpMarketplaceEnabled = remoteConfig.mcpMarketplaceEnabled } + if (remoteConfig.allowedMCPServers !== undefined) { + transformed.allowedMCPServers = remoteConfig.allowedMCPServers + } if (remoteConfig.yoloModeAllowed !== undefined) { // only set the yoloModeToggled field if yolo mode is not allowed. Otherwise, we let the user toggle it. if (remoteConfig.yoloModeAllowed === false) { @@ -152,6 +153,6 @@ export function applyRemoteConfig(remoteConfig?: RemoteConfig): void { // Populate remote config cache with transformed values for (const [key, value] of Object.entries(transformed)) { - stateManager.setRemoteConfigField(key as keyof GlobalStateAndSettings, value) + stateManager.setRemoteConfigField(key as keyof RemoteConfigFields, value) } } diff --git a/src/shared/storage/state-keys.ts b/src/shared/storage/state-keys.ts index 9e4617c6..ced9dc9d 100644 --- a/src/shared/storage/state-keys.ts +++ b/src/shared/storage/state-keys.ts @@ -23,6 +23,13 @@ export type GlobalStateAndSettingsKey = keyof (GlobalState & Settings) export type GlobalStateAndSettings = GlobalState & Settings +export interface RemoteConfigExtraFields { + remoteConfiguredProviders: string[] + allowedMCPServers: Array<{ id: string }> +} + +export type RemoteConfigFields = GlobalStateAndSettings & RemoteConfigExtraFields + export interface GlobalState { lastShownAnnouncementId: string | undefined taskHistory: HistoryItem[]