Merge pull request #4742 from continuedev/dallin/mcp-fixes
Tool/MCP Improvements
This commit is contained in:
commit
4664f61950
35 changed files with 991 additions and 476 deletions
|
|
@ -28,7 +28,6 @@ import {
|
|||
IdeType,
|
||||
ILLM,
|
||||
LLMOptions,
|
||||
MCPOptions,
|
||||
ModelDescription,
|
||||
RerankerDescription,
|
||||
SerializedContinueConfig,
|
||||
|
|
@ -521,6 +520,8 @@ async function intermediateToFinalConfig(
|
|||
contextProviders,
|
||||
models,
|
||||
tools: allTools,
|
||||
mcpServerStatuses: [],
|
||||
slashCommands: config.slashCommands ?? [],
|
||||
modelsByRole: {
|
||||
chat: models,
|
||||
edit: models,
|
||||
|
|
@ -541,53 +542,18 @@ async function intermediateToFinalConfig(
|
|||
},
|
||||
};
|
||||
|
||||
// Apply MCP if specified
|
||||
// Trigger MCP server refreshes (Config is reloaded again once connected!)
|
||||
const mcpManager = MCPManagerSingleton.getInstance();
|
||||
function getMcpId(options: MCPOptions) {
|
||||
return JSON.stringify(options);
|
||||
}
|
||||
if (config.experimental?.modelContextProtocolServers) {
|
||||
await mcpManager.removeUnusedConnections(
|
||||
config.experimental.modelContextProtocolServers.map(getMcpId),
|
||||
);
|
||||
}
|
||||
|
||||
if (config.experimental?.modelContextProtocolServers) {
|
||||
const abortController = new AbortController();
|
||||
const mcpConnectionTimeout = setTimeout(
|
||||
() => abortController.abort(),
|
||||
5000,
|
||||
);
|
||||
|
||||
await Promise.allSettled(
|
||||
config.experimental.modelContextProtocolServers?.map(
|
||||
async (server, index) => {
|
||||
try {
|
||||
const mcpId = getMcpId(server);
|
||||
const mcpConnection = mcpManager.createConnection(mcpId, server);
|
||||
await mcpConnection.modifyConfig(
|
||||
continueConfig,
|
||||
mcpId,
|
||||
abortController.signal,
|
||||
"MCP Server",
|
||||
server.faviconUrl,
|
||||
);
|
||||
} catch (e) {
|
||||
let errorMessage = "Failed to load MCP server";
|
||||
if (e instanceof Error) {
|
||||
errorMessage += ": " + e.message;
|
||||
}
|
||||
errors.push({
|
||||
fatal: false,
|
||||
message: errorMessage,
|
||||
});
|
||||
} finally {
|
||||
clearTimeout(mcpConnectionTimeout);
|
||||
}
|
||||
},
|
||||
) || [],
|
||||
);
|
||||
}
|
||||
mcpManager.setConnections(
|
||||
(config.experimental?.modelContextProtocolServers ?? []).map(
|
||||
(server, index) => ({
|
||||
id: `continue-mcp-server-${index + 1}`,
|
||||
name: `MCP Server ${index + 1}`,
|
||||
...server,
|
||||
}),
|
||||
),
|
||||
false,
|
||||
);
|
||||
|
||||
// Handle experimental modelRole config values for apply and edit
|
||||
const inlineEditModel = getModelByRole(continueConfig, "inlineEdit")?.title;
|
||||
|
|
@ -681,6 +647,7 @@ async function finalToBrowserConfig(
|
|||
rules: final.rules,
|
||||
docs: final.docs,
|
||||
tools: final.tools,
|
||||
mcpServerStatuses: final.mcpServerStatuses,
|
||||
tabAutocompleteOptions: final.tabAutocompleteOptions,
|
||||
usePlatform: await useHub(ide.getIdeSettings()),
|
||||
modelsByRole: Object.fromEntries(
|
||||
|
|
|
|||
|
|
@ -12,12 +12,17 @@ import {
|
|||
IDE,
|
||||
IdeSettings,
|
||||
SerializedContinueConfig,
|
||||
Tool,
|
||||
} from "../../";
|
||||
import { constructMcpSlashCommand } from "../../commands/slash/mcp";
|
||||
import { MCPManagerSingleton } from "../../context/mcp";
|
||||
import MCPContextProvider from "../../context/providers/MCPContextProvider";
|
||||
import { ControlPlaneProxyInfo } from "../../control-plane/analytics/IAnalyticsProvider.js";
|
||||
import { ControlPlaneClient } from "../../control-plane/client.js";
|
||||
import { getControlPlaneEnv } from "../../control-plane/env.js";
|
||||
import { TeamAnalytics } from "../../control-plane/TeamAnalytics.js";
|
||||
import ContinueProxy from "../../llm/llms/stubs/ContinueProxy";
|
||||
import { encodeMCPToolUri } from "../../tools/callTool";
|
||||
import { getConfigJsonPath, getConfigYamlPath } from "../../util/paths";
|
||||
import { localPathOrUriToPath } from "../../util/pathToUri";
|
||||
import { Telemetry } from "../../util/posthog";
|
||||
|
|
@ -93,15 +98,90 @@ export default async function doLoadConfig(
|
|||
configLoadInterrupted = result.configLoadInterrupted;
|
||||
}
|
||||
|
||||
// Rectify model selections for each role
|
||||
if (newConfig) {
|
||||
newConfig = rectifySelectedModelsFromGlobalContext(newConfig, profileId);
|
||||
}
|
||||
|
||||
if (configLoadInterrupted || !newConfig) {
|
||||
return { errors, config: newConfig, configLoadInterrupted: true };
|
||||
}
|
||||
|
||||
// TODO using config result but result with non-fatal errors is an antipattern?
|
||||
// Remove ability have undefined errors, just have an array
|
||||
errors = [...(errors ?? [])];
|
||||
|
||||
// Rectify model selections for each role
|
||||
newConfig = rectifySelectedModelsFromGlobalContext(newConfig, profileId);
|
||||
|
||||
// Add things from MCP servers
|
||||
const mcpManager = MCPManagerSingleton.getInstance();
|
||||
const mcpServerStatuses = mcpManager.getStatuses();
|
||||
|
||||
// Slightly hacky just need connection's client to make slash command for now
|
||||
const serializableStatuses = mcpServerStatuses.map((server) => {
|
||||
const { client, ...rest } = server;
|
||||
return rest;
|
||||
});
|
||||
newConfig.mcpServerStatuses = serializableStatuses;
|
||||
|
||||
for (const server of mcpServerStatuses) {
|
||||
if (server.status === "connected") {
|
||||
const serverTools: Tool[] = server.tools.map((tool) => ({
|
||||
displayTitle: server.name + " " + tool.name,
|
||||
function: {
|
||||
description: tool.description,
|
||||
name: tool.name,
|
||||
parameters: tool.inputSchema,
|
||||
},
|
||||
faviconUrl: server.faviconUrl,
|
||||
readonly: false,
|
||||
type: "function" as const,
|
||||
wouldLikeTo: "",
|
||||
uri: encodeMCPToolUri(server.id, tool.name),
|
||||
group: server.name,
|
||||
}));
|
||||
newConfig.tools.push(...serverTools);
|
||||
|
||||
const serverSlashCommands = server.prompts.map((prompt) =>
|
||||
constructMcpSlashCommand(
|
||||
server.client,
|
||||
prompt.name,
|
||||
prompt.description,
|
||||
prompt.arguments?.map((a: any) => a.name),
|
||||
),
|
||||
);
|
||||
newConfig.slashCommands.push(...serverSlashCommands);
|
||||
|
||||
const submenuItems = server.resources.map((resource) => ({
|
||||
title: resource.name,
|
||||
description: resource.description ?? resource.name,
|
||||
id: resource.uri,
|
||||
icon: server.faviconUrl,
|
||||
}));
|
||||
if (submenuItems.length > 0) {
|
||||
const serverContextProvider = new MCPContextProvider({
|
||||
submenuItems,
|
||||
mcpId: server.id,
|
||||
});
|
||||
newConfig.contextProviders.push(serverContextProvider);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Detect duplicate tool names
|
||||
const counts: Record<string, number> = {};
|
||||
newConfig.tools.forEach((tool) => {
|
||||
if (counts[tool.function.name]) {
|
||||
counts[tool.function.name] = counts[tool.function.name] + 1;
|
||||
} else {
|
||||
counts[tool.function.name] = 1;
|
||||
}
|
||||
});
|
||||
Object.entries(counts).forEach(([toolName, count]) => {
|
||||
if (count > 1) {
|
||||
errors!.push({
|
||||
fatal: false,
|
||||
message: `Duplicate (${count}) tools named "${toolName}" detected. Permissions will conflict and usage may be unpredictable`,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
newConfig.allowAnonymousTelemetry =
|
||||
newConfig.allowAnonymousTelemetry && (await ide.isTelemetryEnabled());
|
||||
|
||||
|
|
|
|||
|
|
@ -111,7 +111,8 @@ async function configYamlToContinueConfig(
|
|||
const continueConfig: ContinueConfig = {
|
||||
slashCommands: [],
|
||||
models: [],
|
||||
tools: allTools,
|
||||
tools: [...allTools],
|
||||
mcpServerStatuses: [],
|
||||
systemMessage: config.rules?.join("\n"),
|
||||
experimental: {
|
||||
modelContextProtocolServers: config.mcpServers?.map((mcpServer) => ({
|
||||
|
|
@ -368,52 +369,19 @@ async function configYamlToContinueConfig(
|
|||
continueConfig.contextProviders.push(new DocsContextProvider({}));
|
||||
}
|
||||
|
||||
// Apply MCP if specified
|
||||
// Trigger MCP server refreshes (Config is reloaded again once connected!)
|
||||
const mcpManager = MCPManagerSingleton.getInstance();
|
||||
if (config.mcpServers) {
|
||||
await mcpManager.removeUnusedConnections(
|
||||
config.mcpServers.map((s) => s.name),
|
||||
);
|
||||
}
|
||||
|
||||
await Promise.allSettled(
|
||||
config.mcpServers?.map(async (server) => {
|
||||
const abortController = new AbortController();
|
||||
const mcpConnectionTimeout = setTimeout(
|
||||
() => abortController.abort(),
|
||||
5000,
|
||||
);
|
||||
|
||||
try {
|
||||
const mcpId = server.name;
|
||||
const mcpConnection = mcpManager.createConnection(mcpId, {
|
||||
transport: {
|
||||
type: "stdio",
|
||||
args: [],
|
||||
...server,
|
||||
},
|
||||
});
|
||||
|
||||
await mcpConnection.modifyConfig(
|
||||
continueConfig,
|
||||
mcpId,
|
||||
abortController.signal,
|
||||
server.name,
|
||||
server.faviconUrl,
|
||||
);
|
||||
} catch (e) {
|
||||
let errorMessage = `Failed to load MCP server ${server.name}`;
|
||||
if (e instanceof Error) {
|
||||
errorMessage += ": " + e.message;
|
||||
}
|
||||
localErrors.push({
|
||||
fatal: false,
|
||||
message: errorMessage,
|
||||
});
|
||||
} finally {
|
||||
clearTimeout(mcpConnectionTimeout);
|
||||
}
|
||||
}) ?? [],
|
||||
mcpManager.setConnections(
|
||||
(config.mcpServers ?? []).map((server) => ({
|
||||
id: server.name,
|
||||
name: server.name,
|
||||
transport: {
|
||||
type: "stdio",
|
||||
args: [],
|
||||
...server,
|
||||
},
|
||||
})),
|
||||
false,
|
||||
);
|
||||
|
||||
return { config: continueConfig, errors: localErrors };
|
||||
|
|
|
|||
|
|
@ -4,16 +4,23 @@ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"
|
|||
import { WebSocketClientTransport } from "@modelcontextprotocol/sdk/client/websocket.js";
|
||||
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
||||
|
||||
import { ContinueConfig, MCPOptions, SlashCommand, Tool } from "../..";
|
||||
import { constructMcpSlashCommand } from "../../commands/slash/mcp";
|
||||
import { encodeMCPToolUri } from "../../tools/callTool";
|
||||
import MCPContextProvider from "../providers/MCPContextProvider";
|
||||
import {
|
||||
MCPConnectionStatus,
|
||||
MCPOptions,
|
||||
MCPPrompt,
|
||||
MCPResource,
|
||||
MCPServerStatus,
|
||||
MCPTool,
|
||||
} from "../..";
|
||||
|
||||
export class MCPManagerSingleton {
|
||||
private static instance: MCPManagerSingleton;
|
||||
|
||||
public onConnectionsRefreshed?: () => void;
|
||||
private connections: Map<string, MCPConnection> = new Map();
|
||||
|
||||
private abortController: AbortController = new AbortController();
|
||||
|
||||
private constructor() {}
|
||||
|
||||
public static getInstance(): MCPManagerSingleton {
|
||||
|
|
@ -46,18 +53,90 @@ export class MCPManagerSingleton {
|
|||
this.connections.delete(id);
|
||||
}
|
||||
|
||||
async removeUnusedConnections(keepIds: string[]) {
|
||||
const toRemove = Array.from(this.connections.keys()).filter(
|
||||
(k) => !keepIds.includes(k),
|
||||
);
|
||||
await Promise.all(toRemove.map((id) => this.removeConnection(id)));
|
||||
setConnections(servers: MCPOptions[], forceRefresh: boolean) {
|
||||
let refresh = false;
|
||||
|
||||
// Remove any connections that are no longer in config
|
||||
Array.from(this.connections.entries()).forEach(([id, connection]) => {
|
||||
if (!servers.find((s) => s.id === id)) {
|
||||
refresh = true;
|
||||
connection.abortController.abort();
|
||||
void connection.client.close();
|
||||
this.connections.delete(id);
|
||||
}
|
||||
});
|
||||
|
||||
// Add any connections that are not yet in manager
|
||||
servers.forEach((server) => {
|
||||
if (!this.connections.has(server.id)) {
|
||||
refresh = true;
|
||||
this.connections.set(server.id, new MCPConnection(server));
|
||||
}
|
||||
});
|
||||
|
||||
// NOTE the id is made by stringifying the options
|
||||
if (refresh) {
|
||||
void this.refreshConnections(forceRefresh);
|
||||
}
|
||||
}
|
||||
|
||||
async refreshConnection(serverId: string) {
|
||||
const connection = this.connections.get(serverId);
|
||||
if (!connection) {
|
||||
throw new Error(`MCP Connection ${serverId} not found`);
|
||||
}
|
||||
await connection.connectClient(true, this.abortController.signal);
|
||||
if (this.onConnectionsRefreshed) {
|
||||
this.onConnectionsRefreshed();
|
||||
}
|
||||
}
|
||||
|
||||
async refreshConnections(force: boolean) {
|
||||
this.abortController.abort();
|
||||
this.abortController = new AbortController();
|
||||
await Promise.race([
|
||||
new Promise((resolve) => {
|
||||
this.abortController.signal.addEventListener("abort", () => {
|
||||
resolve(undefined);
|
||||
});
|
||||
}),
|
||||
(async () => {
|
||||
await Promise.all(
|
||||
Array.from(this.connections.values()).map(async (connection) => {
|
||||
await connection.connectClient(force, this.abortController.signal);
|
||||
}),
|
||||
);
|
||||
if (this.onConnectionsRefreshed) {
|
||||
this.onConnectionsRefreshed();
|
||||
}
|
||||
})(),
|
||||
]);
|
||||
}
|
||||
|
||||
getStatuses(): (MCPServerStatus & { client: Client })[] {
|
||||
return Array.from(this.connections.values()).map((connection) => ({
|
||||
...connection.getStatus(),
|
||||
client: connection.client,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
const DEFAULT_MCP_TIMEOUT = 20_000; // 10 seconds
|
||||
|
||||
class MCPConnection {
|
||||
public client: Client;
|
||||
private transport: Transport;
|
||||
|
||||
private connectionPromise: Promise<unknown> | null = null;
|
||||
public abortController: AbortController;
|
||||
|
||||
public status: MCPConnectionStatus = "not-connected";
|
||||
public errors: string[] = [];
|
||||
|
||||
public prompts: MCPPrompt[] = [];
|
||||
public tools: MCPTool[] = [];
|
||||
public resources: MCPResource[] = [];
|
||||
|
||||
constructor(private readonly options: MCPOptions) {
|
||||
this.transport = this.constructTransport(options);
|
||||
|
||||
|
|
@ -70,6 +149,8 @@ class MCPConnection {
|
|||
capabilities: {},
|
||||
},
|
||||
);
|
||||
|
||||
this.abortController = new AbortController();
|
||||
}
|
||||
|
||||
private constructTransport(options: MCPOptions): Transport {
|
||||
|
|
@ -95,131 +176,170 @@ class MCPConnection {
|
|||
}
|
||||
}
|
||||
|
||||
private isConnected: boolean = false;
|
||||
private connectPromise: Promise<void> | null = null;
|
||||
|
||||
private async connectClient() {
|
||||
if (this.isConnected) {
|
||||
// Already connected
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.connectPromise) {
|
||||
// Connection is already in progress; wait for it to complete
|
||||
await this.connectPromise;
|
||||
return;
|
||||
}
|
||||
|
||||
this.connectPromise = (async () => {
|
||||
await this.client.connect(this.transport);
|
||||
this.isConnected = true;
|
||||
})();
|
||||
|
||||
try {
|
||||
await this.connectPromise;
|
||||
} finally {
|
||||
// Reset the promise so future attempts can try again if necessary
|
||||
this.connectPromise = null;
|
||||
}
|
||||
getStatus(): MCPServerStatus {
|
||||
return {
|
||||
...this.options,
|
||||
errors: this.errors,
|
||||
prompts: this.prompts,
|
||||
resources: this.resources,
|
||||
tools: this.tools,
|
||||
status: this.status,
|
||||
};
|
||||
}
|
||||
|
||||
async modifyConfig(
|
||||
config: ContinueConfig,
|
||||
mcpId: string,
|
||||
signal: AbortSignal,
|
||||
name: string,
|
||||
faviconUrl: string | undefined,
|
||||
) {
|
||||
try {
|
||||
await Promise.race([
|
||||
this.connectClient(),
|
||||
new Promise((_, reject) => {
|
||||
signal.addEventListener("abort", () =>
|
||||
reject(new Error("Connection timed out")),
|
||||
);
|
||||
}),
|
||||
]);
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
const msg = error.message.toLowerCase();
|
||||
if (msg.includes("spawn") && msg.includes("enoent")) {
|
||||
const command = msg.split(" ")[1];
|
||||
throw new Error(
|
||||
`command "${command}" not found. To use this MCP server, install the ${command} CLI.`,
|
||||
);
|
||||
} else if (
|
||||
!error.message.startsWith("StdioClientTransport already started")
|
||||
) {
|
||||
// don't throw error if it's just a "server already running" case
|
||||
throw error;
|
||||
async connectClient(forceRefresh: boolean, externalSignal: AbortSignal) {
|
||||
if (!forceRefresh) {
|
||||
// Already connected
|
||||
if (this.status === "connected") {
|
||||
return;
|
||||
}
|
||||
|
||||
// Connection is already in progress; wait for it to complete
|
||||
if (this.connectionPromise) {
|
||||
await this.connectionPromise;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.status = "connecting";
|
||||
this.tools = [];
|
||||
this.prompts = [];
|
||||
this.resources = [];
|
||||
this.errors = [];
|
||||
|
||||
this.abortController.abort();
|
||||
this.abortController = new AbortController();
|
||||
|
||||
this.connectionPromise = Promise.race([
|
||||
// If aborted by a refresh or other, cancel and don't do anything
|
||||
new Promise((resolve) => {
|
||||
externalSignal.addEventListener("abort", () => {
|
||||
resolve(undefined);
|
||||
});
|
||||
}),
|
||||
new Promise((resolve) => {
|
||||
this.abortController.signal.addEventListener("abort", () => {
|
||||
resolve(undefined);
|
||||
});
|
||||
}),
|
||||
(async () => {
|
||||
const timeoutController = new AbortController();
|
||||
const connectionTimeout = setTimeout(
|
||||
() => timeoutController.abort(),
|
||||
this.options.timeout ?? DEFAULT_MCP_TIMEOUT,
|
||||
);
|
||||
|
||||
try {
|
||||
await Promise.race([
|
||||
new Promise((_, reject) => {
|
||||
timeoutController.signal.addEventListener("abort", () => {
|
||||
reject(new Error("Connection timed out"));
|
||||
});
|
||||
}),
|
||||
(async () => {
|
||||
this.transport = this.constructTransport(this.options);
|
||||
try {
|
||||
await this.client.connect(this.transport);
|
||||
} catch (error) {
|
||||
// Allow the case where for whatever reason is already connected
|
||||
if (
|
||||
error instanceof Error &&
|
||||
error.message.startsWith(
|
||||
"StdioClientTransport already started",
|
||||
)
|
||||
) {
|
||||
await this.client.close();
|
||||
await this.client.connect(this.transport);
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO register server notification handlers
|
||||
// this.client.transport?.onmessage(msg => console.log())
|
||||
// this.client.setNotificationHandler(, notification => {
|
||||
// console.log(notification)
|
||||
// })
|
||||
|
||||
const capabilities = this.client.getServerCapabilities();
|
||||
|
||||
// Resources <—> Context Provider
|
||||
if (capabilities?.resources) {
|
||||
try {
|
||||
const { resources } = await this.client.listResources(
|
||||
{},
|
||||
{ signal: timeoutController.signal },
|
||||
);
|
||||
this.resources = resources;
|
||||
} catch (e) {
|
||||
let errorMessage = `Error loading resources for MCP Server ${this.options.name}`;
|
||||
if (e instanceof Error) {
|
||||
errorMessage += `: ${e.message}`;
|
||||
}
|
||||
this.errors.push(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
// Tools <—> Tools
|
||||
if (capabilities?.tools) {
|
||||
try {
|
||||
const { tools } = await this.client.listTools(
|
||||
{},
|
||||
{ signal: timeoutController.signal },
|
||||
);
|
||||
this.tools = tools;
|
||||
} catch (e) {
|
||||
let errorMessage = `Error loading tools for MCP Server ${this.options.name}`;
|
||||
if (e instanceof Error) {
|
||||
errorMessage += `: ${e.message}`;
|
||||
}
|
||||
this.errors.push(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
// Prompts <—> Slash commands
|
||||
if (capabilities?.prompts) {
|
||||
try {
|
||||
const { prompts } = await this.client.listPrompts(
|
||||
{},
|
||||
{ signal: timeoutController.signal },
|
||||
);
|
||||
this.prompts = prompts;
|
||||
} catch (e) {
|
||||
let errorMessage = `Error loading prompts for MCP Server ${this.options.name}`;
|
||||
if (e instanceof Error) {
|
||||
errorMessage += `: ${e.message}`;
|
||||
}
|
||||
this.errors.push(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
this.status = "connected";
|
||||
})(),
|
||||
]);
|
||||
} catch (error) {
|
||||
// Otherwise it's a connection error
|
||||
let errorMessage = `Failed to connect to MCP server ${this.options.name}`;
|
||||
if (error instanceof Error) {
|
||||
const msg = error.message.toLowerCase();
|
||||
if (msg.includes("spawn") && msg.includes("enoent")) {
|
||||
const command = msg.split(" ")[1];
|
||||
errorMessage += `command "${command}" not found. To use this MCP server, install the ${command} CLI.`;
|
||||
} else {
|
||||
errorMessage += ": " + error.message;
|
||||
}
|
||||
}
|
||||
|
||||
this.status = "error";
|
||||
this.errors.push(errorMessage);
|
||||
} finally {
|
||||
this.connectionPromise = null;
|
||||
clearTimeout(connectionTimeout);
|
||||
}
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
})(),
|
||||
]);
|
||||
|
||||
const capabilities = this.client.getServerCapabilities();
|
||||
|
||||
// Resources <—> Context Provider
|
||||
if (capabilities?.resources) {
|
||||
const { resources } = await this.client.listResources({}, { signal });
|
||||
const submenuItems = resources.map((resource: any) => ({
|
||||
title: resource.name,
|
||||
description: resource.description,
|
||||
id: resource.uri,
|
||||
icon: faviconUrl,
|
||||
}));
|
||||
|
||||
if (!config.contextProviders) {
|
||||
config.contextProviders = [];
|
||||
}
|
||||
|
||||
config.contextProviders.push(
|
||||
new MCPContextProvider({
|
||||
submenuItems,
|
||||
mcpId,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
// Tools <—> Tools
|
||||
if (capabilities?.tools) {
|
||||
const { tools } = await this.client.listTools({}, { signal });
|
||||
const continueTools: Tool[] = tools.map((tool: any) => ({
|
||||
displayTitle: name + " " + tool.name,
|
||||
function: {
|
||||
description: tool.description,
|
||||
name: tool.name,
|
||||
parameters: tool.inputSchema,
|
||||
},
|
||||
faviconUrl,
|
||||
readonly: false,
|
||||
type: "function",
|
||||
wouldLikeTo: `use the ${name} ${tool.name} tool`,
|
||||
uri: encodeMCPToolUri(mcpId, tool.name),
|
||||
}));
|
||||
|
||||
config.tools = [...continueTools, ...config.tools];
|
||||
}
|
||||
|
||||
// Prompts <—> Slash commands
|
||||
if (capabilities?.prompts) {
|
||||
const { prompts } = await this.client.listPrompts({}, { signal });
|
||||
if (!config.slashCommands) {
|
||||
config.slashCommands = [];
|
||||
}
|
||||
|
||||
const slashCommands: SlashCommand[] = prompts.map((prompt: any) =>
|
||||
constructMcpSlashCommand(
|
||||
this.client,
|
||||
prompt.name,
|
||||
prompt.description,
|
||||
prompt.arguments?.map((a: any) => a.name),
|
||||
),
|
||||
);
|
||||
|
||||
config.slashCommands.push(...slashCommands);
|
||||
}
|
||||
await this.connectionPromise;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
11
core/core.ts
11
core/core.ts
|
|
@ -43,6 +43,7 @@ import {
|
|||
} from ".";
|
||||
|
||||
import { isLocalAssistantFile } from "./config/loadLocalAssistants";
|
||||
import { MCPManagerSingleton } from "./context/mcp";
|
||||
import { shouldIgnore } from "./indexing/shouldIgnore";
|
||||
import { walkDirCache } from "./indexing/walkDir";
|
||||
import { llmStreamChat } from "./llm/streamChat";
|
||||
|
|
@ -120,6 +121,13 @@ export class Core {
|
|||
this.messenger,
|
||||
);
|
||||
|
||||
const mcpManager = MCPManagerSingleton.getInstance();
|
||||
mcpManager.onConnectionsRefreshed = async () => {
|
||||
// This ensures that it triggers a NEW load after waiting for config promise to finish
|
||||
await this.configHandler.loadConfig();
|
||||
await this.configHandler.reloadConfig();
|
||||
};
|
||||
|
||||
this.configHandler.onConfigUpdate(async (result) => {
|
||||
const serializedResult = await this.configHandler.getSerializedConfig();
|
||||
this.messenger.send("configUpdate", {
|
||||
|
|
@ -344,6 +352,9 @@ export class Core {
|
|||
return await this.configHandler.listOrganizations();
|
||||
});
|
||||
|
||||
on("mcp/reloadServer", async (msg) => {
|
||||
mcpManager.refreshConnection(msg.data.id);
|
||||
});
|
||||
// Context providers
|
||||
on("context/addDocs", async (msg) => {
|
||||
void this.docsService.indexAndAdd(msg.data);
|
||||
|
|
|
|||
115
core/index.d.ts
vendored
115
core/index.d.ts
vendored
|
|
@ -43,13 +43,13 @@ export interface IndexingProgressUpdate {
|
|||
desc: string;
|
||||
shouldClearIndexes?: boolean;
|
||||
status:
|
||||
| "loading"
|
||||
| "indexing"
|
||||
| "done"
|
||||
| "failed"
|
||||
| "paused"
|
||||
| "disabled"
|
||||
| "cancelled";
|
||||
| "loading"
|
||||
| "indexing"
|
||||
| "done"
|
||||
| "failed"
|
||||
| "paused"
|
||||
| "disabled"
|
||||
| "cancelled";
|
||||
debugInfo?: string;
|
||||
}
|
||||
|
||||
|
|
@ -316,7 +316,12 @@ export interface CompletionOptions extends BaseCompletionOptions {
|
|||
model: string;
|
||||
}
|
||||
|
||||
export type ChatMessageRole = "user" | "assistant" | "thinking" | "system" | "tool";
|
||||
export type ChatMessageRole =
|
||||
| "user"
|
||||
| "assistant"
|
||||
| "thinking"
|
||||
| "system"
|
||||
| "tool";
|
||||
|
||||
export type TextMessagePart = {
|
||||
type: "text";
|
||||
|
|
@ -692,10 +697,10 @@ export interface IDE {
|
|||
getCurrentFile(): Promise<
|
||||
| undefined
|
||||
| {
|
||||
isUntitled: boolean;
|
||||
path: string;
|
||||
contents: string;
|
||||
}
|
||||
isUntitled: boolean;
|
||||
path: string;
|
||||
contents: string;
|
||||
}
|
||||
>;
|
||||
|
||||
getLastFileSaveTimestamp?(): number;
|
||||
|
|
@ -879,11 +884,11 @@ export interface CustomCommand {
|
|||
export interface Prediction {
|
||||
type: "content";
|
||||
content:
|
||||
| string
|
||||
| {
|
||||
type: "text";
|
||||
text: string;
|
||||
}[];
|
||||
| string
|
||||
| {
|
||||
type: "text";
|
||||
text: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
export interface ToolExtras {
|
||||
|
|
@ -907,6 +912,7 @@ export interface Tool {
|
|||
readonly: boolean;
|
||||
uri?: string;
|
||||
faviconUrl?: string;
|
||||
group: string;
|
||||
}
|
||||
|
||||
interface ToolChoice {
|
||||
|
|
@ -1042,8 +1048,54 @@ export interface SSEOptions {
|
|||
export type TransportOptions = StdioOptions | WebSocketOptions | SSEOptions;
|
||||
|
||||
export interface MCPOptions {
|
||||
name: string;
|
||||
id: string;
|
||||
transport: TransportOptions;
|
||||
faviconUrl?: string;
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
export type MCPConnectionStatus =
|
||||
| "connecting"
|
||||
| "connected"
|
||||
| "error"
|
||||
| "not-connected";
|
||||
|
||||
export interface MCPPrompt {
|
||||
name: string;
|
||||
description?: string;
|
||||
arguments?: {
|
||||
name: string;
|
||||
description?: string;
|
||||
required?: boolean;
|
||||
}[];
|
||||
}
|
||||
|
||||
// Leaving here to ideate on
|
||||
// export type ContinueConfigSource = "local-yaml" | "local-json" | "hub-assistant" | "hub"
|
||||
|
||||
export interface MCPResource {
|
||||
name: string;
|
||||
uri: string;
|
||||
description?: string;
|
||||
mimeType?: string;
|
||||
}
|
||||
export interface MCPTool {
|
||||
name: string;
|
||||
description?: string;
|
||||
inputSchema: {
|
||||
type: "object";
|
||||
properties?: Record<string, any>;
|
||||
};
|
||||
}
|
||||
|
||||
export interface MCPServerStatus extends MCPOptions {
|
||||
status: MCPConnectionStatus;
|
||||
errors: string[];
|
||||
|
||||
prompts: MCPPrompt[];
|
||||
tools: MCPTool[];
|
||||
resources: MCPResource[];
|
||||
}
|
||||
|
||||
export interface ContinueUIConfig {
|
||||
|
|
@ -1069,6 +1121,11 @@ export interface ExperimentalModelRoles {
|
|||
applyCodeBlock?: string;
|
||||
}
|
||||
|
||||
export interface ExperimentalMCPOptions {
|
||||
transport: TransportOptions;
|
||||
faviconUrl?: string;
|
||||
}
|
||||
|
||||
export type EditStatus =
|
||||
| "not-started"
|
||||
| "streaming"
|
||||
|
|
@ -1152,7 +1209,7 @@ export interface ExperimentalConfig {
|
|||
* This is needed to crawl a large number of documentation sites that are dynamically rendered.
|
||||
*/
|
||||
useChromiumForDocsCrawling?: boolean;
|
||||
modelContextProtocolServers?: MCPOptions[];
|
||||
modelContextProtocolServers?: ExperimentalMCPOptions[];
|
||||
}
|
||||
|
||||
export interface AnalyticsConfig {
|
||||
|
|
@ -1223,9 +1280,9 @@ export interface Config {
|
|||
embeddingsProvider?: EmbeddingsProviderDescription | ILLM;
|
||||
/** The model that Continue will use for tab autocompletions. */
|
||||
tabAutocompleteModel?:
|
||||
| CustomLLM
|
||||
| ModelDescription
|
||||
| (CustomLLM | ModelDescription)[];
|
||||
| CustomLLM
|
||||
| ModelDescription
|
||||
| (CustomLLM | ModelDescription)[];
|
||||
/** Options for tab autocomplete */
|
||||
tabAutocompleteOptions?: Partial<TabAutocompleteOptions>;
|
||||
/** UI styles customization */
|
||||
|
|
@ -1246,8 +1303,8 @@ export interface ContinueConfig {
|
|||
systemMessage?: string;
|
||||
completionOptions?: BaseCompletionOptions;
|
||||
requestOptions?: RequestOptions;
|
||||
slashCommands?: SlashCommand[];
|
||||
contextProviders?: IContextProvider[];
|
||||
slashCommands: SlashCommand[];
|
||||
contextProviders: IContextProvider[];
|
||||
disableSessionTitles?: boolean;
|
||||
disableIndexing?: boolean;
|
||||
userToken?: string;
|
||||
|
|
@ -1257,6 +1314,7 @@ export interface ContinueConfig {
|
|||
analytics?: AnalyticsConfig;
|
||||
docs?: SiteIndexingConfig[];
|
||||
tools: Tool[];
|
||||
mcpServerStatuses: MCPServerStatus[];
|
||||
rules?: string[];
|
||||
modelsByRole: Record<ModelRole, ILLM[]>;
|
||||
selectedModelByRole: Record<ModelRole, ILLM | null>;
|
||||
|
|
@ -1269,8 +1327,8 @@ export interface BrowserSerializedContinueConfig {
|
|||
systemMessage?: string;
|
||||
completionOptions?: BaseCompletionOptions;
|
||||
requestOptions?: RequestOptions;
|
||||
slashCommands?: SlashCommandDescription[];
|
||||
contextProviders?: ContextProviderDescription[];
|
||||
slashCommands: SlashCommandDescription[];
|
||||
contextProviders: ContextProviderDescription[];
|
||||
disableIndexing?: boolean;
|
||||
disableSessionTitles?: boolean;
|
||||
userToken?: string;
|
||||
|
|
@ -1279,6 +1337,7 @@ export interface BrowserSerializedContinueConfig {
|
|||
analytics?: AnalyticsConfig;
|
||||
docs?: SiteIndexingConfig[];
|
||||
tools: Tool[];
|
||||
mcpServerStatuses: MCPServerStatus[];
|
||||
rules?: string[];
|
||||
usePlatform: boolean;
|
||||
tabAutocompleteOptions?: Partial<TabAutocompleteOptions>;
|
||||
|
|
@ -1319,9 +1378,9 @@ export type PackageDetailsSuccess = PackageDetails & {
|
|||
export type PackageDocsResult = {
|
||||
packageInfo: ParsedPackageInfo;
|
||||
} & (
|
||||
| { error: string; details?: never }
|
||||
| { details: PackageDetailsSuccess; error?: never }
|
||||
);
|
||||
| { error: string; details?: never }
|
||||
| { details: PackageDetailsSuccess; error?: never }
|
||||
);
|
||||
|
||||
export interface TerminalOptions {
|
||||
reuseTerminal?: boolean;
|
||||
|
|
|
|||
|
|
@ -142,6 +142,7 @@ function testLLM(
|
|||
type: "function",
|
||||
wouldLikeTo: "Say hello",
|
||||
readonly: true,
|
||||
group: "Hello",
|
||||
},
|
||||
],
|
||||
toolChoice: {
|
||||
|
|
|
|||
|
|
@ -94,6 +94,12 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
},
|
||||
ContextItemWithId[],
|
||||
];
|
||||
"mcp/reloadServer": [
|
||||
{
|
||||
id: string;
|
||||
},
|
||||
void,
|
||||
];
|
||||
"context/getSymbolsForFiles": [{ uris: string[] }, FileSymbolMap];
|
||||
"context/loadSubmenuItems": [{ title: string }, ContextSubmenuItem[]];
|
||||
"autocomplete/complete": [AutocompleteInput, string[]];
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
|
|||
"config/openProfile",
|
||||
"config/updateSharedConfig",
|
||||
"config/updateSelectedModel",
|
||||
"mcp/reloadServer",
|
||||
"context/getContextItems",
|
||||
"context/getSymbolsForFiles",
|
||||
"context/loadSubmenuItems",
|
||||
|
|
|
|||
|
|
@ -8,4 +8,5 @@ export enum BuiltInToolNames {
|
|||
ExactSearch = "builtin_exact_search",
|
||||
SearchWeb = "builtin_search_web",
|
||||
ViewDiff = "builtin_view_diff",
|
||||
}
|
||||
}
|
||||
export const BUILT_IN_GROUP_NAME = "Built-In";
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { Tool } from "../..";
|
||||
import { BuiltInToolNames } from "../builtIn";
|
||||
import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
|
||||
|
||||
export const createNewFileTool: Tool = {
|
||||
type: "function",
|
||||
displayTitle: "Create New File",
|
||||
wouldLikeTo: "create a new file",
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
readonly: false,
|
||||
function: {
|
||||
name: BuiltInToolNames.CreateNewFile,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import { Tool } from "../..";
|
||||
import { BuiltInToolNames } from "../builtIn";
|
||||
import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
|
||||
|
||||
export const exactSearchTool: Tool = {
|
||||
type: "function",
|
||||
displayTitle: "Exact Search",
|
||||
wouldLikeTo: 'search for "{{{ query }}}" in the repository',
|
||||
readonly: true,
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
function: {
|
||||
name: BuiltInToolNames.ExactSearch,
|
||||
description: "Perform an exact search over the repository using ripgrep.",
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import { Tool } from "../..";
|
||||
import { BuiltInToolNames } from "../builtIn";
|
||||
import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
|
||||
|
||||
export const readCurrentlyOpenFileTool: Tool = {
|
||||
type: "function",
|
||||
displayTitle: "Read Currently Open File",
|
||||
wouldLikeTo: "read the current file",
|
||||
readonly: true,
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
function: {
|
||||
name: BuiltInToolNames.ReadCurrentlyOpenFile,
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import { Tool } from "../..";
|
||||
import { BuiltInToolNames } from "../builtIn";
|
||||
import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
|
||||
|
||||
export const readFileTool: Tool = {
|
||||
type: "function",
|
||||
displayTitle: "Read File",
|
||||
wouldLikeTo: "read {{{ filepath }}}",
|
||||
readonly: true,
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
function: {
|
||||
name: BuiltInToolNames.ReadFile,
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import { Tool } from "../..";
|
||||
import { BuiltInToolNames } from "../builtIn";
|
||||
import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
|
||||
|
||||
export const runTerminalCommandTool: Tool = {
|
||||
type: "function",
|
||||
displayTitle: "Run Terminal Command",
|
||||
wouldLikeTo: "run a terminal command",
|
||||
readonly: false,
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
function: {
|
||||
name: BuiltInToolNames.RunTerminalCommand,
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
import { Tool } from "../..";
|
||||
|
||||
import { BuiltInToolNames } from "../builtIn";
|
||||
import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
|
||||
|
||||
export const searchWebTool: Tool = {
|
||||
type: "function",
|
||||
displayTitle: "Search Web",
|
||||
wouldLikeTo: 'search the web for "{{{ query }}}"',
|
||||
readonly: true,
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
function: {
|
||||
name: BuiltInToolNames.SearchWeb,
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
import { Tool } from "../..";
|
||||
|
||||
import { BuiltInToolNames } from "../builtIn";
|
||||
import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
|
||||
|
||||
export const viewDiffTool: Tool = {
|
||||
type: "function",
|
||||
displayTitle: "View Diff",
|
||||
wouldLikeTo: "view a diff",
|
||||
readonly: true,
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
function: {
|
||||
name: BuiltInToolNames.ViewDiff,
|
||||
description: "View the current diff of working changes",
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
import { Tool } from "../..";
|
||||
|
||||
import { BuiltInToolNames } from "../builtIn";
|
||||
import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
|
||||
|
||||
export const viewRepoMapTool: Tool = {
|
||||
type: "function",
|
||||
displayTitle: "View Repo Map",
|
||||
wouldLikeTo: "view the repository map",
|
||||
readonly: true,
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
function: {
|
||||
name: BuiltInToolNames.ViewRepoMap,
|
||||
description: "View the repository map",
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import { Tool } from "../..";
|
||||
import { BuiltInToolNames } from "../builtIn";
|
||||
import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
|
||||
|
||||
export const viewSubdirectoryTool: Tool = {
|
||||
type: "function",
|
||||
displayTitle: "View Subdirectory",
|
||||
wouldLikeTo: 'view the contents of "{{{ directory_path }}}"',
|
||||
readonly: true,
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
function: {
|
||||
name: BuiltInToolNames.ViewSubdirectory,
|
||||
description: "View the contents of a subdirectory",
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ class MessageTypes {
|
|||
"config/openProfile",
|
||||
"config/updateSharedConfig",
|
||||
"config/updateSelectedModel",
|
||||
"mcp/reloadServer",
|
||||
"context/getContextItems",
|
||||
"context/getSymbolsForFiles",
|
||||
"context/loadSubmenuItems",
|
||||
|
|
|
|||
|
|
@ -4,20 +4,27 @@ type ToggleSwitchProps = {
|
|||
isToggled: boolean;
|
||||
onToggle: () => void;
|
||||
text: string;
|
||||
size?: number;
|
||||
};
|
||||
|
||||
const ToggleSwitch: React.FC<ToggleSwitchProps> = ({
|
||||
isToggled,
|
||||
onToggle,
|
||||
text,
|
||||
size = 16,
|
||||
}) => {
|
||||
return (
|
||||
<div className="flex cursor-pointer select-none items-center justify-between gap-3">
|
||||
<span className="truncate-right">{text}</span>
|
||||
<div>
|
||||
<div
|
||||
className={`border-vsc-input-border bg-vsc-input-background flex h-4 w-8 items-center rounded-full border border-solid p-0.5`}
|
||||
className={`border-vsc-input-border bg-vsc-input-background flex items-center rounded-full border border-solid`}
|
||||
onClick={onToggle}
|
||||
style={{
|
||||
height: size,
|
||||
width: size * 2,
|
||||
padding: size / 8,
|
||||
}}
|
||||
>
|
||||
<div className="relative h-full w-full">
|
||||
<div
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import { selectIsGatheringContext } from "../../redux/slices/sessionSlice";
|
|||
import FileIcon from "../FileIcon";
|
||||
import SafeImg from "../SafeImg";
|
||||
import { getIconFromDropdownItem } from "./MentionList";
|
||||
import { NAMED_ICONS } from "./icons";
|
||||
|
||||
interface ContextItemsPeekProps {
|
||||
contextItems?: ContextItemWithId[];
|
||||
|
|
@ -59,13 +60,28 @@ function ContextItemsPeekItem({ contextItem }: ContextItemsPeekItemProps) {
|
|||
const dimensions = "18px";
|
||||
|
||||
if (contextItem.icon) {
|
||||
const NamedIcon = contextItem.icon
|
||||
? NAMED_ICONS[contextItem.icon]
|
||||
: undefined;
|
||||
return (
|
||||
<SafeImg
|
||||
className="mr-2 flex-shrink-0 rounded-md p-1"
|
||||
src={contextItem.icon}
|
||||
height={dimensions}
|
||||
width={dimensions}
|
||||
fallback={null}
|
||||
fallback={
|
||||
NamedIcon ? (
|
||||
<div
|
||||
className="mr-2 flex-shrink-0"
|
||||
style={{
|
||||
height: dimensions,
|
||||
width: dimensions,
|
||||
}}
|
||||
>
|
||||
<NamedIcon />
|
||||
</div>
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,54 +1,39 @@
|
|||
import { Listbox } from "@headlessui/react";
|
||||
import {
|
||||
EllipsisHorizontalCircleIcon as EllipsisHorizontalIcon,
|
||||
WrenchScrewdriverIcon as WrenchScrewdriverIconOutline,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { WrenchScrewdriverIcon as WrenchScrewdriverIconSolid } from "@heroicons/react/24/solid";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { lightGray, vscForeground } from "../..";
|
||||
import { useAppSelector } from "../../../redux/hooks";
|
||||
import { toggleUseTools } from "../../../redux/slices/uiSlice";
|
||||
import { ToolTip } from "../../gui/Tooltip";
|
||||
import InfoHover from "../../InfoHover";
|
||||
import HoverItem from "./HoverItem";
|
||||
import PopoverTransition from "./PopoverTransition";
|
||||
import ToolDropdownItem from "./ToolDropdownItem";
|
||||
import { useState } from "react";
|
||||
import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
|
||||
import { selectIsInEditMode } from "../../../redux/slices/sessionSlice";
|
||||
import {
|
||||
setDialogMessage,
|
||||
setShowDialog,
|
||||
toggleUseTools,
|
||||
} from "../../../redux/slices/uiSlice";
|
||||
import { ToolTip } from "../../gui/Tooltip";
|
||||
import HoverItem from "./HoverItem";
|
||||
import ToolPermissionsDialog from "./ToolPermissionsDialog";
|
||||
|
||||
interface ToolDropdownProps {
|
||||
interface ToggleToolsButtonProps {
|
||||
disabled: boolean;
|
||||
}
|
||||
|
||||
export default function ToolDropdown(props: ToolDropdownProps) {
|
||||
const buttonRef = useRef<HTMLButtonElement>(null);
|
||||
const dispatch = useDispatch();
|
||||
const [isDropdownOpen, setDropdownOpen] = useState(false);
|
||||
export default function ToggleToolsButton(props: ToggleToolsButtonProps) {
|
||||
const dispatch = useAppDispatch();
|
||||
const [isHovered, setIsHovered] = useState(false);
|
||||
|
||||
const useTools = useAppSelector((state) => state.ui.useTools);
|
||||
const availableTools = useAppSelector((state) => state.config.config.tools);
|
||||
const [showAbove, setShowAbove] = useState(false);
|
||||
const isInEditMode = useAppSelector(selectIsInEditMode);
|
||||
|
||||
const ToolsIcon = useTools
|
||||
? WrenchScrewdriverIconSolid
|
||||
: WrenchScrewdriverIconOutline;
|
||||
|
||||
useEffect(() => {
|
||||
const checkPosition = () => {
|
||||
if (buttonRef.current) {
|
||||
const rect = buttonRef.current.getBoundingClientRect();
|
||||
const windowHeight = window.innerHeight;
|
||||
const spaceBelow = windowHeight - rect.bottom;
|
||||
setShowAbove(spaceBelow < 250);
|
||||
}
|
||||
};
|
||||
|
||||
if (isDropdownOpen) {
|
||||
checkPosition();
|
||||
}
|
||||
}, [isDropdownOpen]);
|
||||
function showTools() {
|
||||
dispatch(setDialogMessage(<ToolPermissionsDialog />));
|
||||
dispatch(setShowDialog(true));
|
||||
}
|
||||
|
||||
const isDisabled = props.disabled || isInEditMode;
|
||||
|
||||
|
|
@ -83,93 +68,18 @@ export default function ToolDropdown(props: ToolDropdownProps) {
|
|||
{useTools && !isDisabled && (
|
||||
<>
|
||||
<span className="hidden align-top sm:flex">Tools</span>
|
||||
|
||||
<div className="relative">
|
||||
<Listbox
|
||||
value={null}
|
||||
onChange={() => {}}
|
||||
as="div"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
disabled={isDisabled}
|
||||
>
|
||||
{({ open }) => (
|
||||
<>
|
||||
<Listbox.Button
|
||||
ref={buttonRef}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setDropdownOpen(!isDropdownOpen);
|
||||
}}
|
||||
className="text-lightgray flex cursor-pointer items-center border-none bg-transparent px-0 outline-none"
|
||||
aria-disabled={isDisabled}
|
||||
>
|
||||
<EllipsisHorizontalIcon className="h-3 w-3 cursor-pointer hover:brightness-125" />
|
||||
</Listbox.Button>
|
||||
<PopoverTransition
|
||||
show={open}
|
||||
afterLeave={() => setDropdownOpen(false)}
|
||||
>
|
||||
<Listbox.Options
|
||||
className={`bg-vsc-editor-background border-lightgray/50 absolute -left-32 z-50 mb-1 min-w-fit whitespace-nowrap rounded-md border border-solid px-1 py-0 shadow-lg ${showAbove ? "bottom-full" : ""}`}
|
||||
static
|
||||
>
|
||||
<div className="sticky">
|
||||
<div
|
||||
className="mb-1 flex items-center gap-2 px-2 py-1 text-xs"
|
||||
style={{
|
||||
color: vscForeground,
|
||||
borderBottom: `1px solid ${lightGray}`,
|
||||
}}
|
||||
>
|
||||
Tool policies{" "}
|
||||
<InfoHover
|
||||
id={"tool-policies"}
|
||||
size={"3"}
|
||||
msg={
|
||||
<div
|
||||
className="gap-0 *:m-1 *:text-left"
|
||||
style={{ fontSize: "10px" }}
|
||||
>
|
||||
<p>
|
||||
<span className="text-green-500">
|
||||
Automatic:
|
||||
</span>{" "}
|
||||
Can be used without asking
|
||||
</p>
|
||||
<p>
|
||||
<span className="text-yellow-500">
|
||||
Allowed:
|
||||
</span>{" "}
|
||||
Will ask before using
|
||||
</p>
|
||||
<p>
|
||||
<span className="text-red-500">
|
||||
Disabled:
|
||||
</span>{" "}
|
||||
Cannot be used
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="max-h-48 overflow-y-auto overflow-x-hidden pr-2">
|
||||
{availableTools.map((tool: any) => (
|
||||
<Listbox.Option
|
||||
key={tool.function.name}
|
||||
value="addAllFiles"
|
||||
className="text-vsc-foreground block w-full cursor-pointer text-left text-xs brightness-75 hover:brightness-125"
|
||||
>
|
||||
<ToolDropdownItem tool={tool} />
|
||||
</Listbox.Option>
|
||||
))}
|
||||
</div>
|
||||
</Listbox.Options>
|
||||
</PopoverTransition>
|
||||
</>
|
||||
)}
|
||||
</Listbox>
|
||||
<div
|
||||
data-tooltip-id="tools-permissions"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
showTools();
|
||||
}}
|
||||
className="text-lightgray flex cursor-pointer items-center"
|
||||
aria-disabled={isDisabled}
|
||||
>
|
||||
<EllipsisHorizontalIcon className="h-3 w-3 cursor-pointer hover:brightness-125" />
|
||||
</div>
|
||||
<ToolTip id="tools-permissions">Tool policies</ToolTip>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,17 +1,21 @@
|
|||
import { InformationCircleIcon } from "@heroicons/react/24/outline";
|
||||
import { Tool } from "core";
|
||||
import { useEffect } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { useAppSelector } from "../../../redux/hooks";
|
||||
import { addTool, toggleToolSetting } from "../../../redux/slices/uiSlice";
|
||||
import { RootState } from "../../../redux/store";
|
||||
import { ToolTip } from "../../gui/Tooltip";
|
||||
|
||||
interface ToolDropdownItemProps {
|
||||
tool: Tool;
|
||||
duplicatesDetected: boolean;
|
||||
excluded: boolean;
|
||||
}
|
||||
|
||||
function ToolDropdownItem(props: ToolDropdownItemProps) {
|
||||
const dispatch = useDispatch();
|
||||
const settings = useSelector(
|
||||
(state: RootState) => state.ui.toolSettings[props.tool.function.name],
|
||||
const settings = useAppSelector(
|
||||
(state) => state.ui.toolSettings[props.tool.function.name],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -26,39 +30,64 @@ function ToolDropdownItem(props: ToolDropdownItemProps) {
|
|||
|
||||
return (
|
||||
<div
|
||||
className="flex w-full items-center justify-between gap-2 px-2 py-1"
|
||||
className="text-vsc-foreground flex cursor-pointer items-center justify-between gap-2 py-1 text-left text-xs brightness-75 hover:brightness-125"
|
||||
onClick={(e) => {
|
||||
dispatch(toggleToolSetting(props.tool.function.name));
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}}
|
||||
>
|
||||
<span className="flex items-center gap-1">
|
||||
{props.tool.faviconUrl && (
|
||||
<img
|
||||
src={props.tool.faviconUrl}
|
||||
alt={props.tool.displayTitle}
|
||||
className="h-4 w-4"
|
||||
/>
|
||||
)}
|
||||
{props.tool.displayTitle}{" "}
|
||||
{/* <InfoHover
|
||||
id={`tool-policy-row-${props.tool.function.name}`}
|
||||
size={"3"}
|
||||
msg={props.tool.function.description}
|
||||
/> */}
|
||||
</span>
|
||||
<div className="flex cursor-pointer gap-2 pr-4">
|
||||
{(settings === "allowedWithPermission" || settings === undefined) && (
|
||||
<span className="text-yellow-500">Allowed</span>
|
||||
)}
|
||||
{settings === "allowedWithoutPermission" && (
|
||||
<span className="text-green-500">Automatic</span>
|
||||
)}
|
||||
{settings === "disabled" && (
|
||||
<span className="text-red-500">Disabled</span>
|
||||
)}
|
||||
<div className="flex flex-1 flex-row items-center gap-1">
|
||||
{props.duplicatesDetected ? (
|
||||
<>
|
||||
<div>
|
||||
<InformationCircleIcon
|
||||
data-tooltip-id={props.tool.displayTitle + "-duplicate-warning"}
|
||||
className="h-3 w-3 cursor-help text-yellow-500"
|
||||
/>
|
||||
</div>
|
||||
<ToolTip
|
||||
id={props.tool.displayTitle + "-duplicate-warning"}
|
||||
place="bottom"
|
||||
className="flex flex-wrap items-center"
|
||||
>
|
||||
<p className="m-0 p-0">
|
||||
<span>Duplicate tool name</span>{" "}
|
||||
<code>{props.tool.function.name}</code>{" "}
|
||||
<span>
|
||||
detected. Permissions will conflict and usage may be
|
||||
unpredictable
|
||||
</span>
|
||||
</p>
|
||||
</ToolTip>
|
||||
</>
|
||||
) : null}
|
||||
<span className="lines lines-1 flex items-center gap-1">
|
||||
{props.tool.faviconUrl && (
|
||||
<img
|
||||
src={props.tool.faviconUrl}
|
||||
alt={props.tool.displayTitle}
|
||||
className="h-4 w-4"
|
||||
/>
|
||||
)}
|
||||
{props.tool.function.name}{" "}
|
||||
</span>
|
||||
</div>
|
||||
{props.excluded ? (
|
||||
<span className="text-lightgray">Excluded</span>
|
||||
) : (
|
||||
<div className="flex cursor-pointer gap-2">
|
||||
{(settings === "allowedWithPermission" || settings === undefined) && (
|
||||
<span className="text-yellow-500">Ask First</span>
|
||||
)}
|
||||
{settings === "allowedWithoutPermission" && (
|
||||
<span className="text-green-500">Automatic</span>
|
||||
)}
|
||||
{settings === "disabled" && (
|
||||
<span className="text-lightgray">Excluded</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,101 @@
|
|||
import { Tool } from "core";
|
||||
import { useMemo } from "react";
|
||||
import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
|
||||
import { toggleToolGroupSetting } from "../../../redux/slices/uiSlice";
|
||||
import ToggleSwitch from "../../gui/Switch";
|
||||
import InfoHover from "../../InfoHover";
|
||||
import ToolDropdownItem from "./ToolDropdownItem";
|
||||
|
||||
const ToolPermissionsDialog = () => {
|
||||
const availableTools = useAppSelector((state) => state.config.config.tools);
|
||||
const toolGroupSettings = useAppSelector(
|
||||
(store) => store.ui.toolGroupSettings,
|
||||
);
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
const toolsByGroup = useMemo(() => {
|
||||
const byGroup: Record<string, Tool[]> = {};
|
||||
for (const tool of availableTools) {
|
||||
if (!byGroup[tool.group]) {
|
||||
byGroup[tool.group] = [];
|
||||
}
|
||||
byGroup[tool.group].push(tool);
|
||||
}
|
||||
return Object.entries(byGroup);
|
||||
}, [availableTools]);
|
||||
|
||||
// Detect duplicate tool names
|
||||
const duplicateDetection = useMemo(() => {
|
||||
const counts: Record<string, number> = {};
|
||||
availableTools.forEach((tool) => {
|
||||
if (counts[tool.function.name]) {
|
||||
counts[tool.function.name] = counts[tool.function.name] + 1;
|
||||
} else {
|
||||
counts[tool.function.name] = 1;
|
||||
}
|
||||
});
|
||||
return Object.fromEntries(
|
||||
Object.entries(counts).map(([k, v]) => [k, v > 1]),
|
||||
);
|
||||
}, [availableTools]);
|
||||
|
||||
return (
|
||||
<div className="px-1">
|
||||
<div className="text-vsc-foreground mb-1 flex items-center gap-2 px-2 py-2 text-xs">
|
||||
<h2 className="m-0 p-0 text-base">Tool policies</h2>
|
||||
<InfoHover
|
||||
id={"tool-policies"}
|
||||
size={"4"}
|
||||
msg={
|
||||
<div
|
||||
className="gap-0 *:m-1 *:text-left"
|
||||
style={{ fontSize: "10px" }}
|
||||
>
|
||||
<p>
|
||||
<span className="text-green-500">Automatic:</span> Can be used
|
||||
without asking
|
||||
</p>
|
||||
<p>
|
||||
<span className="text-yellow-500">Allowed:</span> Will ask
|
||||
before using
|
||||
</p>
|
||||
<p>
|
||||
<span className="text-red-500">Disabled:</span> Cannot be used
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex max-h-72 flex-col gap-2 divide-y divide-zinc-700 overflow-y-auto pl-1 pr-2">
|
||||
{toolsByGroup.map(([groupName, tools]) => (
|
||||
<div key={groupName} className="mt-2 flex flex-col">
|
||||
<div className="mb-1 flex flex-row items-center justify-between px-1">
|
||||
<h3 className="m-0 p-0 text-xs font-bold">{groupName}</h3>
|
||||
<ToggleSwitch
|
||||
isToggled={toolGroupSettings[groupName] !== "exclude"}
|
||||
onToggle={() => dispatch(toggleToolGroupSetting(groupName))}
|
||||
text=""
|
||||
size={12}
|
||||
/>
|
||||
</div>
|
||||
<div className="relative flex flex-col p-1">
|
||||
{tools.map((tool) => (
|
||||
<ToolDropdownItem
|
||||
key={tool.uri + tool.function.name}
|
||||
tool={tool}
|
||||
duplicatesDetected={duplicateDetection[tool.function.name]}
|
||||
excluded={toolGroupSettings[groupName] === "exclude"}
|
||||
/>
|
||||
))}
|
||||
{toolGroupSettings[groupName] === "exclude" && (
|
||||
<div className="absolute right-0 top-0 h-full w-full cursor-not-allowed"></div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ToolPermissionsDialog;
|
||||
|
|
@ -1,25 +1,8 @@
|
|||
import {
|
||||
ArrowRightIcon,
|
||||
ArrowUpOnSquareIcon,
|
||||
AtSymbolIcon,
|
||||
Bars3BottomLeftIcon,
|
||||
BoltIcon,
|
||||
BookOpenIcon,
|
||||
BugAntIcon,
|
||||
CircleStackIcon,
|
||||
CodeBracketIcon,
|
||||
CommandLineIcon,
|
||||
CpuChipIcon,
|
||||
DocumentTextIcon,
|
||||
ExclamationTriangleIcon,
|
||||
FolderIcon,
|
||||
FolderOpenIcon,
|
||||
GlobeAltIcon,
|
||||
MagnifyingGlassIcon,
|
||||
PaperClipIcon,
|
||||
PlusIcon,
|
||||
SparklesIcon,
|
||||
TrashIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { Editor } from "@tiptap/react";
|
||||
import {
|
||||
|
|
@ -46,50 +29,15 @@ import FileIcon from "../FileIcon";
|
|||
import SafeImg from "../SafeImg";
|
||||
import AddDocsDialog from "../dialogs/AddDocsDialog";
|
||||
import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip";
|
||||
import { DiscordIcon } from "../svg/DiscordIcon";
|
||||
import { GithubIcon } from "../svg/GithubIcon";
|
||||
import { GitlabIcon } from "../svg/GitlabIcon";
|
||||
import { GoogleIcon } from "../svg/GoogleIcon";
|
||||
import { NAMED_ICONS } from "./icons";
|
||||
import { ComboBoxItem, ComboBoxItemType } from "./types";
|
||||
|
||||
const ICONS_FOR_DROPDOWN: { [key: string]: any } = {
|
||||
file: FolderIcon,
|
||||
code: CodeBracketIcon,
|
||||
terminal: CommandLineIcon,
|
||||
diff: PlusIcon,
|
||||
search: MagnifyingGlassIcon,
|
||||
url: GlobeAltIcon,
|
||||
open: FolderOpenIcon,
|
||||
codebase: SparklesIcon,
|
||||
problems: ExclamationTriangleIcon,
|
||||
folder: FolderIcon,
|
||||
docs: BookOpenIcon,
|
||||
web: GlobeAltIcon,
|
||||
clipboard: PaperClipIcon,
|
||||
database: CircleStackIcon,
|
||||
postgres: CircleStackIcon,
|
||||
debugger: BugAntIcon,
|
||||
os: CpuChipIcon,
|
||||
tree: Bars3BottomLeftIcon,
|
||||
"prompt-files": DocumentTextIcon,
|
||||
"repo-map": FolderIcon,
|
||||
"/clear": TrashIcon,
|
||||
"/share": ArrowUpOnSquareIcon,
|
||||
"/cmd": CommandLineIcon,
|
||||
issue: GithubIcon,
|
||||
discord: DiscordIcon,
|
||||
google: GoogleIcon,
|
||||
"gitlab-mr": GitlabIcon,
|
||||
http: GlobeAltIcon,
|
||||
trash: TrashIcon,
|
||||
};
|
||||
|
||||
export function getIconFromDropdownItem(
|
||||
id: string | undefined,
|
||||
type: ComboBoxItemType,
|
||||
) {
|
||||
const typeIcon = type === "contextProvider" ? AtSymbolIcon : BoltIcon;
|
||||
return id ? (ICONS_FOR_DROPDOWN[id] ?? typeIcon) : typeIcon;
|
||||
return id ? (NAMED_ICONS[id] ?? typeIcon) : typeIcon;
|
||||
}
|
||||
|
||||
function DropdownIcon(props: { className?: string; item: ComboBoxItem }) {
|
||||
|
|
|
|||
56
gui/src/components/mainInput/icons.ts
Normal file
56
gui/src/components/mainInput/icons.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import {
|
||||
ArrowUpOnSquareIcon,
|
||||
Bars3BottomLeftIcon,
|
||||
BookOpenIcon,
|
||||
BugAntIcon,
|
||||
CircleStackIcon,
|
||||
CodeBracketIcon,
|
||||
CommandLineIcon,
|
||||
CpuChipIcon,
|
||||
DocumentTextIcon,
|
||||
ExclamationTriangleIcon,
|
||||
FolderIcon,
|
||||
FolderOpenIcon,
|
||||
GlobeAltIcon,
|
||||
MagnifyingGlassIcon,
|
||||
PaperClipIcon,
|
||||
PlusIcon,
|
||||
SparklesIcon,
|
||||
TrashIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { DiscordIcon } from "../svg/DiscordIcon";
|
||||
import { GithubIcon } from "../svg/GithubIcon";
|
||||
import { GitlabIcon } from "../svg/GitlabIcon";
|
||||
import { GoogleIcon } from "../svg/GoogleIcon";
|
||||
|
||||
export const NAMED_ICONS: { [key: string]: any } = {
|
||||
file: FolderIcon,
|
||||
code: CodeBracketIcon,
|
||||
terminal: CommandLineIcon,
|
||||
diff: PlusIcon,
|
||||
search: MagnifyingGlassIcon,
|
||||
url: GlobeAltIcon,
|
||||
open: FolderOpenIcon,
|
||||
codebase: SparklesIcon,
|
||||
problems: ExclamationTriangleIcon,
|
||||
folder: FolderIcon,
|
||||
docs: BookOpenIcon,
|
||||
web: GlobeAltIcon,
|
||||
clipboard: PaperClipIcon,
|
||||
database: CircleStackIcon,
|
||||
postgres: CircleStackIcon,
|
||||
debugger: BugAntIcon,
|
||||
os: CpuChipIcon,
|
||||
tree: Bars3BottomLeftIcon,
|
||||
"prompt-files": DocumentTextIcon,
|
||||
"repo-map": FolderIcon,
|
||||
"/clear": TrashIcon,
|
||||
"/share": ArrowUpOnSquareIcon,
|
||||
"/cmd": CommandLineIcon,
|
||||
issue: GithubIcon,
|
||||
discord: DiscordIcon,
|
||||
google: GoogleIcon,
|
||||
"gitlab-mr": GitlabIcon,
|
||||
http: GlobeAltIcon,
|
||||
trash: TrashIcon,
|
||||
};
|
||||
190
gui/src/pages/More/MCPServersPreview.tsx
Normal file
190
gui/src/pages/More/MCPServersPreview.tsx
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
import {
|
||||
ArrowPathIcon,
|
||||
CircleStackIcon,
|
||||
CommandLineIcon,
|
||||
InformationCircleIcon,
|
||||
WrenchScrewdriverIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { MCPServerStatus } from "core";
|
||||
import { useContext } from "react";
|
||||
import { SecondaryButton } from "../../components";
|
||||
import { ToolTip } from "../../components/gui/Tooltip";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
import { updateConfig } from "../../redux/slices/configSlice";
|
||||
|
||||
interface MCPServerStatusProps {
|
||||
server: MCPServerStatus;
|
||||
}
|
||||
function MCPServerPreview({ server }: MCPServerStatusProps) {
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const config = useAppSelector((store) => store.config.config);
|
||||
const dispatch = useAppDispatch();
|
||||
const toolsTooltipId = `${server.id}-tools`;
|
||||
const promptsTooltipId = `${server.id}-prompts`;
|
||||
const resourcesTooltipId = `${server.id}-resources`;
|
||||
const errorsTooltipId = `${server.id}-errors`;
|
||||
|
||||
async function onRefresh() {
|
||||
// optimistic config update
|
||||
dispatch(
|
||||
updateConfig({
|
||||
...config,
|
||||
mcpServerStatuses: config.mcpServerStatuses.map((s) =>
|
||||
s.id === server.id
|
||||
? {
|
||||
...s,
|
||||
status: "connecting",
|
||||
}
|
||||
: s,
|
||||
),
|
||||
}),
|
||||
);
|
||||
ideMessenger.post("mcp/reloadServer", {
|
||||
id: server.id,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-1.5 pb-4">
|
||||
<h3 className="m-0 mb-1 text-xs sm:text-sm">{server.name}</h3>
|
||||
<div className="flex flex-row items-center justify-between gap-3">
|
||||
<div className="flex flex-row items-center gap-2">
|
||||
{server.status === "not-connected" ? (
|
||||
<div className="flex flex-row items-center gap-2">
|
||||
<div className="hidden h-2 w-2 rounded-full bg-stone-500 sm:flex"></div>
|
||||
<span>Not connected</span>
|
||||
</div>
|
||||
) : server.status === "connected" ? (
|
||||
<div className="flex flex-row items-center gap-2">
|
||||
<div className="hidden h-2 w-2 rounded-full bg-green-500 sm:flex"></div>
|
||||
<span className="">Connected</span>
|
||||
</div>
|
||||
) : server.status === "connecting" ? (
|
||||
<div className="flex flex-row items-center gap-2">
|
||||
<div className="hidden h-2 w-2 rounded-full bg-yellow-500 sm:flex"></div>
|
||||
<span>Connecting...</span>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-row items-center gap-2">
|
||||
<div className="hidden h-2 w-2 rounded-full bg-red-500 sm:flex"></div>
|
||||
<span>Error</span>
|
||||
</div>
|
||||
)}
|
||||
{server.errors.length ? (
|
||||
<>
|
||||
<InformationCircleIcon
|
||||
className={`h-3 w-3 ${server.status === "error" ? "text-red-500" : "text-yellow-500"}`}
|
||||
data-tooltip-id={errorsTooltipId}
|
||||
/>
|
||||
<ToolTip id={errorsTooltipId} className="flex flex-col gap-0.5">
|
||||
{server.errors.map((error, idx) => (
|
||||
<code key={idx}>{error}</code>
|
||||
))}
|
||||
{server.errors.length === 0 ? (
|
||||
<span className="text-stone-500">No known errors</span>
|
||||
) : null}
|
||||
</ToolTip>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
<div
|
||||
className="text-lightgray flex cursor-pointer flex-row items-center gap-2 underline hover:opacity-80"
|
||||
onClick={onRefresh}
|
||||
>
|
||||
<div>
|
||||
<ArrowPathIcon className="h-3 w-3" />
|
||||
</div>
|
||||
<span className="hidden sm:flex">Refresh</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="relative flex flex-row flex-wrap items-center gap-4">
|
||||
{/* Tools */}
|
||||
<div
|
||||
className="flex cursor-zoom-in flex-row items-center gap-2 hover:opacity-80"
|
||||
data-tooltip-id={toolsTooltipId}
|
||||
>
|
||||
<WrenchScrewdriverIcon className="h-4 w-4" />
|
||||
<span>{`Tools: ${server.tools.length}`}</span>
|
||||
</div>
|
||||
<ToolTip id={toolsTooltipId} className="flex flex-col gap-0.5">
|
||||
{server.tools.map((tool, idx) => (
|
||||
<code key={idx}>{tool.name}</code>
|
||||
))}
|
||||
{server.tools.length === 0 ? (
|
||||
<span className="text-stone-500">No tools</span>
|
||||
) : null}
|
||||
</ToolTip>
|
||||
|
||||
{/* Prompts */}
|
||||
<div
|
||||
className="flex cursor-zoom-in flex-row items-center gap-2 hover:opacity-80"
|
||||
data-tooltip-id={promptsTooltipId}
|
||||
>
|
||||
<CommandLineIcon className="h-4 w-4" />
|
||||
<span>{`Prompts: ${server.prompts.length}`}</span>
|
||||
</div>
|
||||
<ToolTip id={promptsTooltipId} className="flex flex-col gap-0.5">
|
||||
{server.prompts.map((prompt, idx) => (
|
||||
<code key={idx}>{prompt.name}</code>
|
||||
))}
|
||||
{server.prompts.length === 0 ? (
|
||||
<span className="text-stone-500">No prompts</span>
|
||||
) : null}
|
||||
</ToolTip>
|
||||
{/* Resources */}
|
||||
<div
|
||||
className="flex cursor-zoom-in flex-row items-center gap-2 hover:opacity-80"
|
||||
data-tooltip-id={resourcesTooltipId}
|
||||
>
|
||||
<CircleStackIcon className="h-4 w-4" />
|
||||
<span>{`Resources: ${server.resources.length}`}</span>
|
||||
</div>
|
||||
<ToolTip id={resourcesTooltipId} className="flex flex-col gap-0.5">
|
||||
{server.resources.map((resource, idx) => (
|
||||
<code key={idx}>{resource.name}</code>
|
||||
))}
|
||||
{server.resources.length === 0 ? (
|
||||
<span className="text-stone-500">No resources</span>
|
||||
) : null}
|
||||
</ToolTip>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
function MCPServersPreview() {
|
||||
const servers = useAppSelector(
|
||||
(store) => store.config.config.mcpServerStatuses,
|
||||
);
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex flex-row items-center justify-between">
|
||||
<h3 className="mb-0 mt-0 text-lg">MCP Servers</h3>
|
||||
</div>
|
||||
|
||||
<div className="flex max-h-[170px] flex-col gap-1 overflow-y-auto overflow-x-hidden pr-2">
|
||||
<div>
|
||||
{servers.length === 0 && (
|
||||
<SecondaryButton
|
||||
className="flex h-7 flex-col items-center justify-center"
|
||||
onClick={() => {
|
||||
ideMessenger.post("config/openProfile", {
|
||||
profileId: undefined,
|
||||
});
|
||||
}}
|
||||
>
|
||||
Add MCP Servers
|
||||
</SecondaryButton>
|
||||
)}
|
||||
</div>
|
||||
{servers.map((server, idx) => (
|
||||
<MCPServerPreview key={idx} server={server} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default MCPServersPreview;
|
||||
|
|
@ -15,6 +15,7 @@ import { saveCurrentSession } from "../../redux/thunks/session";
|
|||
import { AccountButton } from "../config/AccountButton";
|
||||
import IndexingProgress from "./IndexingProgress";
|
||||
import KeyboardShortcuts from "./KeyboardShortcuts";
|
||||
import MCPServersPreview from "./MCPServersPreview";
|
||||
import MoreHelpRow from "./MoreHelpRow";
|
||||
import { RulesPreview } from "./RulesPreview";
|
||||
|
||||
|
|
@ -66,6 +67,10 @@ function MorePage() {
|
|||
<RulesPreview />
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col py-5">
|
||||
<MCPServersPreview />
|
||||
</div>
|
||||
|
||||
<div className="py-5">
|
||||
<h3 className="mb-4 mt-0 text-xl">Help center</h3>
|
||||
<div className="-mx-4 flex flex-col">
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ export function ToolCallDisplay(props: ToolCallDisplayProps) {
|
|||
tool.wouldLikeTo,
|
||||
props.toolCallState.parsedArgs,
|
||||
);
|
||||
return rendered;
|
||||
return rendered.trim();
|
||||
}, [props.toolCallState, tool]);
|
||||
|
||||
const args: [string, any][] = useMemo(() => {
|
||||
|
|
@ -61,7 +61,15 @@ export function ToolCallDisplay(props: ToolCallDisplayProps) {
|
|||
<img src={tool.faviconUrl} className="h-4 w-4 rounded-sm" />
|
||||
)}
|
||||
<div className="">
|
||||
Continue wants to <span>{wouldLikeToMessage.trim()}</span>
|
||||
Continue wants to{" "}
|
||||
{wouldLikeToMessage ? (
|
||||
<span>{wouldLikeToMessage}</span>
|
||||
) : (
|
||||
<>
|
||||
<span>use the</span> <code>{tool?.displayTitle}</code>{" "}
|
||||
<span>tool</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{!!args.length ? (
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ const EMPTY_CONFIG: BrowserSerializedContinueConfig = {
|
|||
contextProviders: [],
|
||||
models: [],
|
||||
tools: [],
|
||||
mcpServerStatuses: [],
|
||||
usePlatform: true,
|
||||
modelsByRole: {
|
||||
chat: [],
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ type ToolSetting =
|
|||
| "allowedWithoutPermission"
|
||||
| "disabled";
|
||||
|
||||
type ToolGroupSetting = "include" | "exclude";
|
||||
|
||||
type UIState = {
|
||||
showDialog: boolean;
|
||||
dialogMessage: string | JSX.Element | undefined;
|
||||
|
|
@ -22,6 +24,7 @@ type UIState = {
|
|||
shouldAddFileForEditing: boolean;
|
||||
useTools: boolean;
|
||||
toolSettings: { [toolName: string]: ToolSetting };
|
||||
toolGroupSettings: { [toolGroupName: string]: ToolGroupSetting };
|
||||
ttsActive: boolean;
|
||||
};
|
||||
|
||||
|
|
@ -51,6 +54,9 @@ export const uiSlice = createSlice({
|
|||
[BuiltInToolNames.SearchWeb]: "allowedWithoutPermission",
|
||||
[BuiltInToolNames.ViewDiff]: "allowedWithoutPermission",
|
||||
},
|
||||
toolGroupSettings: {
|
||||
BUILT_IN_GROUP_NAME: "include",
|
||||
},
|
||||
} as UIState,
|
||||
reducers: {
|
||||
setOnboardingCard: (
|
||||
|
|
@ -109,6 +115,15 @@ export const uiSlice = createSlice({
|
|||
break;
|
||||
}
|
||||
},
|
||||
toggleToolGroupSetting: (state, action: PayloadAction<string>) => {
|
||||
const setting = state.toolGroupSettings[action.payload] ?? "include";
|
||||
|
||||
if (setting === "include") {
|
||||
state.toolGroupSettings[action.payload] = "exclude";
|
||||
} else {
|
||||
state.toolGroupSettings[action.payload] = "include";
|
||||
}
|
||||
},
|
||||
setTTSActive: (state, { payload }: PayloadAction<boolean>) => {
|
||||
state.ttsActive = payload;
|
||||
},
|
||||
|
|
@ -124,6 +139,7 @@ export const {
|
|||
setHasDismissedExploreDialog,
|
||||
toggleUseTools,
|
||||
toggleToolSetting,
|
||||
toggleToolGroupSetting,
|
||||
addTool,
|
||||
setTTSActive,
|
||||
} = uiSlice.actions;
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ const saveSubsetFilters = [
|
|||
// Don't persist any of the edit state for now
|
||||
createFilter("editModeState", []),
|
||||
createFilter("config", ["defaultModelTitle"]),
|
||||
createFilter("ui", ["toolSettings", "useTools"]),
|
||||
createFilter("ui", ["toolSettings", "toolGroupSettings", "useTools"]),
|
||||
createFilter("indexing", []),
|
||||
createFilter("tabs", ["tabs"]),
|
||||
];
|
||||
|
|
|
|||
|
|
@ -57,10 +57,11 @@ export const callTool = createAsyncThunk<void, undefined, ThunkApiType>(
|
|||
toolCallId: toolCallState.toolCallId,
|
||||
toolOutput: [
|
||||
{
|
||||
name: "Tool Call Failed",
|
||||
icon: "problems",
|
||||
name: "Tool Call Error",
|
||||
description: "Tool Call Failed",
|
||||
content: `The tool call failed with the message:\n\n${result.error}\n\nPlease try something else or request further instructions.`,
|
||||
hidden: true,
|
||||
hidden: false,
|
||||
},
|
||||
],
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ export const streamNormalInput = createAsyncThunk<
|
|||
const state = getState();
|
||||
const defaultModel = selectDefaultModel(state);
|
||||
const toolSettings = state.ui.toolSettings;
|
||||
const toolGroupSettings = state.ui.toolGroupSettings;
|
||||
const streamAborter = state.session.streamAborter;
|
||||
const useTools = state.ui.useTools;
|
||||
if (!defaultModel) {
|
||||
|
|
@ -47,7 +48,9 @@ export const streamNormalInput = createAsyncThunk<
|
|||
completionOptions: includeTools
|
||||
? {
|
||||
tools: state.config.config.tools.filter(
|
||||
(tool) => toolSettings[tool.function.name] !== "disabled",
|
||||
(tool) =>
|
||||
toolSettings[tool.function.name] !== "disabled" &&
|
||||
toolGroupSettings[tool.group] !== "exclude",
|
||||
),
|
||||
}
|
||||
: {},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue