Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(open-knowledge): open MCP consent dialog on menu re-trigger (#1785)

Andrew Mikofalvyae805a1290f5
diff --git a/.changeset/mcp-consent-menu-immediate-dialog.md b/.changeset/mcp-consent-menu-immediate-dialog.md
new file mode 100644
index 000000000..31d2d1f01
--- /dev/null
+++ b/.changeset/mcp-consent-menu-immediate-dialog.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge-desktop": patch
+---
+
+File → Configure AI Tool Integrations… now opens the consent dialog immediately in the focused window (editor or project switcher). Previously the click armed the dialog silently and it only appeared in the next window the app opened, so clicking the menu item with a window already in front did nothing visible.
diff --git a/packages/desktop/src/main/index.ts b/packages/desktop/src/main/index.ts
index ab7654e95..1191fdbaf 100644
--- a/packages/desktop/src/main/index.ts
+++ b/packages/desktop/src/main/index.ts
@@ -155,6 +155,7 @@ import {
checkAndRepairMcpWiringOnStartup,
type McpStartupRepairResult,
type McpWiringCliSurface,
+ type McpWiringDispatchTarget,
type RunMcpWiringHandle,
runMcpWiringOnFirstLaunch,
} from './mcp-wiring.ts';
@@ -1148,7 +1149,10 @@ async function runApplicationMenuRefresh(): Promise<void> {
mcpWiringHandle?.destroy();
mcpWiringHandle = null;
try {
- mcpWiringHandle = armMcpWiring({ forceShow: true });
+ mcpWiringHandle = armMcpWiring({
+ forceShow: true,
+ immediateDispatchTarget: pickLoadedRendererForMcpDialog(),
+ });
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
console.error('[main] reconfigureMcpWiring failed', { err: message });
@@ -1254,7 +1258,12 @@ function createProjectMcpReclaimCliSurface(): ProjectMcpReclaimCliSurface {
};
}
-function createMcpWiringOpts(opts: { forceShow?: boolean } = {}) {
+interface ArmMcpWiringOpts {
+ forceShow?: boolean;
+ immediateDispatchTarget?: McpWiringDispatchTarget;
+}
+
+function createMcpWiringOpts(opts: ArmMcpWiringOpts = {}) {
return {
isPackaged: app.isPackaged,
executablePath: app.getPath('exe'),
@@ -1265,10 +1274,11 @@ function createMcpWiringOpts(opts: { forceShow?: boolean } = {}) {
forceEnv: process.env.OK_M6B_FORCE ?? null,
reclaimDisableEnv: process.env.OK_RECLAIM_DISABLE ?? null,
forceShow: opts.forceShow ?? false,
+ immediateDispatchTarget: opts.immediateDispatchTarget,
};
}
-function armMcpWiring(opts: { forceShow?: boolean } = {}): RunMcpWiringHandle {
+function armMcpWiring(opts: ArmMcpWiringOpts = {}): RunMcpWiringHandle {
return runMcpWiringOnFirstLaunch(createMcpWiringOpts(opts));
}
@@ -1276,6 +1286,14 @@ function formatUnknownError(err: unknown): string {
return err instanceof Error ? err.message : String(err);
}
+function pickLoadedRendererForMcpDialog(): McpWiringDispatchTarget | undefined {
+ const isUsable = (win: BrowserWindow): boolean =>
+ !win.isDestroyed() && !win.webContents.isLoading();
+ const focused = BrowserWindow.getFocusedWindow();
+ if (focused && isUsable(focused)) return focused.webContents;
+ return BrowserWindow.getAllWindows().find(isUsable)?.webContents;
+}
+
function dispatchStartupReclaimToastWhenReady(results: {
mcp: McpStartupRepairResult;
path: EnsureCliOnPathResult;
diff --git a/packages/desktop/src/main/mcp-wiring.test.ts b/packages/desktop/src/main/mcp-wiring.test.ts
index ba07a469b..05195736f 100644
--- a/packages/desktop/src/main/mcp-wiring.test.ts
+++ b/packages/desktop/src/main/mcp-wiring.test.ts
@@ -9,8 +9,10 @@ import {
checkAndRepairMcpWiringOnStartup,
type McpStatusMarker,
type McpWiringCliSurface,
+ type McpWiringDispatchTarget,
type McpWiringFsOps,
readMcpStatusMarker,
+ runMcpWiringOnFirstLaunch,
writeMcpStatusMarker,
} from './mcp-wiring.ts';
@@ -185,3 +187,216 @@ describe('MCP status marker', () => {
});
});
});
+
+type WiringOpts = Parameters<typeof runMcpWiringOnFirstLaunch>[0];
+
+function stubIpcMain(): WiringOpts['ipcMain'] & {
+ handlers: Map<string, (...args: unknown[]) => unknown>;
+} {
+ const handlers = new Map<string, (...args: unknown[]) => unknown>();
+ return {
+ handlers,
+ handle(channel: string, fn: (...args: unknown[]) => unknown) {
+ handlers.set(channel, fn);
+ },
+ removeHandler(channel: string) {
+ handlers.delete(channel);
+ },
+ } as unknown as WiringOpts['ipcMain'] & {
+ handlers: Map<string, (...args: unknown[]) => unknown>;
+ };
+}
+
+function fakeWebContents(
+ id: number,
+ opts: { failSend?: boolean } = {},
+): McpWiringDispatchTarget & { sent: Array<{ channel: string; payload: unknown }> } {
+ const sent: Array<{ channel: string; payload: unknown }> = [];
+ return {
+ id,
+ sent,
+ send(channel: string, payload?: unknown) {
+ if (opts.failSend) throw new Error('WebContents was destroyed');
+ sent.push({ channel, payload });
+ },
+ };
+}
+
+function buildFirstLaunchCli(): { cli: McpWiringCliSurface; writes: McpWiringEditorId[][] } {
+ const target = fakeTarget('claude' as McpWiringEditorId);
+ const writes: McpWiringEditorId[][] = [];
+ const cli: McpWiringCliSurface = {
+ detectInstalledEditors: () => ['claude' as McpWiringEditorId],
+ classifyExistingMcpEntry: () => ({ kind: 'absent' }) as McpEntryClassification,
+ readExistingMcpEntry: () => null,
+ allEditorIds: ['claude' as McpWiringEditorId],
+ editorTargets: { claude: target } as Record<McpWiringEditorId, EditorMcpTarget>,
+ writeUserMcpConfigs: async ({ editors }) => {
+ writes.push([...editors]);
+ return editors.map((editorId) => ({
+ editorId,
+ label: editorId,
+ action: 'written' as const,
+ configPath: target.configPath('', '/home/u'),
+ serverName: 'open-knowledge',
+ }));
+ },
+ };
+ return { cli, writes };
+}
+
+const SILENT_LOGGER = { info() {}, warn() {}, error() {}, event() {} };
+
+function buildWiringOpts(overrides: Partial<WiringOpts> = {}): WiringOpts {
+ const { cli } = buildFirstLaunchCli();
+ return {
+ isPackaged: true,
+ executablePath: PACKAGED_EXE,
+ home: '/home/u',
+ platform: 'darwin',
+ ipcMain: stubIpcMain(),
+ cli,
+ fs: memoryFs(),
+ logger: SILENT_LOGGER,
+ ...overrides,
+ };
+}
+
+describe('runMcpWiringOnFirstLaunch — mid-session immediate dispatch', () => {
+ test('show dispatches to the provided target and binds confirm to its sender', async () => {
+ const ipcMain = stubIpcMain();
+ const wc = fakeWebContents(11);
+ const fs = memoryFs();
+ const { cli, writes } = buildFirstLaunchCli();
+ const handle = runMcpWiringOnFirstLaunch(
+ buildWiringOpts({ ipcMain, cli, fs, immediateDispatchTarget: wc }),
+ );
+
+ expect(handle.armed).toBe(true);
+ expect(wc.sent).toEqual([
+ {
+ channel: 'ok:mcp-wiring:show',
+ payload: {
+ detectedEditors: [{ id: 'claude', label: 'claude', detected: true, willReplace: false }],
+ },
+ },
+ ]);
+ expect(ipcMain.handlers.has('ok:mcp-wiring:renderer-ready')).toBe(false);
+
+ const confirm = ipcMain.handlers.get('ok:mcp-wiring:confirm');
+ expect(confirm).toBeDefined();
+ const result = await confirm?.({ sender: { id: 11 } }, { editorIds: ['claude'] });
+ expect(result).toEqual({ ok: true });
+ expect(writes).toEqual([['claude' as McpWiringEditorId]]);
+ expect(readMcpStatusMarker('/home/u', fs)).toMatchObject({
+ configured: true,
+ editors: ['claude'],
+ });
+ });
+
+ test('confirm from a window other than the dispatch target is rejected', async () => {
+ const ipcMain = stubIpcMain();
+ const wc = fakeWebContents(11);
+ const { cli, writes } = buildFirstLaunchCli();
+ runMcpWiringOnFirstLaunch(buildWiringOpts({ ipcMain, cli, immediateDispatchTarget: wc }));
+
+ const confirm = ipcMain.handlers.get('ok:mcp-wiring:confirm');
+ const result = (await confirm?.({ sender: { id: 99 } }, { editorIds: ['claude'] })) as {
+ ok: boolean;
+ };
+ expect(result.ok).toBe(false);
+ expect(writes).toEqual([]);
+ });
+
+ test('skip from the dispatch target writes the skip marker without touching configs', async () => {
+ const ipcMain = stubIpcMain();
+ const wc = fakeWebContents(11);
+ const fs = memoryFs();
+ const { cli, writes } = buildFirstLaunchCli();
+ runMcpWiringOnFirstLaunch(
+ buildWiringOpts({
+ ipcMain,
+ cli,
+ fs,
+ immediateDispatchTarget: wc,
+ now: () => new Date('2026-06-10T00:00:00.000Z'),
+ }),
+ );
+
+ const skip = ipcMain.handlers.get('ok:mcp-wiring:skip');
+ expect(skip).toBeDefined();
+ const result = await skip?.({ sender: { id: 11 } });
+ expect(result).toEqual({ ok: true });
+ expect(writes).toEqual([]);
+ expect(readMcpStatusMarker('/home/u', fs)).toEqual({
+ configured: false,
+ skippedAt: '2026-06-10T00:00:00.000Z',
+ });
+ });
+
+ test('skip from a window other than the dispatch target is rejected', async () => {
+ const ipcMain = stubIpcMain();
+ const wc = fakeWebContents(11);
+ const fs = memoryFs();
+ runMcpWiringOnFirstLaunch(buildWiringOpts({ ipcMain, fs, immediateDispatchTarget: wc }));
+
+ const skip = ipcMain.handlers.get('ok:mcp-wiring:skip');
+ const result = (await skip?.({ sender: { id: 99 } })) as { ok: boolean };
+ expect(result.ok).toBe(false);
+ expect(readMcpStatusMarker('/home/u', fs)).toBeNull();
+ });
+
+ test('forceShow + immediate target re-fires the dialog over a prior skip marker', () => {
+ const ipcMain = stubIpcMain();
+ const wc = fakeWebContents(7);
+ const fs = memoryFs({
+ '/home/u/.ok/mcp-status.json': JSON.stringify({
+ configured: false,
+ skippedAt: '2026-05-26T00:00:00.000Z',
+ }),
+ });
+ const handle = runMcpWiringOnFirstLaunch(
+ buildWiringOpts({ ipcMain, fs, forceShow: true, immediateDispatchTarget: wc }),
+ );
+ expect(handle.armed).toBe(true);
+ expect(wc.sent.map((s) => s.channel)).toEqual(['ok:mcp-wiring:show']);
+ expect(ipcMain.handlers.has('ok:mcp-wiring:renderer-ready')).toBe(false);
+ });
+
+ test('failed immediate dispatch leaves the mount-ack fallback armed', async () => {
+ const ipcMain = stubIpcMain();
+ const broken = fakeWebContents(11, { failSend: true });
+ const fs = memoryFs();
+ const { cli, writes } = buildFirstLaunchCli();
+ runMcpWiringOnFirstLaunch(
+ buildWiringOpts({ ipcMain, cli, fs, immediateDispatchTarget: broken }),
+ );
+
+ const ready = ipcMain.handlers.get('ok:mcp-wiring:renderer-ready');
+ expect(ready).toBeDefined();
+
+ const wc2 = fakeWebContents(22);
+ ready?.({ sender: wc2 });
+ expect(wc2.sent.map((s) => s.channel)).toEqual(['ok:mcp-wiring:show']);
+ expect(ipcMain.handlers.has('ok:mcp-wiring:renderer-ready')).toBe(false);
+
+ const confirm = ipcMain.handlers.get('ok:mcp-wiring:confirm');
+ const result = await confirm?.({ sender: { id: 22 } }, { editorIds: ['claude'] });
+ expect(result).toEqual({ ok: true });
+ expect(writes).toEqual([['claude' as McpWiringEditorId]]);
+ expect(readMcpStatusMarker('/home/u', fs)).toMatchObject({
+ configured: true,
+ editors: ['claude'],
+ });
+ });
+
+ test('no immediate target preserves the boot-path mount-ack behavior', () => {
+ const ipcMain = stubIpcMain();
+ runMcpWiringOnFirstLaunch(buildWiringOpts({ ipcMain }));
+
+ expect(ipcMain.handlers.has('ok:mcp-wiring:renderer-ready')).toBe(true);
+ const wc = fakeWebContents(5);
+ ipcMain.handlers.get('ok:mcp-wiring:renderer-ready')?.({ sender: wc });
+ expect(wc.sent.map((s) => s.channel)).toEqual(['ok:mcp-wiring:show']);
+ });
+});
diff --git a/packages/desktop/src/main/mcp-wiring.ts b/packages/desktop/src/main/mcp-wiring.ts
index 34d09a011..caed74aff 100644
--- a/packages/desktop/src/main/mcp-wiring.ts
+++ b/packages/desktop/src/main/mcp-wiring.ts
@@ -22,7 +22,7 @@ import type {
McpWiringSkipResult,
} from '../shared/ipc-channels.ts';
import { createHandler } from '../shared/ipc-handler.ts';
-import { sendToRenderer } from '../shared/ipc-send.ts';
+import { type SendableWebContents, sendToRenderer } from '../shared/ipc-send.ts';
import { logIpcError } from './ipc-log.ts';
const MCP_STATUS_DIR_NAME = '.ok';
@@ -149,6 +149,10 @@ function isPermittedSender(
interface IpcMainLike extends Pick<IpcMain, 'handle' | 'removeHandler'> {}
+export interface McpWiringDispatchTarget extends SendableWebContents {
+ readonly id: number;
+}
+
export interface McpWiringCliSurface {
detectInstalledEditors(cwd: string, home?: string): McpWiringEditorId[];
writeUserMcpConfigs(opts: { editors: McpWiringEditorId[]; home?: string }): Promise<
@@ -201,6 +205,7 @@ interface RunMcpWiringOpts {
forceEnv?: string | null | undefined;
reclaimDisableEnv?: string | null | undefined;
forceShow?: boolean;
+ immediateDispatchTarget?: McpWiringDispatchTarget;
fs?: McpWiringFsOps;
now?: () => Date;
logger?: McpWiringLogger;
@@ -394,6 +399,7 @@ export function runMcpWiringOnFirstLaunch(opts: RunMcpWiringOpts): RunMcpWiringH
forceEnv,
reclaimDisableEnv,
forceShow = false,
+ immediateDispatchTarget,
fs,
now,
logger = DEFAULT_LOGGER,
@@ -626,26 +632,31 @@ export function runMcpWiringOnFirstLaunch(opts: RunMcpWiringOpts): RunMcpWiringH
return { ok: true };
};
- const rendererReadyHandler = (event: IpcMainInvokeEvent): undefined => {
+ const dispatchShowAndBind = (target: McpWiringDispatchTarget): boolean => {
try {
- sendToRenderer(event.sender, 'ok:mcp-wiring:show', {
+ sendToRenderer(target, 'ok:mcp-wiring:show', {
detectedEditors: detections,
});
logger.info('dispatched show to renderer', {
detectedCount: detections.length,
- senderId: event.sender.id,
+ senderId: target.id,
});
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
logger.error('show dispatch failed — handler remains armed for next renderer', {
message,
});
- return undefined;
+ return false;
}
- capturedSenderId = event.sender.id;
+ capturedSenderId = target.id;
try {
ipcMain.removeHandler('ok:mcp-wiring:renderer-ready');
} catch {}
+ return true;
+ };
+
+ const rendererReadyHandler = (event: IpcMainInvokeEvent): undefined => {
+ dispatchShowAndBind(event.sender);
return undefined;
};
@@ -654,9 +665,14 @@ export function runMcpWiringOnFirstLaunch(opts: RunMcpWiringOpts): RunMcpWiringH
register('ok:mcp-wiring:skip', skipHandler);
register('ok:mcp-wiring:renderer-ready', rendererReadyHandler);
- logger.info('armed — waiting for renderer mount-ack', {
- detectedCount: detections.filter((d) => d.detected).length,
- });
+ const immediateDispatched =
+ immediateDispatchTarget !== undefined && dispatchShowAndBind(immediateDispatchTarget);
+
+ if (!immediateDispatched) {
+ logger.info('armed — waiting for renderer mount-ack', {
+ detectedCount: detections.filter((d) => d.detected).length,
+ });
+ }
let destroyed = false;
return {