Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

fix(mcp): owner prompts can't be auto-answered by Allow All; ADR-029 follow-up

Asyfdzaky1afbfd4a4127
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a29f84d2..0db6534e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,7 +3,8 @@
## Unreleased
### MCP servers (ADR-029)
-- **MCP servers: Mercury can use tools from Model Context Protocol servers.** Add a local server (`mercury mcp add files --stdio npx -- -y @modelcontextprotocol/server-filesystem ~/Documents`) or a remote one (`--http <url>`), allow the tools you want (`mercury mcp allow`), and the agent can call them next to its built-in tools. Every MCP call asks first in Ask Me mode, and Allow All does not cover MCP tools; only tools you list in `autoApprove` run without a prompt, and only those run in scheduled tasks. Secrets stay in `.env` as `${env:NAME}` references and are masked everywhere they could appear. Local servers get a minimal environment, never Mercury's API keys, and remote servers go through the SSRF guard. Check health with `mercury mcp test`, `mercury doctor --mcp`, `/mcp` in chat, or the new read-only **MCP** dashboard page. The agent's file tools now always ask before writing `mercury.yaml`, `permissions.yaml` or `.env`, even under Allow All. See [MCP Servers](https://mercuryagent.sh/docs/integrations/mcp) and ADR-029.
+- **MCP servers: Mercury can use tools from Model Context Protocol servers.** Add a local server (`mercury mcp add files --stdio npx -- -y @modelcontextprotocol/server-filesystem ~/Documents`) or a remote one (`--http <url>`), allow the tools you want (`mercury mcp allow`), and the agent can call them next to its built-in tools. Every MCP call asks first in Ask Me mode, and Allow All does not cover MCP tools; only tools you list in `autoApprove` run without a prompt, and only those run when nobody can be asked. Secrets stay in `.env` as `${env:NAME}` references and are masked everywhere they could appear. Local servers get a minimal environment, never Mercury's API keys, and remote servers go through the SSRF guard. Check health with `mercury mcp test`, `mercury doctor --mcp`, `/mcp` in chat, or the new read-only **MCP** dashboard page. The agent's file tools now always ask before writing `mercury.yaml`, `permissions.yaml` or `.env`, even under Allow All. See [MCP Servers](https://mercuryagent.sh/docs/integrations/mcp) and ADR-029.
+- **Allow All in the terminal, the web dashboard and Mercury Cloud no longer skips MCP prompts.** The terminal attached to the background service (what `mercury` opens), the dashboard and Cloud sessions share one web channel, and in Allow All it answered every approval with yes on its own. So MCP tool calls, shell commands that change MCP setup, and writes to `mercury.yaml`, `permissions.yaml` or `.env` ran without asking there. They now ask in every channel, as documented. Other prompts still follow the session's mode.
## 1.4.2 — search that finds things, and a research prompt that asks only when you mean it
diff --git a/DECISIONS.md b/DECISIONS.md
index 47fa61a7..0f55481a 100644
--- a/DECISIONS.md
+++ b/DECISIONS.md
@@ -269,7 +269,7 @@
- **Transports.** stdio and Streamable HTTP. Legacy SSE is left out.
- **Tool names.** `mcp__<server>__<tool>`. Server ids match `^[a-z][a-z0-9-]{0,23}$`. Tool parts are sanitised to `[A-Za-z0-9_-]` and the whole name is capped at 64 characters. A truncated or colliding name gets a 6-character hash suffix, and a reverse map keeps calls on the original name.
- **Visibility.** A server's tools are hidden until listed in `tools.allow` (`["*"]` for all). `tools.deny` always wins. Bots, plan mode and channel members get no MCP tools in Phase 1.
- - **Approval.** There is no trust flag. Every MCP call asks in Ask Me mode, and Allow All never covers MCP tools. The only way to skip the prompt is `tools.autoApprove`: exact tool names, no wildcards, set by the owner. A tool that appears later through `list_changed` therefore never inherits approval. Unattended runs (internal turns, scheduled tasks, sub-agents) may only run `autoApprove` tools. Annotations a server sends, such as `readOnlyHint`, never change permissions.
+ - **Approval.** There is no trust flag. Every MCP call asks in Ask Me mode, and Allow All never covers MCP tools. The only way to skip the prompt is `tools.autoApprove`: exact tool names, no wildcards, set by the owner. A tool that appears later through `list_changed` therefore never inherits approval. A scheduled task or sub-agent started from a chat asks on that chat; a run with nobody to ask (an internal turn, a fail-closed context) may only run `autoApprove` tools. Annotations a server sends, such as `readOnlyHint`, never change permissions.
- **Process and secrets.** A stdio server starts from the SDK's `getDefaultEnvironment()` plus its own configured `env`, never the daemon's environment, so provider keys loaded from `.env` never reach a third-party process. `${env:NAME}` references are resolved at connect time only, never in `loadConfig`, because `saveConfig` rewrites the whole file and would otherwise write secrets into YAML. Resolved values are registered with the redaction layer.
- **HTTP.** Requests go through the SSRF guard. Private and loopback targets need a per-server `allowPrivate: true`, which only the owner can set.
- **Lifecycle.** The process that runs the Agent owns the connections: the daemon (ADR-024), or the terminal where no daemon runs. Servers connect in the background at boot with a timeout, so one broken server never blocks startup or other tools.
@@ -290,3 +290,8 @@
- Any new place that filters tools by name (plan mode, members, bots, sub-agents) must decide how it treats the `mcp__` prefix.
- Text from an MCP server (descriptions, results, errors) is untrusted input and must never be used to make a permission decision.
- Resources, prompts, sampling, OAuth, images in results, bot access and the 2026-07-28 protocol (`versionNegotiation: 'auto'`) are follow-ups.
+- **Follow-up after the #207 review**:
+ - **One approval rule for plugin and MCP tools: trust follows origin.** Allow All, internal-turn grants and a tool's own "read-only" claim apply only to code Mercury vouches for: built-in tools and plugins installed from the catalog with a matching checksum (`verified`). Tools from code the owner brings in from elsewhere (every MCP server, and plugins installed from a path, URL or GitHub) always ask, and skip the prompt only when the owner named them exactly (`tools.autoApprove` for MCP, or a scheduled task's `allow_tools`, which the owner approves when the task is created) or answered **Always** for that tool in that chat. MCP tools and verified plugins already follow this rule; unverified plugins still follow the normal modes until the plugin tool path enforces it.
+ - **Owner prompts can't be answered by a channel's own Allow All.** MCP tool calls, shell commands that change MCP setup, and writes to `mercury.yaml`, `permissions.yaml` and `.env` ask with `alwaysAsk`. The web channel, which serves the terminal attached to the background service, the web dashboard and Mercury Cloud, used to answer every prompt itself in an Allow All session; it now shows these.
+ - **Mercury Cloud: configuration stays local.** Cloud relays chats to the owner's own Mercury (they arrive through `WebChannel`), so Cloud chats can use MCP tools with the same prompts. Cloud has no command to add, enable or change servers, and `${env:}` secrets never leave the local `.env`. Configuring servers from Cloud would let a remote control start local processes, so it needs its own trust design and issue.
+ - **Shared call wrapper: yes, in stages.** The plugin runtime is also an MCP-over-stdio client, and the two keep separate copies of the same steps, which have drifted. The approval preview shows plugin arguments cut to 400 characters without redaction, and MCP arguments redacted, start and end, up to 4,000. Results are capped at 100,000 characters for plugins and 32 KB for MCP, and plugin results aren't redacted. One module will own the approval preview, timeouts, the result cap, redaction, image handling and error text for both. Image handling moves first; the rest follows once those differences are settled.
diff --git a/src/capabilities/mcp/e2e.test.ts b/src/capabilities/mcp/e2e.test.ts
index 7cf5e7d8..c0a0184f 100644
--- a/src/capabilities/mcp/e2e.test.ts
+++ b/src/capabilities/mcp/e2e.test.ts
@@ -124,7 +124,7 @@ describe('MCP end to end over stdio', () => {
it('asks before a call and runs it on yes', async () => {
const { ask, run } = await harness(servers(), { answer: 'yes' });
expect(await run('mcp__fx__echo', { text: 'hello' })).toBe('hello');
- expect(ask).toHaveBeenCalledWith('MCP tool call\nServer: fx\nTool: echo\nArguments:\n{\n "text": "hello"\n}');
+ expect(ask).toHaveBeenCalledWith('MCP tool call\nServer: fx\nTool: echo\nArguments:\n{\n "text": "hello"\n}', { alwaysAsk: true });
}, 20_000);
it('returns a denial to the agent on no', async () => {
diff --git a/src/capabilities/mcp/gate.test.ts b/src/capabilities/mcp/gate.test.ts
index 484ab74e..17cf0f84 100644
--- a/src/capabilities/mcp/gate.test.ts
+++ b/src/capabilities/mcp/gate.test.ts
@@ -18,6 +18,7 @@ const { CapabilityRegistry } = await import('../registry.js');
const { filterBotTools } = await import('../../bots/registry-factory.js');
const { formatToolStep } = await import('../../utils/tool-label.js');
const { registerSecretValue } = await import('../../utils/redact.js');
+const { WebChannel } = await import('../../channels/web.js');
type McpManager = import('./manager.js').McpManager;
afterAll(() => rmSync(home, { recursive: true, force: true }));
@@ -50,7 +51,7 @@ describe('PermissionManager.checkMcpTool', () => {
it('shows server, tool and arguments, and honours yes and no', async () => {
const yes = manager('yes');
expect(await yes.pm.checkMcpTool(request())).toEqual({ allowed: true });
- expect(yes.ask).toHaveBeenCalledWith('MCP tool call\nServer: fx\nTool: echo\nArguments:\n{\n "text": "hi"\n}');
+ expect(yes.ask).toHaveBeenCalledWith('MCP tool call\nServer: fx\nTool: echo\nArguments:\n{\n "text": "hi"\n}', { alwaysAsk: true });
const no = manager('no');
expect(await no.pm.checkMcpTool(request())).toEqual({ allowed: false, reason: 'User denied MCP tool fx/echo' });
@@ -232,3 +233,52 @@ describe('MCP tools in the registry and filters', () => {
expect(formatToolStep('some_unknown_tool', {})).toBe('some_unknown_tool');
});
});
+
+describe('always-ask prompts on the web dashboard and Mercury Cloud', () => {
+ function webInAllowAll() {
+ const channel = new WebChannel('Mercury');
+ const events: Array<{ type: string; data?: Record<string, unknown> }> = [];
+ channel.setSessionPermissionMode('session-1', 'allow-all');
+ channel.emitCloudMessage('work', 'request-1', 'session-1', 'conversation-1', undefined, (event) => {
+ events.push(event);
+ return true;
+ });
+ const pm = new PermissionManager();
+ pm.onAsk((prompt, options) => channel.askPermission(prompt, 'request-1', options));
+ pm.setCurrentContext('web', 'request-1');
+ pm.getManifest().capabilities.filesystem.scopes = [{ path: home, read: true, write: true }];
+ pm.getManifest().capabilities.shell.enabled = true;
+ pm.getManifest().capabilities.shell.cwdOnly = false;
+ const answerNext = async (answer: string) => {
+ await vi.waitFor(() => expect(events.some((event) => event.type === 'permission_request')).toBe(true));
+ const id = events.filter((event) => event.type === 'permission_request').pop()?.data?.id as string;
+ events.length = 0;
+ expect(channel.resolveApproval(id, answer, 'request-1')).toBe(true);
+ };
+ return { pm, events, answerNext };
+ }
+
+ it('asks before an MCP tool call even when the session is in Allow All', async () => {
+ const { pm, answerNext } = webInAllowAll();
+ const verdict = pm.checkMcpTool(request());
+ await answerNext('no');
+ expect(await verdict).toEqual({ allowed: false, reason: 'User denied MCP tool fx/echo' });
+ });
+
+ it('asks before an MCP setup shell command and a config-file write in Allow All', async () => {
+ const { pm, answerNext } = webInAllowAll();
+ const shell = pm.checkShellCommand('mercury mcp add evil --stdio node -y');
+ await answerNext('no');
+ expect((await shell).allowed).toBe(false);
+
+ const write = pm.checkFsAccess(join(home, 'mercury.yaml'), 'write');
+ await answerNext('no');
+ expect((await write).allowed).toBe(false);
+ });
+
+ it('leaves other prompts to the session mode', async () => {
+ const { pm, events } = webInAllowAll();
+ expect(await pm.approvePluginTool('demo__run', 'Run plugin tool demo → run')).toBe(true);
+ expect(events.some((event) => event.type === 'permission_request')).toBe(false);
+ });
+});
diff --git a/src/capabilities/permissions.ts b/src/capabilities/permissions.ts
index 882479da..6ff27161 100644
--- a/src/capabilities/permissions.ts
+++ b/src/capabilities/permissions.ts
@@ -66,6 +66,10 @@ function protectedConfigPaths(): string[] {
];
}
+export interface AskOptions {
+ alwaysAsk?: boolean;
+}
+
/** Result of a shell permission check. */
export interface ShellCheckResult {
allowed: boolean;
@@ -385,7 +389,7 @@ export function splitShellSegments(command: string): string[] {
export class PermissionManager {
private manifest: PermissionsManifest;
private readonly cwd: string;
- private askHandler?: (prompt: string) => Promise<string>;
+ private askHandler?: (prompt: string, options?: AskOptions) => Promise<string>;
private turnAnswers: Array<{ action: string; answer: 'yes' | 'no' | 'always' }> = [];
/**
* The main agent's (root) context: replaced, never mutated, by the
@@ -563,11 +567,11 @@ export class PermissionManager {
return this.ctx().senderRole;
}
- onAsk(handler: (prompt: string) => Promise<string>): void {
+ onAsk(handler: (prompt: string, options?: AskOptions) => Promise<string>): void {
// Every answer the owner gives is evidence for the Owner Model (autonomy,
// risk per action type); the learning loop drains it once per turn.
- this.askHandler = async (prompt: string) => {
- const answer = await handler(prompt);
+ this.askHandler = async (prompt: string, options?: AskOptions) => {
+ const answer = await (options ? handler(prompt, options) : handler(prompt));
if (answer === 'yes' || answer === 'no' || answer === 'always') {
const action = prompt.split('\n')[0].replace(/:.*$/, '').trim().slice(0, 40) || 'action';
this.turnAnswers.push({ action, answer });
@@ -968,7 +972,7 @@ export class PermissionManager {
if (!this.askHandler || ctx.channelType === 'internal' || this.failClosed) {
return { allowed: false, reason: 'Changing MCP servers or mercury.yaml from a shell command needs the owner; run it yourself in a terminal', needsApproval: false };
}
- const answer = await this.askHandler(`Run command (changes Mercury's MCP servers or config, so it always asks): ${trimmed}`);
+ const answer = await this.askOwner(`Run command (changes Mercury's MCP servers or config, so it always asks): ${trimmed}`);
return answer === 'yes' || answer === 'always'
? { allowed: true, needsApproval: false, lane: 'shell' }
: { allowed: false, reason: `User denied: ${trimmed}`, needsApproval: false };
@@ -1103,7 +1107,7 @@ export class PermissionManager {
reason: `MCP tool ${label} needs approval; add "${toolName}" to tools.autoApprove for server "${serverId}" to run it unattended`,
};
}
- const answer = await this.askHandler(
+ const answer = await this.askOwner(
`MCP tool call\nServer: ${serverId}\nTool: ${toolName}\nArguments:\n${formatMcpArgs(request.args)}`,
);
if (answer === 'yes') return { allowed: true };
@@ -1134,13 +1138,17 @@ export class PermissionManager {
reason: `Permission denied: ${resolved} is a Mercury config file and can only be changed with the owner's confirmation`,
};
}
- const answer = await this.askHandler(
+ const answer = await this.askOwner(
`Write to Mercury config file: ${resolved}\n(it controls MCP servers, permissions and secrets)`,
);
if (answer === 'yes' || answer === 'always') return { allowed: true };
return { allowed: false, reason: `User denied write to ${path}` };
}
+ private askOwner(prompt: string): Promise<string> {
+ return this.askHandler ? this.askHandler(prompt, { alwaysAsk: true }) : Promise.resolve('no');
+ }
+
/**
* Argv-lane classification: policy (tokenizer, allowlist, flag policy),
* binary availability in the pinned PATH, and a path gate over the
diff --git a/src/channels/web.test.ts b/src/channels/web.test.ts
index 81853618..b506115e 100644
--- a/src/channels/web.test.ts
+++ b/src/channels/web.test.ts
@@ -155,4 +155,36 @@ describe('WebChannel durable streaming', () => {
await expect(channel.askPermission('Write file?', 'request-allowed')).resolves.toBe('yes');
});
+
+ it('still asks in an allow-all session when the prompt must always ask', async () => {
+ const channel = new WebChannel('Mercury');
+ const events: Array<{ type: string; data?: Record<string, unknown> }> = [];
+ channel.setSessionPermissionMode('session-allowed', 'allow-all');
+ channel.emitCloudMessage('work', 'request-allowed', 'session-allowed', 'conversation-1', undefined, (event) => {
+ events.push(event);
+ return true;
+ });
+
+ const decision = channel.askPermission('MCP tool call', 'request-allowed', { alwaysAsk: true });
+ const id = events.find((event) => event.type === 'permission_request')?.data?.id as string;
+ expect(id).toBeTruthy();
+ expect(channel.resolveApproval(id, 'no', 'request-allowed')).toBe(true);
+ await expect(decision).resolves.toBe('no');
+ });
+
+ it('still asks under the global bypass when the prompt must always ask', async () => {
+ const channel = new WebChannel('Mercury');
+ const events: Array<{ type: string; data?: Record<string, unknown> }> = [];
+ channel.setBypassPermissions(true);
+ channel.emitCloudMessage('work', 'request-bypass', 'session-bypass', 'conversation-1', undefined, (event) => {
+ events.push(event);
+ return true;
+ });
+
+ await expect(channel.askPermission('Write file?', 'request-bypass')).resolves.toBe('yes');
+ const decision = channel.askPermission('MCP tool call', 'request-bypass', { alwaysAsk: true });
+ const id = events.find((event) => event.type === 'permission_request')?.data?.id as string;
+ expect(channel.resolveApproval(id, 'yes', 'request-bypass')).toBe(true);
+ await expect(decision).resolves.toBe('yes');
+ });
});
diff --git a/src/channels/web.ts b/src/channels/web.ts
index a0d4b74f..19b83b62 100644
--- a/src/channels/web.ts
+++ b/src/channels/web.ts
@@ -237,8 +237,8 @@ export class WebChannel extends BaseChannel {
this.broadcast({ type: 'thinking', data: { targetId: _targetId } });
}
- async askPermission(prompt: string, _targetId?: string): Promise<string> {
- if (this.isPermissionBypassed(_targetId)) return 'yes';
+ async askPermission(prompt: string, _targetId?: string, options?: { alwaysAsk?: boolean }): Promise<string> {
+ if (!options?.alwaysAsk && this.isPermissionBypassed(_targetId)) return 'yes';
if (!this.hasInteractiveTarget(_targetId)) return 'no';
const id = `perm_${randomUUID()}`;
this.broadcast({
diff --git a/src/index.ts b/src/index.ts
index 42f1445e..954cf3ff 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -3702,7 +3702,7 @@ async function runAgent(isDaemon: boolean = false): Promise<void> {
setWebSpotify(spotifyClient);
}
- capabilities.permissions.onAsk(async (prompt: string) => {
+ capabilities.permissions.onAsk(async (prompt: string, options?: { alwaysAsk?: boolean }) => {
const channelType = capabilities.permissions.getCurrentChannelType();
const { channelId } = capabilities.getChannelContext();
if (channelType === 'telegram' && tgChannel) {
@@ -3712,7 +3712,7 @@ async function runAgent(isDaemon: boolean = false): Promise<void> {
return (channels.get('signal') as SignalChannel).askPermission(prompt, channelId);
}
if (channelType === 'web' && webChannel) {
- return webChannel.askPermission(prompt, channelId);
+ return webChannel.askPermission(prompt, channelId, options);
}
// Any other channel that can ask (plugin channels such as WhatsApp).
const asking = channels.get(channelType as Parameters<typeof channels.get>[0]) as { askPermission?: (p: string, id?: string) => Promise<string> } | undefined;
diff --git a/website/docs/integrations/mcp.mdx b/website/docs/integrations/mcp.mdx
index efe0e504..adfdfc6e 100644
--- a/website/docs/integrations/mcp.mdx
+++ b/website/docs/integrations/mcp.mdx
@@ -159,7 +159,7 @@ MCP tools have their own rules, separate from the shell and file tools:
| Tool not in `allow` (or in `deny`) | The agent can't see it |
| Ask Me mode | You're asked before every call, with server, tool and arguments (shown whole up to 4,000 characters; longer ones show the start and the end) |
| You answer **Always** | That tool runs without asking in that chat until Mercury restarts |
-| **Allow All** mode | You're **still asked** — Allow All never covers MCP tools |
+| **Allow All** mode | You're **still asked** — Allow All never covers MCP tools, in the terminal, the web dashboard and Mercury Cloud alike |
| Tool in `autoApprove` | Runs without asking, in chats and in unattended runs |
| Scheduled tasks and sub-agents | They ask on the chat they came from, like a normal call; nothing is approved for them. A run with no one to ask (fail-closed, internal) only runs `autoApprove` tools |
| Plan mode | MCP tools are not available |
@@ -213,3 +213,4 @@ In chat, `/mcp` shows the live status of the running Mercury; the dashboard's **
- **Windows.** Commands such as `npx` that are `.cmd` shims work as `command: npx`.
- **Standalone binaries.** MCP is built into the standalone binaries (verified on the Windows binary; macOS and Linux run the same bundled code). Stdio servers still need their own runtime installed — Node.js for `npx`, Python for `uvx`.
- **Termux.** MCP is untested on Termux. Install Mercury with npm there; stdio servers that only need Node.js are expected to work.
+- **Mercury Cloud.** Servers are configured only on the machine that runs Mercury, in `mercury.yaml` or with `mercury mcp` in a terminal. Chats from Mercury Cloud reach that Mercury, so they can use its MCP tools and get the same prompts, even in an Allow All session. Cloud can't add or change servers, and your `${env:…}` secrets stay in the local `.env`.