Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix(chat): surface custom MCP connectors in the @ mention picker (#16685)

Arvin Xu70f3665e0b21
diff --git a/apps/server/src/routers/lambda/aiAgent.ts b/apps/server/src/routers/lambda/aiAgent.ts
index ce89027b7e3..91fcdec0f9f 100644
--- a/apps/server/src/routers/lambda/aiAgent.ts
+++ b/apps/server/src/routers/lambda/aiAgent.ts
@@ -191,6 +191,14 @@ const ExecAgentSchema = z
toolCallId: z.string(),
})
.optional(),
+ /**
+ * Tool identifiers the user @-mentioned in this message. Enabled for this
+ * run in addition to the agent's pinned plugins, so a mentioned tool that
+ * isn't pinned to the agent (e.g. a custom MCP connector picked from the @
+ * list) is callable. Scoped to the caller's own installed tools/connectors
+ * by the user-scoped lookups downstream, so it can't enable others' tools.
+ */
+ selectedToolIds: z.array(z.string()).optional(),
/** The agent slug to run (either agentId or slug is required) */
slug: z.string().optional(),
/**
@@ -680,6 +688,7 @@ export const aiAgentRouter = router({
fileIds,
parentMessageId,
resumeApproval,
+ selectedToolIds,
trigger,
userInterventionConfig,
} = input;
@@ -700,6 +709,7 @@ export const aiAgentRouter = router({
// human-approval resume β€” either way, skip user message creation.
resume: !!parentMessageId,
resumeApproval,
+ selectedToolIds,
slug,
trigger: trigger ?? RequestTrigger.Chat,
userInterventionConfig,
diff --git a/apps/server/src/services/aiAgent/index.ts b/apps/server/src/services/aiAgent/index.ts
index 1235246cfd4..a6498a8763b 100644
--- a/apps/server/src/services/aiAgent/index.ts
+++ b/apps/server/src/services/aiAgent/index.ts
@@ -320,6 +320,14 @@ interface InternalExecAgentParams extends ExecAgentParams {
rejectionReason?: string;
toolCallId: string;
};
+ /**
+ * Tool identifiers the user @-mentioned in this message. Merged into the
+ * agent's plugin set for this run (alongside `additionalPluginIds`) so a
+ * mentioned tool that isn't pinned to the agent β€” e.g. a custom MCP connector
+ * picked from the @ list β€” is enabled and callable. User-scoped lookups
+ * downstream (connectors, installed plugins) keep it to the caller's own tools.
+ */
+ selectedToolIds?: string[];
/** Abort startup before the agent runtime operation is created */
signal?: AbortSignal;
/**
@@ -912,6 +920,7 @@ export class AiAgentService {
parentOperationId,
resume,
resumeApproval,
+ selectedToolIds,
suppressUserMessage,
ephemeralUserMessage,
} = params;
@@ -2006,7 +2015,17 @@ export class AiAgentService {
let lobehubSkillManifests: LobeToolManifest[] = [];
let composioManifests: LobeToolManifest[] = [];
let connectorManifests: ReturnType<typeof buildConnectorManifests> = [];
- let agentPlugins: string[] = [...(agentConfig?.plugins ?? []), ...(additionalPluginIds || [])];
+ // `selectedToolIds` are the user's @-mention picks for this turn; merged in
+ // (deduped) alongside the agent's pinned plugins and any internal
+ // `additionalPluginIds` so a mentioned-but-not-pinned tool (e.g. a custom MCP
+ // connector) is both queried for manifests and enabled by the tools engine.
+ let agentPlugins: string[] = [
+ ...new Set([
+ ...(agentConfig?.plugins ?? []),
+ ...(additionalPluginIds || []),
+ ...(selectedToolIds || []),
+ ]),
+ ];
// Model metadata is needed both for tool support checks and agent-management context.
const { loadModels } = await import('@/business/client/model-bank/loadModels');
diff --git a/src/features/ChatInput/InputEditor/ActionTag/useInstalledSkillsAndTools.ts b/src/features/ChatInput/InputEditor/ActionTag/useInstalledSkillsAndTools.ts
index 4b2f90b6b93..751bc0277a6 100644
--- a/src/features/ChatInput/InputEditor/ActionTag/useInstalledSkillsAndTools.ts
+++ b/src/features/ChatInput/InputEditor/ActionTag/useInstalledSkillsAndTools.ts
@@ -9,6 +9,7 @@ import {
lobehubSkillStoreSelectors,
pluginSelectors,
} from '@/store/tool/selectors';
+import { connectorSelectors } from '@/store/tool/slices/connector';
import type { ActionTagData } from './types';
@@ -19,6 +20,7 @@ import type { ActionTagData } from './types';
*/
export const useInstalledSkillsAndTools = (): ActionTagData[] => {
const builtinSkills = useToolStore(builtinToolSelectors.installedBuiltinSkills, isEqual);
+ const customConnectors = useToolStore(connectorSelectors.customConnectors, isEqual);
const installedPlugins = useToolStore(pluginSelectors.installedPluginMetaList, isEqual);
const composioServers = useToolStore(composioStoreSelectors.getServers, isEqual);
const lobehubSkillServers = useToolStore(lobehubSkillStoreSelectors.getServers, isEqual);
@@ -63,6 +65,19 @@ export const useInstalledSkillsAndTools = (): ActionTagData[] => {
// --- Build tool set, excluding identifiers already classified as skills ---
const toolMap = new Map<string, { icon?: string; label: string }>();
+ // Custom connectors (user-added MCP servers) first: they take priority over
+ // a legacy plugin sharing the same identifier, mirroring toolEngineering's
+ // connector-over-plugin rule. Only enabled connectors with synced tools are
+ // in the tools engine (buildClientConnectorManifests), so match that here β€”
+ // otherwise the picker would offer a mention that resolves to nothing.
+ for (const item of customConnectors) {
+ if (!item.isEnabled || (item.tools?.length ?? 0) === 0) continue;
+ if (skillMap.has(item.identifier)) continue;
+ if (!toolMap.has(item.identifier)) {
+ toolMap.set(item.identifier, { label: item.name || item.identifier });
+ }
+ }
+
for (const item of installedPlugins) {
// Skip entries that are actually skills (lobehub skill, agent skill, builtin skill)
if (skillMap.has(item.identifier)) continue;
@@ -91,6 +106,7 @@ export const useInstalledSkillsAndTools = (): ActionTagData[] => {
return items;
}, [
builtinSkills,
+ customConnectors,
installedPlugins,
composioServers,
lobehubSkillServers,
diff --git a/src/features/Verify/Workspace/ReportListPanel.tsx b/src/features/Verify/Workspace/ReportListPanel.tsx
index 4e45f1f22c7..e4668f38f4e 100644
--- a/src/features/Verify/Workspace/ReportListPanel.tsx
+++ b/src/features/Verify/Workspace/ReportListPanel.tsx
@@ -185,6 +185,7 @@ const styles = createStaticStyles(({ css }) => ({
`,
itemTitle: css`
overflow: hidden;
+ display: block;
font-size: 13px;
line-height: 1.4;
diff --git a/src/routes/(main)/agent/_layout/Sidebar/Topic/List/index.test.tsx b/src/routes/(main)/agent/_layout/Sidebar/Topic/List/index.test.tsx
index 622171eb651..8cda123a982 100644
--- a/src/routes/(main)/agent/_layout/Sidebar/Topic/List/index.test.tsx
+++ b/src/routes/(main)/agent/_layout/Sidebar/Topic/List/index.test.tsx
@@ -104,7 +104,13 @@ vi.mock('../TopicListContent/FlatMode', () => ({
default: () => <div data-testid="flat-mode" />,
}));
-vi.mock('@lobehub/ui', () => ({
+// Partial mock: keep every real export (e.g. `lobeStaticStylish`, which
+// `createStaticStyles` reads at import time in transitively-loaded modules like
+// ShareModal/useContainerStyles) and override only Flexbox. A full mock returning
+// just Flexbox drops those exports and crashes collection whenever the suite's
+// module graph evaluates one of them.
+vi.mock('@lobehub/ui', async (importOriginal) => ({
+ ...(await importOriginal<Record<string, unknown>>()),
Flexbox: ({ children }: { children?: ReactNode }) => <div>{children}</div>,
}));
diff --git a/src/services/aiAgent.ts b/src/services/aiAgent.ts
index 8e1073dbbef..c6196b9a4bd 100644
--- a/src/services/aiAgent.ts
+++ b/src/services/aiAgent.ts
@@ -37,6 +37,8 @@ export interface ExecAgentTaskParams {
prompt: string;
/** Resume a previous op paused on `human_approve_required` instead of starting from a fresh user prompt. */
resumeApproval?: ResumeApprovalParam;
+ /** Tool identifiers the user @-mentioned in this message; the server enables them for this run. */
+ selectedToolIds?: string[];
slug?: string;
/**
* Override what initiated this operation. Server defaults to `'chat'` when
diff --git a/src/store/chat/slices/agentRun/actions/entries/conversationLifecycle.ts b/src/store/chat/slices/agentRun/actions/entries/conversationLifecycle.ts
index ef4e9894be7..7f6081d1b8d 100644
--- a/src/store/chat/slices/agentRun/actions/entries/conversationLifecycle.ts
+++ b/src/store/chat/slices/agentRun/actions/entries/conversationLifecycle.ts
@@ -909,6 +909,11 @@ export class ConversationLifecycleActionImpl {
metadata: requestMetadata,
parentOperationId: operationId,
optimisticTopic,
+ // Forward @-mentioned tool ids so the server runtime enables them for
+ // this run β€” the gateway/server path otherwise never sees the mention
+ // selection (only the client runtime did). Omit when empty.
+ selectedToolIds:
+ selectedTools.length > 0 ? selectedTools.map((tool) => tool.identifier) : undefined,
// Pass temp message IDs so the UI doesn't show a blank loading
// state while waiting for the first step_start event to replace
// messages with the server's real IDs.
diff --git a/src/store/chat/slices/agentRun/actions/transports/client/streamingExecutor.ts b/src/store/chat/slices/agentRun/actions/transports/client/streamingExecutor.ts
index 43f05981967..84f11c96a98 100644
--- a/src/store/chat/slices/agentRun/actions/transports/client/streamingExecutor.ts
+++ b/src/store/chat/slices/agentRun/actions/transports/client/streamingExecutor.ts
@@ -217,7 +217,13 @@ export class StreamingExecutorActionImpl {
// When disableTools is true (broadcast mode), skipDefaultTools prevents default tools from being added
const toolsEngine = createAgentToolsEngine(
{ model: agentConfigData.model, provider: agentConfigData.provider! },
- effectivePluginIds,
+ // Use `mergedToolIds` (not `effectivePluginIds`) so the enable rules cover
+ // user-selected @-mention ids too β€” the same id set `generateToolsDetailed`
+ // receives below. Otherwise a mentioned tool that isn't pinned to the agent
+ // (e.g. a custom MCP connector picked from the @ list) would have its
+ // manifest included but be defaulted to disabled by the enable checker, so
+ // no function tools are sent. `platformFilter` still gates availability.
+ mergedToolIds,
// Context-aware builtin manifests: lobe-agent hides callSubAgent in group /
// sub-agent runs. Replaces the former dropSubAgentInGroup + applyPluginFilters
// isSubAgent hard-coding.
diff --git a/src/store/chat/slices/agentRun/actions/transports/gateway/gateway.ts b/src/store/chat/slices/agentRun/actions/transports/gateway/gateway.ts
index 76ffcce8ffc..cd99697c391 100644
--- a/src/store/chat/slices/agentRun/actions/transports/gateway/gateway.ts
+++ b/src/store/chat/slices/agentRun/actions/transports/gateway/gateway.ts
@@ -391,6 +391,14 @@ export class GatewayActionImpl {
* a fresh user prompt.
*/
resumeApproval?: ResumeApprovalParam;
+ /**
+ * Tool identifiers the user @-mentioned in this message. Forwarded to the
+ * server as `selectedToolIds` so the server runtime enables them for this
+ * run (mirrors the client runtime's mention β†’ callable-tool wiring). Lets a
+ * user invoke a tool that isn't pinned to the agent (e.g. a custom MCP
+ * connector picked from the @ list).
+ */
+ selectedToolIds?: string[];
/**
* Temporary message IDs created during the initial sendMessage phase.
* These are associated with the new gateway operation so the UI doesn't
@@ -409,6 +417,7 @@ export class GatewayActionImpl {
parentMessageId,
parentOperationId,
resumeApproval,
+ selectedToolIds,
tempMessageIds,
} = params;
@@ -477,6 +486,7 @@ export class GatewayActionImpl {
parentMessageId,
prompt: message,
resumeApproval,
+ selectedToolIds,
trigger: metadata?.trigger,
userInterventionConfig,
},