Skip to content

Commit 613ce91

Browse files
Merge pull request #6224 from continuedev/fix-atmention-dropdown-mcp-refresh
Add MCP provider refresh for @mention dropdown submenu items
2 parents c8acda3 + 8f27a84 commit 613ce91

File tree

1 file changed

+55
-38
lines changed

1 file changed

+55
-38
lines changed

core/core.ts

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
IdeSettings,
4343
ModelDescription,
4444
RangeInFile,
45+
ToolCall,
4546
type ContextItem,
4647
type ContextItemId,
4748
type IDE,
@@ -147,6 +148,18 @@ export class Core {
147148

148149
MCPManagerSingleton.getInstance().onConnectionsRefreshed = () => {
149150
void this.configHandler.reloadConfig();
151+
152+
// Refresh @mention dropdown submenu items for MCP providers
153+
const mcpManager = MCPManagerSingleton.getInstance();
154+
const mcpProviderNames = Array.from(mcpManager.connections.keys()).map(
155+
(mcpId) => `mcp-${mcpId}`,
156+
);
157+
158+
if (mcpProviderNames.length > 0) {
159+
this.messenger.send("refreshSubmenuItems", {
160+
providers: mcpProviderNames,
161+
});
162+
}
150163
};
151164

152165
this.codeBaseIndexer = new CodebaseIndexer(
@@ -743,44 +756,9 @@ export class Core {
743756
return { url };
744757
});
745758

746-
on("tools/call", async ({ data: { toolCall } }) => {
747-
const { config } = await this.configHandler.loadConfig();
748-
if (!config) {
749-
throw new Error("Config not loaded");
750-
}
751-
752-
const tool = config.tools.find(
753-
(t) => t.function.name === toolCall.function.name,
754-
);
755-
756-
if (!tool) {
757-
throw new Error(`Tool ${toolCall.function.name} not found`);
758-
}
759-
760-
if (!config.selectedModelByRole.chat) {
761-
throw new Error("No chat model selected");
762-
}
763-
764-
// Define a callback for streaming output updates
765-
const onPartialOutput = (params: {
766-
toolCallId: string;
767-
contextItems: ContextItem[];
768-
}) => {
769-
this.messenger.send("toolCallPartialOutput", params);
770-
};
771-
772-
return await callTool(tool, toolCall, {
773-
config,
774-
ide: this.ide,
775-
llm: config.selectedModelByRole.chat,
776-
fetch: (url, init) =>
777-
fetchwithRequestOptions(url, init, config.requestOptions),
778-
tool,
779-
toolCallId: toolCall.id,
780-
onPartialOutput,
781-
codeBaseIndexer: this.codeBaseIndexer,
782-
});
783-
});
759+
on("tools/call", async ({ data: { toolCall } }) =>
760+
this.handleToolCall(toolCall),
761+
);
784762

785763
on("isItemTooBig", async ({ data: { item } }) => {
786764
return this.isItemTooBig(item);
@@ -805,6 +783,45 @@ export class Core {
805783
});
806784
}
807785

786+
private async handleToolCall(toolCall: ToolCall) {
787+
const { config } = await this.configHandler.loadConfig();
788+
if (!config) {
789+
throw new Error("Config not loaded");
790+
}
791+
792+
const tool = config.tools.find(
793+
(t) => t.function.name === toolCall.function.name,
794+
);
795+
796+
if (!tool) {
797+
throw new Error(`Tool ${toolCall.function.name} not found`);
798+
}
799+
800+
if (!config.selectedModelByRole.chat) {
801+
throw new Error("No chat model selected");
802+
}
803+
804+
// Define a callback for streaming output updates
805+
const onPartialOutput = (params: {
806+
toolCallId: string;
807+
contextItems: ContextItem[];
808+
}) => {
809+
this.messenger.send("toolCallPartialOutput", params);
810+
};
811+
812+
return await callTool(tool, toolCall, {
813+
config,
814+
ide: this.ide,
815+
llm: config.selectedModelByRole.chat,
816+
fetch: (url, init) =>
817+
fetchwithRequestOptions(url, init, config.requestOptions),
818+
tool,
819+
toolCallId: toolCall.id,
820+
onPartialOutput,
821+
codeBaseIndexer: this.codeBaseIndexer,
822+
});
823+
}
824+
808825
private async isItemTooBig(item: ContextItemWithId) {
809826
const { config } = await this.configHandler.loadConfig();
810827
if (!config) {

0 commit comments

Comments
 (0)