From 3ec3a870cddedcf704f88c2766b92c3547d21db2 Mon Sep 17 00:00:00 2001 From: Nate Date: Fri, 20 Jun 2025 10:56:47 -0700 Subject: [PATCH 1/2] Add MCP provider refresh for @mention dropdown submenu items --- core/core.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/core.ts b/core/core.ts index a06ae8b78..9710a552a 100644 --- a/core/core.ts +++ b/core/core.ts @@ -147,6 +147,18 @@ export class Core { MCPManagerSingleton.getInstance().onConnectionsRefreshed = () => { void this.configHandler.reloadConfig(); + + // Refresh @mention dropdown submenu items for MCP providers + const mcpManager = MCPManagerSingleton.getInstance(); + const mcpProviderNames = Array.from(mcpManager.connections.keys()).map( + (mcpId) => `mcp-${mcpId}` + ); + + if (mcpProviderNames.length > 0) { + this.messenger.send("refreshSubmenuItems", { + providers: mcpProviderNames, + }); + } }; this.codeBaseIndexer = new CodebaseIndexer( From 8f27a84bc1642d1d4870ae3354034c4ace2a1599 Mon Sep 17 00:00:00 2001 From: Nate Date: Fri, 20 Jun 2025 16:53:59 -0700 Subject: [PATCH 2/2] fix prettier and complexity errors --- core/core.ts | 87 +++++++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/core/core.ts b/core/core.ts index 9710a552a..8665ed297 100644 --- a/core/core.ts +++ b/core/core.ts @@ -42,6 +42,7 @@ import { IdeSettings, ModelDescription, RangeInFile, + ToolCall, type ContextItem, type ContextItemId, type IDE, @@ -147,13 +148,13 @@ export class Core { MCPManagerSingleton.getInstance().onConnectionsRefreshed = () => { void this.configHandler.reloadConfig(); - + // Refresh @mention dropdown submenu items for MCP providers const mcpManager = MCPManagerSingleton.getInstance(); const mcpProviderNames = Array.from(mcpManager.connections.keys()).map( - (mcpId) => `mcp-${mcpId}` + (mcpId) => `mcp-${mcpId}`, ); - + if (mcpProviderNames.length > 0) { this.messenger.send("refreshSubmenuItems", { providers: mcpProviderNames, @@ -755,44 +756,9 @@ export class Core { return { url }; }); - on("tools/call", async ({ data: { toolCall } }) => { - const { config } = await this.configHandler.loadConfig(); - if (!config) { - throw new Error("Config not loaded"); - } - - const tool = config.tools.find( - (t) => t.function.name === toolCall.function.name, - ); - - if (!tool) { - throw new Error(`Tool ${toolCall.function.name} not found`); - } - - if (!config.selectedModelByRole.chat) { - throw new Error("No chat model selected"); - } - - // Define a callback for streaming output updates - const onPartialOutput = (params: { - toolCallId: string; - contextItems: ContextItem[]; - }) => { - this.messenger.send("toolCallPartialOutput", params); - }; - - return await callTool(tool, toolCall, { - config, - ide: this.ide, - llm: config.selectedModelByRole.chat, - fetch: (url, init) => - fetchwithRequestOptions(url, init, config.requestOptions), - tool, - toolCallId: toolCall.id, - onPartialOutput, - codeBaseIndexer: this.codeBaseIndexer, - }); - }); + on("tools/call", async ({ data: { toolCall } }) => + this.handleToolCall(toolCall), + ); on("isItemTooBig", async ({ data: { item } }) => { return this.isItemTooBig(item); @@ -817,6 +783,45 @@ export class Core { }); } + private async handleToolCall(toolCall: ToolCall) { + const { config } = await this.configHandler.loadConfig(); + if (!config) { + throw new Error("Config not loaded"); + } + + const tool = config.tools.find( + (t) => t.function.name === toolCall.function.name, + ); + + if (!tool) { + throw new Error(`Tool ${toolCall.function.name} not found`); + } + + if (!config.selectedModelByRole.chat) { + throw new Error("No chat model selected"); + } + + // Define a callback for streaming output updates + const onPartialOutput = (params: { + toolCallId: string; + contextItems: ContextItem[]; + }) => { + this.messenger.send("toolCallPartialOutput", params); + }; + + return await callTool(tool, toolCall, { + config, + ide: this.ide, + llm: config.selectedModelByRole.chat, + fetch: (url, init) => + fetchwithRequestOptions(url, init, config.requestOptions), + tool, + toolCallId: toolCall.id, + onPartialOutput, + codeBaseIndexer: this.codeBaseIndexer, + }); + } + private async isItemTooBig(item: ContextItemWithId) { const { config } = await this.configHandler.loadConfig(); if (!config) {