filter mcp marketplace results based on remote config (#7277)
This commit is contained in:
1 parent
8215d3fdb9
commit
64dcc3fc89
4 files changed
+37
-19
No files matched your search
@@ -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
|
||||
|
||||
@@ -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<Settings> = {}
|
||||
private remoteConfigCache: Partial<GlobalStateAndSettings> & { remoteConfiguredProviders?: string[] } = {}
|
||||
private remoteConfigCache: Partial<RemoteConfigFields> = {} 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<K extends keyof GlobalStateAndSettings>(key: K, value: GlobalStateAndSettings[K]): void {
|
||||
setRemoteConfigField<K extends keyof RemoteConfigFields>(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<GlobalStateAndSettings> & { remoteConfiguredProviders?: string[] } {
|
||||
getRemoteConfigSettings(): Partial<RemoteConfigFields> {
|
||||
if (!this.isInitialized) {
|
||||
throw new Error(STATE_MANAGER_NOT_INITIALIZED)
|
||||
}
|
||||
|
||||
@@ -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<GlobalStateAndSettings> containing only the fields present in remote config, plus availableProviders
|
||||
* @returns Partial<RemoteConfigFields> containing only the fields present in remote config
|
||||
*/
|
||||
export function transformRemoteConfigToStateShape(
|
||||
remoteConfig: RemoteConfig,
|
||||
): Partial<GlobalStateAndSettings> & { remoteConfiguredProviders?: string[] } {
|
||||
const transformed: Partial<GlobalStateAndSettings> & { remoteConfiguredProviders?: string[] } = {}
|
||||
export function transformRemoteConfigToStateShape(remoteConfig: RemoteConfig): Partial<RemoteConfigFields> {
|
||||
const transformed: Partial<RemoteConfigFields> = {}
|
||||
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
@@ -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[]
|
||||
|
||||
Reference in new issue
Block a user