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.

Merge pull request #248 from cosmicstack-labs/feat/mcp-followup

Salman Qureshi6db680b596f6
diff --cc CHANGELOG.md
index 864b6ca1,29147eb9..98052963
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -2,57 -2,13 +2,62 @@@
## Unreleased
+### Providers
+- **Remote Ollama behind a username and password.** Set `username` and `password` on Ollama Local, OpenAI-compatible, LM Studio, LiteLLM or Atomic Chat in `mercury.yaml`. Mercury sends them as HTTP Basic auth for chat and for model lists, instead of a Bearer key.
+
+### MCP
+- MCP text resources can be enabled per server: list bounded catalog pages and read sourced documents or schemas, with separate URI permissions and exact unattended approvals. Resource reads still ask under Web Allow All; cancellation and reconnect never replay a read.
+
+## 1.5.1 — speech uses the voice you chose, Gemini included
+
+### Speech
+- **Your voice choice counts everywhere.** Reading a reply aloud, voice typing and voice notes from Telegram or WhatsApp use the voice service chosen in Settings → Voice when it has a key. A fresh install with only a Gemini key no longer asks for an OpenAI key.
+- **Gemini speaks and listens.** Gemini reads replies aloud (about 4 seconds for a sentence) and transcribes what you say, with the same key Optimus uses. A Gemini model that's busy or retired falls through to the next one.
+- **The "needs a speech service" notice** points to Voice settings and names every option (Gemini, OpenAI, Deepgram, ElevenLabs) instead of an "Add OpenAI key" button.
+
+### Mercury Desktop
+- **"Update Optimus" says what happened** on the microphone & permissions card: updated, no newer version yet, or why it failed. It used to spin for a second and show nothing.
+
+### Plugins
+- **Optimus 0.5.1 is in the catalog** (a plugin-only update, works with Mercury 1.3.9 and newer): the microphone picker, live voice-level test, off switch and permission checks on Mercury Desktop's Optimus page. Update it under Plugins → Optimus.
+
+## 1.5.0 — Mercury Desktop, updates that roll back, remote access you control
+
+### Mercury Desktop (new)
+- **One app for chat, code, bots and research.** It installs and starts Mercury on this computer for you, or connects to any number of Mercury servers and switches between them from the top bar.
+- **Download it at [mercuryagent.sh/download](https://mercuryagent.sh/download).** This first release isn't code-signed yet: macOS asks you to allow it once (System Settings → Privacy & Security → Open Anyway), Windows SmartScreen once (More info → Run anyway). On a Mac, `curl -fsSL https://mercuryagent.sh/install-desktop.sh | sh` installs it with no prompt.
+- **Bots 2.0 in the app.** An inbox of run reports, create and edit bots in words, answer a bot's question mid-run (Allow once, Always allow, Deny), design a fleet's crew or let Mercury decide.
+- **Commands and skills in the composer** (`/` and `#`), saved chats, microphone and permissions for Optimus on every OS.
+
+### Updates that never leave you broken
+- **An Update button, top right, like Chrome's.** It appears only when the app or one of your servers has an update, gets more noticeable the longer it waits, and shows what's new before you update. Settings → About checks the app and every server in one go, and "Update everything" does them all.
+- **Server updates roll back by themselves.** `mercury upgrade` (and the desktop) waits for running work, downloads with checksums (resuming if interrupted), backs up, installs, starts the new version and checks it works. If it doesn't, the old version and your settings come back on their own.
+- **Desktop updates** download in the background, resume after a dropped connection, are verified before install, and install when you restart or quit.
+- **Required updates** (for example a security fix) show a full screen; continuing without updating takes ticking every risk. Everything else is dismissible.
+- **One signed update notice** tells every install what's current; an unsigned or tampered one is ignored, and being offline never blocks anything.
+
+### Remote access you control
+- **New devices need your approval.** A phone or laptop signing in shows a code; you approve it with `approve CODE` on Telegram or WhatsApp, in `/server`, or in Mercury Desktop.
+- **Sensitive actions from a remote device ask you first** (the shell, Allow All, plugins, channel tokens, restarts, server updates). Remote shell is off by default.
+- **Tunnels no longer count as "this computer"**, unused devices expire after 30 days, revoking a device cuts it off at once, and a known device from a new address tells you.
+- **`/server` and `mercury server`**: remote access on/off, allowed IP addresses, device tokens (list, make, revoke), approvals and the security log. `mercury doctor --security` checks it all.
+
+### Research
+- **One visible run**: a plan you can approve, live progress with failures and their reasons, "Write the report now", and a report even when a run is cut short.
+- **Reports export as PDF and Word**, sources show their site icons, and everything Mercury makes is saved in `~/mercury-artifacts` (one folder per chat) instead of loose in your home folder.
+
+### Also in this release
+- **Chat attachments** (photos and PDFs), bots take files too, bot avatars, renaming bots.
+- Runcrate provider preset; a declared vision capability beats the name-based guess; a zero daily budget means no ceiling; Telegram keeps typing while Mercury prepares.
+
+
### 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.
+ - **MCP tools can show the model pictures.** Up to 4 images per call (PNG, JPEG, WebP or GIF) from an MCP server now reach the model as images, the same way plugin screenshots do, when the model and provider can take images in tool results (Anthropic, and OpenAI's Responses API). Elsewhere the model is told an image was left out. Chat history and logs keep only the text, never the base64.
+
+ ### Plugins
+ - **Plugin images reach the model only where the provider can take them.** On Chat Completions providers (Mercury Cloud, GitHub Copilot, Ollama, LM Studio, LiteLLM, AI/ML API and other OpenAI-compatible endpoints) the AI SDK sent a plugin's screenshot as JSON text, so the model got megabytes of base64 instead of a picture. Images in tool results now go only to Anthropic and to OpenAI's Responses API; every other provider, Grok and ChatGPT Web included until they are verified, gets the usual "this model can't view images" note.
## 1.4.2 — search that finds things, and a research prompt that asks only when you mean it
diff --cc DECISIONS.md
index 6467f609,94ed10a6..2c678bd9
--- a/DECISIONS.md
+++ b/DECISIONS.md
@@@ -273,9 -273,8 +273,9 @@@
- **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.
- - **Results.** Converted to strings, so the existing compaction can shrink them. Results are capped, and image and audio blocks become placeholders for now.
+ - **Results.** Converted to strings, so the existing compaction can shrink them. Results are capped. Up to 4 supported images per call are held by tool call id and attached in `toModelOutput` through the helper the plugin bridge also uses (`src/capabilities/tool-images.ts`), only when the model and provider can take images in tool results; audio and other media become placeholders.
- **Configuration.** Adding or enabling a server is an owner action through `mercury.yaml` or `mercury mcp …`. The agent has no tool for it.
+ - **Text resources.** Opt-in `resources.allow`/`deny` URI filters are independent of tool permissions. Two shared schemas list resource metadata and read bounded text through the existing connection. Each list asks; each read asks unless the exact URI is in `resources.autoApprove` or the owner remembered that URI in that source chat. Resource owner prompts bypass channel Allow All. Metadata continuations are bounded, expire and are invalidated on reconnect; resource contents are never cached by Mercury. No URI is opened locally or fetched separately. Resource-only servers work without advertising tools. Templates, subscriptions and binary reads remain out of scope.
- **Spike results** (Windows x64, Node 22.12, Bun 1.3.8):
- The v2 client connects, lists tools, calls them and receives `tools/list_changed` over stdio. Over Streamable HTTP it uses a caller-supplied `fetch` with static headers. These are covered by `src/capabilities/mcp/sdk-smoke.test.ts` against a dependency-free fixture server.
- The same client works under Bun and inside a `bun build --compile` binary. In the binary it starts a server both directly and through a `.cmd` shim (how `npx` runs on Windows), and `npx.cmd` resolves under `getDefaultEnvironment()`.
@@@ -290,7 -289,12 +290,12 @@@
- **Consequence**: Owners can use the MCP ecosystem without a hand-written capability per integration. Every third-party call is visible in Ask Me mode unless the owner named the tool in `autoApprove`. The cost is a prompt per call for servers the owner hasn't pre-approved, even under Allow All. That is deliberate. Maintenance owned by Mercury:
- 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.
- - Resource templates/subscriptions, prompts, sampling, OAuth, images in results, bot access and the 2026-07-28 protocol (`versionNegotiation: 'auto'`) are follow-ups.
- - Resources, prompts, sampling, OAuth, bot access and the 2026-07-28 protocol (`versionNegotiation: 'auto'`) are follow-ups.
++ - Resource templates/subscriptions, prompts, sampling, OAuth, 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 is already shared (`src/capabilities/tool-images.ts`); the rest follows once those differences are settled.
## ADR-030: Mercury Desktop — a Tauri shell around the one dashboard, over a versioned API
diff --cc src/capabilities/tool-images.ts
index 00000000,90816a4c..4c15b741
mode 000000,100644..100644
--- a/src/capabilities/tool-images.ts
+++ b/src/capabilities/tool-images.ts
@@@ -1,0 -1,55 +1,59 @@@
+ export interface ToolImage {
+ data: string;
+ mimeType: string;
+ }
+
+ export type ToolImageOutput =
+ | { type: 'text'; value: string }
+ | {
+ type: 'content';
+ value: Array<{ type: 'text'; text: string } | { type: 'image-data'; data: string; mediaType: string }>;
+ };
+
+ export const TOOL_IMAGE_TYPES = new Set(['image/png', 'image/jpeg', 'image/webp', 'image/gif']);
+ export const MAX_TOOL_IMAGES = 4;
+ export const MAX_TOOL_IMAGE_CHARS = 8_000_000;
+ const MAX_PENDING = 32;
+
+ const pendingImages = new Map<string, ToolImage[]>();
+ let imagesAllowed = true;
+
+ export function setToolImagesAllowed(allowed: boolean): void {
+ imagesAllowed = allowed;
+ }
+
++export function toolImagesAllowed(): boolean {
++ return imagesAllowed;
++}
++
+ export function usableImages(images: ToolImage[]): ToolImage[] {
+ return images
+ .filter((image) => TOOL_IMAGE_TYPES.has(image.mimeType) && image.data.length <= MAX_TOOL_IMAGE_CHARS)
+ .slice(0, MAX_TOOL_IMAGES);
+ }
+
+ export function holdImages(toolCallId: string | undefined, images: ToolImage[]): void {
+ if (!toolCallId || !images.length) return;
+ pendingImages.set(toolCallId, images);
+ while (pendingImages.size > MAX_PENDING) pendingImages.delete(pendingImages.keys().next().value as string);
+ }
+
+ export function attachedImagesNote(count: number): string {
+ return count ? `\n[${count} image${count > 1 ? 's' : ''} attached]` : '';
+ }
+
+ export function toolOutputWithImages(toolCallId: string, text: string): ToolImageOutput {
+ const images = pendingImages.get(toolCallId);
+ if (!images?.length) return { type: 'text', value: text };
+ if (!imagesAllowed) {
+ return { type: 'text', value: `${text}\n(The current model can't view images, so the attached image was left out. Say so if it matters.)` };
+ }
+ return {
+ type: 'content',
+ value: [{ type: 'text', text }, ...images.map((image) => ({ type: 'image-data' as const, data: image.data, mediaType: image.mimeType }))],
+ };
+ }
+
+ export function resetToolImages(): void {
+ pendingImages.clear();
+ }
diff --cc src/core/agent.ts
index 0a283292,4162ec70..a2cbdd37
--- a/src/core/agent.ts
+++ b/src/core/agent.ts
@@@ -3796,15 -3394,8 +3796,15 @@@ export class Agent
// passed back with assistant turns (issue #24); other providers
// get plain text.
// Photos and PDFs from the chat go to models that can take them.
- setPluginImagesAllowed(modelSeesImages(provider.name, provider.getModel()) && provider.supportsToolResultImages());
- const providerMessages = withAttachments(deepseekProviderOptions ? withReasoningParts(messages) : messages, msg, provider.name, provider.getModel());
+ const seesImages = modelSeesImages(provider.name, provider.getModel(), provider.seesImages);
- setPluginImagesAllowed(seesImages);
++ setPluginImagesAllowed(seesImages && provider.supportsToolResultImages());
+ const providerMessages = withAttachments(
+ deepseekProviderOptions ? withReasoningParts(messages) : messages,
+ msg,
+ provider.name,
+ provider.getModel(),
+ provider.seesImages,
+ );
// Per-provider output ceiling: a 32K request is rejected outright by
// providers with smaller limits and burned a halve-and-retry round.
const providerMaxOutputTokens = Math.min(effectiveMaxOutputTokens, provider.getMaxOutputTokens() ?? Infinity);
diff --cc src/plugins/tool-bridge.ts
index 8801cce0,1e011abc..b4716351
--- a/src/plugins/tool-bridge.ts
+++ b/src/plugins/tool-bridge.ts
@@@ -13,6 -13,16 +13,17 @@@
import { jsonSchema, tool, type Tool } from 'ai';
import { isMcpToolName } from '../capabilities/mcp/naming.js';
import type { PermissionManager } from '../capabilities/permissions.js';
+ import {
+ TOOL_IMAGE_TYPES,
+ attachedImagesNote,
+ holdImages,
+ resetToolImages,
+ setToolImagesAllowed,
++ toolImagesAllowed,
+ toolOutputWithImages,
+ usableImages,
+ type ToolImage,
+ } from '../capabilities/tool-images.js';
import { logger } from '../utils/logger.js';
export interface LiveTool {
@@@ -65,28 -68,9 +69,13 @@@ function isToolContent(v: unknown): v i
return !!v && typeof v === 'object' && (v as Record<symbol, unknown>)[CONTENT] === true;
}
- /**
- * Images waiting to be attached to their tool result, by tool call id.
- * execute() returns text only (so logs, history and learning never carry
- * base64); toModelOutput() adds the images when the result goes to the model.
- * Bounded: a result the SDK never converts can't leak memory.
- */
- const pendingImages = new Map<string, PluginImage[]>();
- /** Whether the model in use can take images (set by the agent before each provider call). */
- let imagesAllowed = true;
-
export function setPluginImagesAllowed(allowed: boolean): void {
- imagesAllowed = allowed;
+ setToolImagesAllowed(allowed);
}
+
+/** Capture once when constructing tools for the current provider request. */
- export function currentToolImagesAllowed(): boolean { return imagesAllowed; }
- const MAX_PENDING = 32;
++export function currentToolImagesAllowed(): boolean { return toolImagesAllowed(); }
+
- function holdImages(callId: string, images: PluginImage[]): void {
- pendingImages.set(callId, images);
- while (pendingImages.size > MAX_PENDING) pendingImages.delete(pendingImages.keys().next().value as string);
- }
const TOOL_NAME_RE = /^([a-z][a-z0-9-]{1,30}[a-z0-9])__([a-z][a-z0-9_]{0,29})$/;
const liveTools = new Map<string, LiveTool>();
diff --cc src/providers/openai-compat.ts
index 4d390a6d,8c7c78b5..b58c2c07
--- a/src/providers/openai-compat.ts
+++ b/src/providers/openai-compat.ts
@@@ -41,12 -40,8 +42,13 @@@ export class OpenAICompatProvider exten
super(config);
this.name = config.name;
this.model = config.model;
+ this.usesResponsesApi = !useChatApi;
+ const attribution = aimlapiHeaders(config.baseUrl);
+ const basicAuth = basicAuthHeaders(config);
+ // So a `cat mercury.yaml` or an error that echoes it never shows the password.
+ if (config.password) registerSecretValue(config.password);
+
this.client = createOpenAI({
apiKey: config.apiKey || 'no-key',
baseURL: config.baseUrl,