Move MCP marketplace catalog from global state to disk cache (#5835)
* Move MCP marketplace catalog from global state to disk cache * add cleanup function to remove catalog from vs code storage * type fixes * move disk related functions to disk file * add try/catch around file/json operations * fix weird tab formatting
This commit is contained in:
1 parent
4469a4fea4
commit
8be46f9cfe
7 files changed
+57
-13
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import * as vscode from "vscode"
|
||||
import {
|
||||
cleanupMcpMarketplaceCatalogFromGlobalState,
|
||||
migrateCustomInstructionsToGlobalRules,
|
||||
migrateTaskHistoryToFile,
|
||||
migrateWelcomeViewCompleted,
|
||||
@@ -60,6 +61,9 @@ export async function initialize(context: vscode.ExtensionContext): Promise<Webv
|
||||
// Ensure taskHistory.json exists and migrate legacy state (runs once)
|
||||
await migrateTaskHistoryToFile(context)
|
||||
|
||||
// Clean up MCP marketplace catalog from global state (moved to disk cache)
|
||||
await cleanupMcpMarketplaceCatalogFromGlobalState(context)
|
||||
|
||||
// Clean up orphaned file context warnings (startup cleanup)
|
||||
await FileContextTracker.cleanupOrphanedWarnings(context)
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ import {
|
||||
ensureMcpServersDirectoryExists,
|
||||
ensureSettingsDirectoryExists,
|
||||
GlobalFileNames,
|
||||
writeMcpMarketplaceCatalogToCache,
|
||||
} from "../storage/disk"
|
||||
import { PersistenceErrorEvent, StateManager } from "../storage/StateManager"
|
||||
import { Settings } from "../storage/state-keys"
|
||||
@@ -496,8 +497,8 @@ export class Controller {
|
||||
})),
|
||||
}
|
||||
|
||||
// Store in global state
|
||||
this.stateManager.setGlobalState("mcpMarketplaceCatalog", catalog)
|
||||
// Store in cache file
|
||||
await writeMcpMarketplaceCatalogToCache(catalog)
|
||||
return catalog
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch MCP marketplace:", error)
|
||||
@@ -534,8 +535,8 @@ export class Controller {
|
||||
})),
|
||||
}
|
||||
|
||||
// Store in global state
|
||||
this.stateManager.setGlobalState("mcpMarketplaceCatalog", catalog)
|
||||
// Store in cache file
|
||||
await writeMcpMarketplaceCatalogToCache(catalog)
|
||||
return catalog
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch MCP marketplace:", error)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { McpMarketplaceCatalog } from "@shared/mcp"
|
||||
import { Empty, EmptyRequest } from "@shared/proto/cline/common"
|
||||
import { OpenRouterCompatibleModelInfo } from "@shared/proto/cline/models"
|
||||
import { readMcpMarketplaceCatalogFromCache } from "@/core/storage/disk"
|
||||
import { telemetryService } from "@/services/telemetry"
|
||||
import type { Controller } from "../index"
|
||||
import { sendMcpMarketplaceCatalogEvent } from "../mcp/subscribeToMcpMarketplaceCatalog"
|
||||
@@ -213,10 +213,10 @@ export async function initializeWebview(controller: Controller, _request: EmptyR
|
||||
// Prefetch marketplace and OpenRouter models
|
||||
|
||||
// Send stored MCP marketplace catalog if available
|
||||
const mcpMarketplaceCatalog = controller.stateManager.getGlobalStateKey("mcpMarketplaceCatalog")
|
||||
const mcpMarketplaceCatalog = await readMcpMarketplaceCatalogFromCache()
|
||||
|
||||
if (mcpMarketplaceCatalog) {
|
||||
sendMcpMarketplaceCatalogEvent(mcpMarketplaceCatalog as McpMarketplaceCatalog)
|
||||
sendMcpMarketplaceCatalogEvent(mcpMarketplaceCatalog)
|
||||
}
|
||||
|
||||
// Silently refresh MCP marketplace catalog
|
||||
|
||||
@@ -8,6 +8,7 @@ import fs from "fs/promises"
|
||||
import os from "os"
|
||||
import * as path from "path"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { McpMarketplaceCatalog } from "@/shared/mcp"
|
||||
import { GlobalState, Settings } from "./state-keys"
|
||||
|
||||
export const GlobalFileNames = {
|
||||
@@ -25,6 +26,7 @@ export const GlobalFileNames = {
|
||||
cursorRulesFile: ".cursorrules",
|
||||
windsurfRules: ".windsurfrules",
|
||||
taskMetadata: "task_metadata.json",
|
||||
mcpMarketplaceCatalog: "mcp_marketplace_catalog.json",
|
||||
}
|
||||
|
||||
export async function getDocumentsPath(): Promise<string> {
|
||||
@@ -179,6 +181,30 @@ export async function ensureCacheDirectoryExists(): Promise<string> {
|
||||
return getGlobalStorageDir("cache")
|
||||
}
|
||||
|
||||
export async function readMcpMarketplaceCatalogFromCache(): Promise<McpMarketplaceCatalog | undefined> {
|
||||
try {
|
||||
const mcpMarketplaceCatalogFilePath = path.join(await ensureCacheDirectoryExists(), GlobalFileNames.mcpMarketplaceCatalog)
|
||||
const fileExists = await fileExistsAtPath(mcpMarketplaceCatalogFilePath)
|
||||
if (fileExists) {
|
||||
const fileContents = await fs.readFile(mcpMarketplaceCatalogFilePath, "utf8")
|
||||
return JSON.parse(fileContents)
|
||||
}
|
||||
return undefined
|
||||
} catch (error) {
|
||||
console.error("Failed to read MCP marketplace catalog from cache:", error)
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
export async function writeMcpMarketplaceCatalogToCache(catalog: McpMarketplaceCatalog): Promise<void> {
|
||||
try {
|
||||
const mcpMarketplaceCatalogFilePath = path.join(await ensureCacheDirectoryExists(), GlobalFileNames.mcpMarketplaceCatalog)
|
||||
await fs.writeFile(mcpMarketplaceCatalogFilePath, JSON.stringify(catalog))
|
||||
} catch (error) {
|
||||
console.error("Failed to write MCP marketplace catalog to cache:", error)
|
||||
}
|
||||
}
|
||||
|
||||
async function getGlobalStorageDir(...subdirs: string[]) {
|
||||
const fullPath = path.resolve(HostProvider.get().globalStorageFsPath, ...subdirs)
|
||||
await fs.mkdir(fullPath, { recursive: true })
|
||||
|
||||
@@ -8,7 +8,6 @@ import { ClineRulesToggles } from "@/shared/cline-rules"
|
||||
import { DictationSettings } from "@/shared/DictationSettings"
|
||||
import { HistoryItem } from "@/shared/HistoryItem"
|
||||
import { McpDisplayMode } from "@/shared/McpDisplayMode"
|
||||
import { McpMarketplaceCatalog } from "@/shared/mcp"
|
||||
import { Mode, OpenaiReasoningEffort } from "@/shared/storage/types"
|
||||
import { TelemetrySetting } from "@/shared/TelemetrySetting"
|
||||
import { UserInfo } from "@/shared/UserInfo"
|
||||
@@ -28,7 +27,6 @@ export interface GlobalState {
|
||||
lastShownAnnouncementId: string | undefined
|
||||
taskHistory: HistoryItem[]
|
||||
userInfo: UserInfo | undefined
|
||||
mcpMarketplaceCatalog: McpMarketplaceCatalog | undefined
|
||||
favoritedModelIds: string[]
|
||||
mcpMarketplaceEnabled: boolean
|
||||
mcpResponsesCollapsed: boolean
|
||||
|
||||
@@ -638,3 +638,22 @@ export async function migrateWelcomeViewCompleted(context: vscode.ExtensionConte
|
||||
// Continue execution - migration failure shouldn't break extension startup
|
||||
}
|
||||
}
|
||||
|
||||
export async function cleanupMcpMarketplaceCatalogFromGlobalState(context: vscode.ExtensionContext) {
|
||||
try {
|
||||
// Check if mcpMarketplaceCatalog exists in global state
|
||||
const mcpMarketplaceCatalog = await context.globalState.get("mcpMarketplaceCatalog")
|
||||
|
||||
if (mcpMarketplaceCatalog !== undefined) {
|
||||
console.log("Cleaning up mcpMarketplaceCatalog from global state...")
|
||||
|
||||
// Delete it from global state
|
||||
await context.globalState.update("mcpMarketplaceCatalog", undefined)
|
||||
|
||||
console.log("Successfully removed mcpMarketplaceCatalog from global state")
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to cleanup mcpMarketplaceCatalog from global state:", error)
|
||||
// Continue execution - cleanup failure shouldn't break extension startup
|
||||
}
|
||||
}
|
||||
@@ -236,9 +236,6 @@ export async function readGlobalStateFromDisk(context: ExtensionContext): Promis
|
||||
const dictationSettings = context.globalState.get<GlobalStateAndSettings["dictationSettings"]>("dictationSettings") as
|
||||
| DictationSettings
|
||||
| undefined
|
||||
|
||||
const mcpMarketplaceCatalog =
|
||||
context.globalState.get<GlobalStateAndSettings["mcpMarketplaceCatalog"]>("mcpMarketplaceCatalog")
|
||||
const lastDismissedInfoBannerVersion =
|
||||
context.globalState.get<GlobalStateAndSettings["lastDismissedInfoBannerVersion"]>("lastDismissedInfoBannerVersion")
|
||||
const lastDismissedModelBannerVersion = context.globalState.get<
|
||||
@@ -560,7 +557,6 @@ export async function readGlobalStateFromDisk(context: ExtensionContext): Promis
|
||||
terminalOutputLineLimit: terminalOutputLineLimit ?? 500,
|
||||
defaultTerminalProfile: defaultTerminalProfile ?? "default",
|
||||
globalWorkflowToggles: globalWorkflowToggles || {},
|
||||
mcpMarketplaceCatalog,
|
||||
qwenCodeOauthPath,
|
||||
customPrompt,
|
||||
autoCondenseThreshold: autoCondenseThreshold || 0.75, // default to 0.75 if not set
|
||||
|
||||
Reference in new issue
Block a user