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.

35.2 KB
Raw Blame
"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([["5675"],{74923(e,n,s){s.r(n),s.d(n,{metadata:()=>i,default:()=>a,frontMatter:()=>t,contentTitle:()=>d,toc:()=>o,assets:()=>l});var i=JSON.parse('{"id":"reference/plugins","title":"Writing plugins","description":"A Mercury plugin is a folder with a mercury-plugin.json manifest and code.","source":"@site/docs/reference/plugins.mdx","sourceDirName":"reference","slug":"/reference/plugins","permalink":"/docs/reference/plugins","draft":false,"unlisted":false,"editUrl":"https://github.com/cosmicstack-labs/mercury-agent/tree/main/website/docs/reference/plugins.mdx","tags":[],"version":"current","frontMatter":{"id":"plugins","title":"Writing plugins","sidebar_label":"Writing plugins"},"sidebar":"docsSidebar","previous":{"title":"Permissions","permalink":"/docs/reference/permissions"},"next":{"title":"Second Brain","permalink":"/docs/reference/second-brain"}}'),r=s(74848),c=s(28453);let t={id:"plugins",title:"Writing plugins",sidebar_label:"Writing plugins"},d,l={},o=[{value:"Which kind?",id:"which-kind",level:2},{value:"The manifest",id:"the-manifest",level:2},{value:"In-process API",id:"in-process-api",level:2},{value:"Rules for a stable plugin",id:"rules-for-a-stable-plugin",level:2},{value:"Out-of-process (MCP)",id:"out-of-process-mcp",level:2},{value:"Tool images (plugin API 1.2)",id:"tool-images-plugin-api-12",level:2},{value:"Screenshots sized for the model",id:"screenshots-sized-for-the-model",level:3},{value:"Chat channels (plugin API 1.1)",id:"chat-channels-plugin-api-11",level:2},{value:"Voice sessions",id:"voice-sessions",level:3},{value:"Mercury&#39;s providers",id:"mercurys-providers",level:3},{value:"Who can talk to the agent",id:"who-can-talk-to-the-agent",level:3},{value:"Publishing",id:"publishing",level:2}];function h(e){let n={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,c.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(n.p,{children:["A Mercury plugin is a folder with a ",(0,r.jsx)(n.code,{children:"mercury-plugin.json"})," manifest and code.\nStart from a working one:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-sh",children:"mercury plugins init my-plugin                    # runs inside Mercury\nmercury plugins init my-plugin --out-of-process   # an MCP server in its own process\ncd my-plugin\nmercury plugins validate .                        # check it the way Mercury will run it\nmercury plugins install . --yes                   # try it in your Mercury\nmercury plugins pack .                            # .tgz + checksum + catalog entry\n"})}),"\n",(0,r.jsxs)(n.p,{children:["No npm package is needed: ",(0,r.jsx)(n.code,{children:"init"})," writes the API types next to your code as\n",(0,r.jsx)(n.code,{children:"mercury-plugin.d.ts"}),"."]}),"\n",(0,r.jsxs)(n.p,{children:["Mercury 1.4 implements ",(0,r.jsx)(n.strong,{children:"plugin API 1.2"}),". Minor versions only add, so a\nplugin written for 1.0 or 1.1 keeps working. The two official plugins are\nfull examples of an out-of-process plugin written in Rust:\n",(0,r.jsx)(n.a,{href:"../integrations/whatsapp",children:"WhatsApp"})," (a chat channel with voice calls, API 1.1)\nand ",(0,r.jsx)(n.a,{href:"../integrations/optimus",children:"Optimus"})," (a desktop channel with tool images,\nAPI 1.2). Their source is in\n",(0,r.jsx)(n.a,{href:"https://github.com/cosmicstack-labs/mercury-agent/tree/main/plugins",children:(0,r.jsx)(n.code,{children:"plugins/"})}),"."]}),"\n",(0,r.jsx)(n.h2,{id:"which-kind",children:"Which kind?"}),"\n",(0,r.jsxs)(n.table,{children:[(0,r.jsx)(n.thead,{children:(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.th,{}),(0,r.jsx)(n.th,{children:"In-process"}),(0,r.jsx)(n.th,{children:"Out-of-process"})]})}),(0,r.jsxs)(n.tbody,{children:[(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"Runs"}),(0,r.jsxs)(n.td,{children:["Inside Mercury, loaded with ",(0,r.jsx)(n.code,{children:"import()"})]}),(0,r.jsx)(n.td,{children:"As a child process speaking MCP over stdio"})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"Good for"}),(0,r.jsx)(n.td,{children:"Small, fast tools; slash commands"}),(0,r.jsx)(n.td,{children:"Native code, heavy work, existing MCP servers, other languages"})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"If it crashes"}),(0,r.jsx)(n.td,{children:"Errors are contained and counted; repeated failures turn it off"}),(0,r.jsx)(n.td,{children:"Mercury restarts it; repeated crashes turn it off"})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"Slash commands"}),(0,r.jsx)(n.td,{children:"Yes"}),(0,r.jsx)(n.td,{children:"Not yet (plugin API 1.2)"})]})]})]}),"\n",(0,r.jsx)(n.h2,{id:"the-manifest",children:"The manifest"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-json",children:'{\n  "manifestVersion": 1,\n  "id": "weather",\n  "name": "Weather",\n  "version": "1.2.0",\n  "description": "Forecasts and alerts.",\n  "kind": "in-process",\n  "engines": { "mercury": ">=1.4.0 <2.0.0", "pluginApi": "^1.0.0" },\n  "entry": "index.mjs",\n  "contributes": {\n    "tools": [{ "name": "forecast", "description": "Get the forecast for a city.", "readOnly": true, "timeoutMs": 20000 }],\n    "commands": [{ "name": "weather", "description": "Today\'s weather" }]\n  },\n  "permissions": { "network": ["api.weather.example"], "secrets": ["WEATHER_API_KEY"] },\n  "settings": {\n    "version": 2,\n    "fields": { "unit": { "type": "enum", "options": ["c", "f"], "default": "c" } },\n    "migrations": [{ "to": 2, "rename": { "units": "unit" }, "mapValues": { "unit": { "celsius": "c", "fahrenheit": "f" } } }]\n  }\n}\n'})}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:["\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.strong,{children:"Settings"})," can carry setup metadata. Settings with ",(0,r.jsx)(n.code,{children:'"setup": true'})," are\nasked in order right after install, in chat or in the terminal. Every\nsetting with a ",(0,r.jsx)(n.code,{children:"label"})," is listed on the plugin's ",(0,r.jsx)(n.code,{children:"/plugins ID"})," menu with its\ncurrent value. The metadata fields are:"]}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"label"}),': a plain question, such as "Which number will you chat from?";']}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"required"}),": setup can't finish without a value;"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"optionLabels"}),": what each choice does, for enum options and for booleans\nunder ",(0,r.jsx)(n.code,{children:'"true"'})," and ",(0,r.jsx)(n.code,{children:'"false"'}),' ("On: Mercury picks up when you call it").\nThe menu repeats the chosen label after saving, so the owner reads what\nthe choice does, not just "yes";']}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"examples"}),": one-tap suggestions for a string or number setting (typing\nyour own still works);"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:'"format": "phone"'}),", which is validated and normalised to ",(0,r.jsx)(n.code,{children:"+digits"}),";"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"when"}),": show the setting only when other settings have these values,\nsuch as ",(0,r.jsx)(n.code,{children:'{ "voiceEngine": ["gemini"] }'}),". A list of conditions means any of\nthem. After the owner changes a setting in the menu, Mercury asks straight\naway for the settings that now apply (pick Gemini, then the Gemini key);"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"group"}),": put the setting in a menu section declared under\n",(0,r.jsx)(n.code,{children:"settings.groups"}),", each with a ",(0,r.jsx)(n.code,{children:"label"}),", an optional ",(0,r.jsx)(n.code,{children:"description"}),", and\n",(0,r.jsx)(n.code,{children:"readyUnless"})," (requirements such as ",(0,r.jsx)(n.code,{children:'"provider:openai"'}),' that mark the\nsection "needs setup");']}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"setupWhenMissing"}),": ask this in setup only while a requirement is\nmissing. With an OpenAI provider set up, the default voice just works, so\nsetup doesn't ask which voice to use."]}),"\n"]}),"\n",(0,r.jsxs)(n.p,{children:["A setting of ",(0,r.jsx)(n.code,{children:'"type": "secret"'})," is an API key the owner pastes once. It is\nstored with Mercury's own keys (never in the plugin's settings file), shown\nonly as \"set\", and passed to the plugin as the environment variable named\nby its ",(0,r.jsx)(n.code,{children:"secret"})," field, which must also be listed in ",(0,r.jsx)(n.code,{children:"permissions.secrets"}),"."]}),"\n",(0,r.jsxs)(n.p,{children:["Chat channel plugins (WhatsApp) also get a linking step at the end of\nsetup. A ",(0,r.jsx)(n.code,{children:"desktop"})," channel has no account to link."]}),"\n"]}),"\n",(0,r.jsxs)(n.li,{children:["\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.strong,{children:"Tools"})," are shown to the model as ",(0,r.jsx)(n.code,{children:"ID__name"})," (for example\n",(0,r.jsx)(n.code,{children:"weather__forecast"}),"). ",(0,r.jsx)(n.code,{children:"readOnly"})," tools skip approval and are available in\nplan mode; every other tool asks the owner first."]}),"\n"]}),"\n",(0,r.jsxs)(n.li,{children:["\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.strong,{children:"Commands"})," can't use a built-in name (",(0,r.jsx)(n.code,{children:"/help"}),", ",(0,r.jsx)(n.code,{children:"/stop"}),", ",(0,r.jsx)(n.code,{children:"/bots"})," and so on)."]}),"\n"]}),"\n",(0,r.jsxs)(n.li,{children:["\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.strong,{children:"permissions.network"})," lists the hosts ",(0,r.jsx)(n.code,{children:"ctx.fetch"})," may reach (",(0,r.jsx)(n.code,{children:"*.example.com"}),"\nworks). Private and loopback addresses are always blocked."]}),"\n"]}),"\n",(0,r.jsxs)(n.li,{children:["\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.strong,{children:"permissions.secrets"})," lists the names from ",(0,r.jsx)(n.code,{children:"~/.mercury/.env"})," the plugin\nmay read. Nothing else is visible to it. ",(0,r.jsx)(n.code,{children:"permissions.optionalSecrets"})," maps\nthe ones it works without to what they turn on; a missing one is explained\nto the owner once."]}),"\n"]}),"\n",(0,r.jsxs)(n.li,{children:["\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.strong,{children:"permissions.desktop"})," (plugin API 1.2) says the plugin controls the\ncomputer: it sees the screen, moves the mouse and types. ",(0,r.jsx)(n.code,{children:"/plugins info"}),"\nand install show it as a warning. The plugin must also ask for consent in\nits own setup, as ",(0,r.jsx)(n.a,{href:"../integrations/optimus",children:"Optimus"}),' does with\n"Control this computer".']}),"\n"]}),"\n",(0,r.jsxs)(n.li,{children:["\n",(0,r.jsxs)(n.p,{children:["Out-of-process plugins use ",(0,r.jsx)(n.code,{children:'"server": { "command": "node", "args": ["server.mjs"] }'}),".\n",(0,r.jsx)(n.code,{children:"node"})," means Mercury's own runtime, so users don't need Node installed.\nIt can also be a binary inside the package, with per-platform variants\nunder ",(0,r.jsx)(n.code,{children:"server.platforms"})," and their SHA-256 in ",(0,r.jsx)(n.code,{children:"checksums"}),"."]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(n.h2,{id:"in-process-api",children:"In-process API"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"/** @param {import('./mercury-plugin').PluginContext} ctx */\nexport async function activate(ctx) {\n  ctx.tools.register({\n    name: 'forecast',\n    inputSchema: { type: 'object', properties: { city: { type: 'string' } }, required: ['city'] },\n    execute: async ({ city }, { signal }) => {\n      const res = await ctx.fetch(`https://api.weather.example/v1?q=${encodeURIComponent(city)}`, {\n        headers: { authorization: `Bearer ${ctx.secrets.get('WEATHER_API_KEY')}` },\n        signal,\n      });\n      return await res.json();\n    },\n  });\n  ctx.timers.setInterval(() => ctx.log.debug('tick'), 60_000);\n}\n"})}),"\n",(0,r.jsx)(n.p,{children:"The context provides:"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"ctx.tools"}),", ",(0,r.jsx)(n.code,{children:"ctx.commands"})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"ctx.settings"}),", ",(0,r.jsx)(n.code,{children:"ctx.secrets"})]}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.code,{children:"ctx.fetch"})}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.code,{children:"ctx.timers"})}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.code,{children:"ctx.log"})}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"ctx.plugin.dataDir"}),", a folder kept across updates"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"ctx.signal"}),", aborted when the plugin stops"]}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.code,{children:"ctx.onDispose"})}),"\n"]}),"\n",(0,r.jsxs)(n.p,{children:["Everything registered or scheduled through ",(0,r.jsx)(n.code,{children:"ctx"})," is cleaned up automatically\nwhen the plugin is turned off, updated or removed."]}),"\n",(0,r.jsx)(n.h2,{id:"rules-for-a-stable-plugin",children:"Rules for a stable plugin"}),"\n",(0,r.jsxs)(n.p,{children:["These are checked by ",(0,r.jsx)(n.code,{children:"mercury plugins validate"}),":"]}),"\n",(0,r.jsxs)(n.ol,{children:["\n",(0,r.jsxs)(n.li,{children:["\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.strong,{children:"One self-contained file."})," Bundle your dependencies\n(",(0,r.jsx)(n.code,{children:"esbuild src/index.ts --bundle --format=esm --platform=node --outfile=index.mjs"}),").\nA compiled Mercury can't resolve npm packages for you; only ",(0,r.jsx)(n.code,{children:"node:"}),"\nbuiltins and files in your package load."]}),"\n"]}),"\n",(0,r.jsxs)(n.li,{children:["\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.strong,{children:"Hot plug."})," Your plugin must start, stop and start again cleanly, with\nno restart of Mercury. Use ",(0,r.jsx)(n.code,{children:"ctx.timers"})," and ",(0,r.jsx)(n.code,{children:"ctx.signal"}),", not globals."]}),"\n"]}),"\n",(0,r.jsxs)(n.li,{children:["\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.strong,{children:"Clean up."})," Anything you start outside ",(0,r.jsx)(n.code,{children:"ctx"}),", stop in ",(0,r.jsx)(n.code,{children:"ctx.onDispose"}),"."]}),"\n"]}),"\n",(0,r.jsxs)(n.li,{children:["\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.strong,{children:"Versioned contract."})," Declare ",(0,r.jsx)(n.code,{children:"engines.pluginApi"}),". Plugin API minor\nversions only add. A breaking change is a new major, and the previous one\nstays supported for at least two Mercury minor releases."]}),"\n"]}),"\n",(0,r.jsxs)(n.li,{children:["\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.strong,{children:"Settings migrations."})," If you rename or remove a setting, or change its\nmeaning, do two things:"]}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:["bump ",(0,r.jsx)(n.code,{children:"settings.version"}),";"]}),"\n",(0,r.jsxs)(n.li,{children:["add a ",(0,r.jsx)(n.code,{children:"migrations"})," step (",(0,r.jsx)(n.code,{children:"rename"}),", ",(0,r.jsx)(n.code,{children:"remove"}),", ",(0,r.jsx)(n.code,{children:"mapValues"}),")."]}),"\n"]}),"\n",(0,r.jsx)(n.p,{children:"Saved values then carry over on update. Rolling back restores the older\nversion's settings."}),"\n"]}),"\n",(0,r.jsxs)(n.li,{children:["\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.strong,{children:"No plugin-to-plugin dependencies"})," (as of plugin API 1.2). Each plugin stands\nalone."]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(n.h2,{id:"out-of-process-mcp",children:"Out-of-process (MCP)"}),"\n",(0,r.jsx)(n.p,{children:"Mercury starts the server and runs the handshake:"}),"\n",(0,r.jsxs)(n.ol,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"initialize"}),", then ",(0,r.jsx)(n.code,{children:"notifications/initialized"})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"tools/list"}),", which exposes only the tools your manifest declares"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"tools/call"})," for each tool use"]}),"\n"]}),"\n",(0,r.jsxs)(n.p,{children:["It also handles ",(0,r.jsx)(n.code,{children:"ping"})," and ",(0,r.jsx)(n.code,{children:"notifications/tools/list_changed"}),". It cancels\ncalls with ",(0,r.jsx)(n.code,{children:"notifications/cancelled"})," when a turn stops."]}),"\n",(0,r.jsx)(n.p,{children:"What your server receives:"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Settings:"})," JSON in the ",(0,r.jsx)(n.code,{children:"MERCURY_PLUGIN_SETTINGS"})," environment variable."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Data folder:"})," ",(0,r.jsx)(n.code,{children:"MERCURY_PLUGIN_DATA_DIR"}),"."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Secrets:"})," the declared secrets, as environment variables."]}),"\n"]}),"\n",(0,r.jsx)(n.p,{children:"Write logs to stderr. Stdout is the protocol channel."}),"\n",(0,r.jsx)(n.h2,{id:"tool-images-plugin-api-12",children:"Tool images (plugin API 1.2)"}),"\n",(0,r.jsxs)(n.p,{children:["An out-of-process tool can return images to the model next to its text, as\nstandard MCP ",(0,r.jsx)(n.code,{children:"image"})," content:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-json",children:'{ "content": [\n  { "type": "text", "text": "Sent: click (640, 380)." },\n  { "type": "image", "data": "<base64>", "mimeType": "image/jpeg" }\n] }\n'})}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Types:"})," ",(0,r.jsx)(n.code,{children:"image/png"}),", ",(0,r.jsx)(n.code,{children:"image/jpeg"}),", ",(0,r.jsx)(n.code,{children:"image/webp"}),", ",(0,r.jsx)(n.code,{children:"image/gif"}),"."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Limits:"})," 4 images per result, about 6 MB each."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Kept out of history."})," The images go to the model with that one tool\nresult. Chat history, logs and memory only ever see the text."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Text-only models"})," get the text plus a note that an image was left out."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Models whose API takes images only from the user"})," (OpenAI-compatible chat:\nOpenRouter, LiteLLM, Mercury Cloud, Ollama, LM Studio) get the image in a\nmessage right after the tool result. Only the newest two screenshots are kept."]}),"\n"]}),"\n",(0,r.jsxs)(n.p,{children:["Require ",(0,r.jsx)(n.code,{children:'"pluginApi": "^1.2.0"'})," to use it."]}),"\n",(0,r.jsx)(n.h3,{id:"screenshots-sized-for-the-model",children:"Screenshots sized for the model"}),"\n",(0,r.jsxs)(n.p,{children:["Models are billed for an image by its pixels, by rules that differ per family.\nA tool that takes screenshots can let Mercury choose the size for the model in\nuse by declaring a ",(0,r.jsx)(n.code,{children:"mercury_screenshot"})," parameter in its input schema (or\n",(0,r.jsx)(n.code,{children:'"screenshots": true'})," on the tool in the manifest):"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-json",children:'"mercury_screenshot": { "type": "object", "description": "Set by Mercury; leave it out.",\n  "properties": { "include": { "type": "boolean" }, "max_width": { "type": "integer" }, "max_height": { "type": "integer" } } }\n'})}),"\n",(0,r.jsx)(n.p,{children:"Mercury hides the parameter from the model and fills it on every call:"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"max_width"})," \xd7 ",(0,r.jsx)(n.code,{children:"max_height"}),": fit the screenshot in this box (never enlarge it).\nFor example, Claude and OpenAI get 1024\xd7640, Gemini 768\xd7480, and open vision\nmodels 896\xd7560. Shrink the capture yourself, so the coordinates the model\nclicks stay in the picture it saw."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"include: false"}),": the model can't see images. Don't capture; say in text\nwhat is on screen (for example, the active window)."]}),"\n"]}),"\n",(0,r.jsxs)(n.p,{children:["An older Mercury shows the parameter as optional, so the model may leave it out.\nTreat a missing value as your own default. The owner can set one size for\nevery model with ",(0,r.jsx)(n.code,{children:"MERCURY_SCREENSHOT_BOX=1280x800"}),"."]}),"\n",(0,r.jsx)(n.h2,{id:"chat-channels-plugin-api-11",children:"Chat channels (plugin API 1.1)"}),"\n",(0,r.jsxs)(n.p,{children:["An out-of-process plugin can provide a chat channel. The channel types are\n",(0,r.jsx)(n.code,{children:"whatsapp"})," (plugin API 1.1, see ",(0,r.jsx)(n.a,{href:"../integrations/whatsapp",children:"WhatsApp"}),") and\n",(0,r.jsx)(n.code,{children:"desktop"})," (plugin API 1.2, see ",(0,r.jsx)(n.a,{href:"../integrations/optimus",children:"Optimus"}),"). Declare\nit and require the matching API:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-json",children:'"engines": { "mercury": ">=1.4.0 <2.0.0", "pluginApi": "^1.1.0" },\n"contributes": { "channel": { "type": "whatsapp" } },\n"settings": { "version": 1, "fields": {\n  "owner": { "type": "string", "description": "The owner\'s phone number", "format": "phone" },\n  "members": { "type": "string", "description": "Other numbers allowed to chat, comma separated" },\n  "allowGroups": { "type": "boolean", "default": false }\n} }\n'})}),"\n",(0,r.jsxs)(n.p,{children:["Mercury sends ",(0,r.jsx)(n.code,{children:'capabilities.experimental["mercury/channel"]'})," in\n",(0,r.jsx)(n.code,{children:"initialize"}),". After that, the same stdio connection carries the following\nmessages."]}),"\n",(0,r.jsxs)(n.table,{children:[(0,r.jsx)(n.thead,{children:(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.th,{children:"Direction"}),(0,r.jsx)(n.th,{children:"Message"}),(0,r.jsx)(n.th,{children:"Params"})]})}),(0,r.jsxs)(n.tbody,{children:[(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"plugin \u2192 Mercury (notification)"}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"mercury/channel/status"})}),(0,r.jsxs)(n.td,{children:[(0,r.jsx)(n.code,{children:"state"})," (",(0,r.jsx)(n.code,{children:"starting"}),", ",(0,r.jsx)(n.code,{children:"needs-pairing"}),", ",(0,r.jsx)(n.code,{children:"pairing"}),", ",(0,r.jsx)(n.code,{children:"connected"}),", ",(0,r.jsx)(n.code,{children:"disconnected"}),", ",(0,r.jsx)(n.code,{children:"logged-out"}),", ",(0,r.jsx)(n.code,{children:"error"}),"), ",(0,r.jsx)(n.code,{children:"detail?"}),", ",(0,r.jsx)(n.code,{children:"account?"}),", ",(0,r.jsx)(n.code,{children:"qr?"}),", ",(0,r.jsx)(n.code,{children:"pairCode?"})]})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"plugin \u2192 Mercury (notification)"}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"mercury/channel/message"})}),(0,r.jsxs)(n.td,{children:[(0,r.jsx)(n.code,{children:"id"}),", ",(0,r.jsx)(n.code,{children:"chatId"}),", ",(0,r.jsx)(n.code,{children:"senderId"}),", ",(0,r.jsx)(n.code,{children:"senderPhone?"}),", ",(0,r.jsx)(n.code,{children:"senderName?"}),", ",(0,r.jsx)(n.code,{children:"isGroup?"}),", ",(0,r.jsx)(n.code,{children:"fromMe?"}),", ",(0,r.jsx)(n.code,{children:"text?"}),", ",(0,r.jsx)(n.code,{children:"attachments?"})," (each with ",(0,r.jsx)(n.code,{children:"kind"}),", ",(0,r.jsx)(n.code,{children:"path"}),", ",(0,r.jsx)(n.code,{children:"mime?"}),", ",(0,r.jsx)(n.code,{children:"name?"}),"), ",(0,r.jsx)(n.code,{children:"timestamp?"})]})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"plugin \u2192 Mercury (notification)"}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"mercury/channel/activity"})}),(0,r.jsxs)(n.td,{children:[(0,r.jsx)(n.code,{children:"listening"}),", ",(0,r.jsx)(n.code,{children:"working"}),", ",(0,r.jsx)(n.code,{children:"muted"})," (API 1.2, desktop: shown in the terminal status bar)"]})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"Mercury \u2192 plugin (request)"}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"mercury/channel/send"})}),(0,r.jsxs)(n.td,{children:[(0,r.jsx)(n.code,{children:"chatId"}),", ",(0,r.jsx)(n.code,{children:"text"})]})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"Mercury \u2192 plugin (request)"}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"mercury/channel/sendFile"})}),(0,r.jsxs)(n.td,{children:[(0,r.jsx)(n.code,{children:"chatId"}),", ",(0,r.jsx)(n.code,{children:"path"}),", ",(0,r.jsx)(n.code,{children:"caption?"})]})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"Mercury \u2192 plugin (request)"}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"mercury/channel/typing"})}),(0,r.jsxs)(n.td,{children:[(0,r.jsx)(n.code,{children:"chatId"}),", ",(0,r.jsx)(n.code,{children:"on"})]})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"Mercury \u2192 plugin (request)"}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"mercury/channel/pair"})}),(0,r.jsxs)(n.td,{children:[(0,r.jsx)(n.code,{children:"method"})," (",(0,r.jsx)(n.code,{children:"qr"})," or ",(0,r.jsx)(n.code,{children:"code"}),"), ",(0,r.jsx)(n.code,{children:"phone?"})]})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"Mercury \u2192 plugin (request)"}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"mercury/channel/unlink"})}),(0,r.jsx)(n.td,{children:"none"})]})]})]}),"\n",(0,r.jsxs)(n.p,{children:["Photos and PDFs in ",(0,r.jsx)(n.code,{children:"attachments"})," are passed to the model when it accepts\nthem. Voice notes are transcribed with the owner's OpenAI provider before the\nmessage reaches the agent."]}),"\n",(0,r.jsx)(n.h3,{id:"voice-sessions",children:"Voice sessions"}),"\n",(0,r.jsxs)(n.p,{children:["A channel plugin can also carry ",(0,r.jsx)(n.strong,{children:"voice"}),": calls on WhatsApp, or listening\nmode at the computer for a ",(0,r.jsx)(n.code,{children:"desktop"})," channel. Both use the same messages."]}),"\n",(0,r.jsxs)(n.table,{children:[(0,r.jsx)(n.thead,{children:(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.th,{children:"Direction"}),(0,r.jsx)(n.th,{children:"Message"}),(0,r.jsx)(n.th,{children:"Params \u2192 result"})]})}),(0,r.jsxs)(n.tbody,{children:[(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"plugin \u2192 Mercury (request)"}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"mercury/call/incoming"})}),(0,r.jsxs)(n.td,{children:[(0,r.jsx)(n.code,{children:"callId"}),", ",(0,r.jsx)(n.code,{children:"from"}),", ",(0,r.jsx)(n.code,{children:"fromPhone?"}),", ",(0,r.jsx)(n.code,{children:"voiceReady"})," \u2192 ",(0,r.jsx)(n.code,{children:"accept"}),", ",(0,r.jsx)(n.code,{children:"instructions?"})]})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"plugin \u2192 Mercury (request)"}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"mercury/call/briefing"})}),(0,r.jsxs)(n.td,{children:[(0,r.jsx)(n.code,{children:"callId"})," \u2192 ",(0,r.jsx)(n.code,{children:"instructions"})]})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"plugin \u2192 Mercury (request)"}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"mercury/call/ask"})}),(0,r.jsxs)(n.td,{children:[(0,r.jsx)(n.code,{children:"callId"}),", ",(0,r.jsx)(n.code,{children:"question"})," \u2192 ",(0,r.jsx)(n.code,{children:"answer"})," (runs a normal Mercury turn)"]})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"plugin \u2192 Mercury (request)"}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"mercury/call/approve"})}),(0,r.jsxs)(n.td,{children:[(0,r.jsx)(n.code,{children:"callId"}),", ",(0,r.jsx)(n.code,{children:"approvalId"}),", ",(0,r.jsx)(n.code,{children:"approved"})," \u2192 ",(0,r.jsx)(n.code,{children:"ok"})]})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"plugin \u2192 Mercury (request)"}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"mercury/call/schedule"})}),(0,r.jsxs)(n.td,{children:[(0,r.jsx)(n.code,{children:"when"}),", ",(0,r.jsx)(n.code,{children:"topic"})," \u2192 ",(0,r.jsx)(n.code,{children:"ok"}),", ",(0,r.jsx)(n.code,{children:"text"})]})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"plugin \u2192 Mercury (request)"}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"mercury/call/stop"})}),(0,r.jsxs)(n.td,{children:[(0,r.jsx)(n.code,{children:"callId"})," \u2192 ",(0,r.jsx)(n.code,{children:"stopped"})]})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"plugin \u2192 Mercury (notification)"}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"mercury/call/ended"})}),(0,r.jsxs)(n.td,{children:[(0,r.jsx)(n.code,{children:"callId"}),", ",(0,r.jsx)(n.code,{children:"direction"}),", ",(0,r.jsx)(n.code,{children:"outcome"}),", ",(0,r.jsx)(n.code,{children:"durationSec"}),", ",(0,r.jsx)(n.code,{children:"transcript"}),", ",(0,r.jsx)(n.code,{children:"reason?"})]})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"Mercury \u2192 plugin (notification)"}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"mercury/call/progress"})}),(0,r.jsxs)(n.td,{children:[(0,r.jsx)(n.code,{children:"callId"}),", ",(0,r.jsx)(n.code,{children:"activity"})," (what the running turn is doing now)"]})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"Mercury \u2192 plugin (notification)"}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"mercury/call/context"})}),(0,r.jsxs)(n.td,{children:[(0,r.jsx)(n.code,{children:"callId"}),", ",(0,r.jsx)(n.code,{children:"text"})," (something happened in the chat, such as a photo arriving)"]})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"Mercury \u2192 plugin (notification)"}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"mercury/call/approval"})}),(0,r.jsxs)(n.td,{children:[(0,r.jsx)(n.code,{children:"callId"}),", ",(0,r.jsx)(n.code,{children:"approvalId"}),", ",(0,r.jsx)(n.code,{children:"prompt"})," (ask the owner out loud)"]})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"Mercury \u2192 plugin (notification)"}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"mercury/call/approval-resolved"})}),(0,r.jsxs)(n.td,{children:[(0,r.jsx)(n.code,{children:"callId"}),", ",(0,r.jsx)(n.code,{children:"approvalId"}),", ",(0,r.jsx)(n.code,{children:"decision"}),", ",(0,r.jsx)(n.code,{children:"via"})]})]})]})]}),"\n",(0,r.jsx)(n.p,{children:"How these work:"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsxs)(n.strong,{children:[(0,r.jsx)(n.code,{children:"incoming"}),":"]})," Mercury answers only the owner, and only when the plugin\nsays its voice engine is ready."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsxs)(n.strong,{children:[(0,r.jsx)(n.code,{children:"ask"}),":"]})," runs a normal Mercury turn whose answer is spoken back."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Approvals:"})," a turn that needs approval during a call sends\n",(0,r.jsx)(n.code,{children:"approval"}),". On WhatsApp it is also posted in the chat; the first answer\nwins. The plugin sends ",(0,r.jsx)(n.code,{children:"approve"}),' only after checking that the owner\'s own\ntranscribed words said yes, and a spoken yes never becomes "always". No\nanswer within 2 minutes is no.']}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsxs)(n.strong,{children:[(0,r.jsx)(n.code,{children:"schedule"}),":"]}),' "call me back at 9" on a call. The time is worked out by\nMercury, not by a model.']}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsxs)(n.strong,{children:[(0,r.jsx)(n.code,{children:"stop"}),":"]})," the owner said stop or goodbye: Mercury ends the work the\nsession started."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsxs)(n.strong,{children:[(0,r.jsx)(n.code,{children:"ended"}),":"]})," on WhatsApp, sends the owner a summary with the transcript.\nA desktop session reports only failures."]}),"\n"]}),"\n",(0,r.jsx)(n.h3,{id:"mercurys-providers",children:"Mercury's providers"}),"\n",(0,r.jsxs)(n.p,{children:["A plugin that needs one of Mercury's AI providers (",(0,r.jsx)(n.code,{children:"openai"})," or ",(0,r.jsx)(n.code,{children:"grok"}),")\ndeclares it, so the owner sets a key in one place:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-json",children:'"permissions": { "providers": {\n  "openai": { "unlocks": "Voice calls", "when": { "voiceEngine": "openai" },\n              "alternative": "Or pick another voice in /plugins whatsapp \u2192 Voice calls." }\n} }\n'})}),"\n",(0,r.jsxs)(n.p,{children:["The short form ",(0,r.jsx)(n.code,{children:'{ "openai": "Voice calls" }'})," also works. Mercury passes the\nkey the owner already set up as ",(0,r.jsx)(n.code,{children:"MERCURY_PROVIDER_OPENAI_API_KEY"})," and\n",(0,r.jsx)(n.code,{children:"MERCURY_PROVIDER_OPENAI_BASE_URL"})," (",(0,r.jsx)(n.code,{children:"MERCURY_PROVIDER_GROK_\u2026"})," for Grok). With\n",(0,r.jsx)(n.code,{children:"when"}),", the provider is only required while the settings match. If it isn't\nset up, the owner is told once what it turns off, and ",(0,r.jsx)(n.code,{children:"/plugins info"})," shows\nit."]}),"\n",(0,r.jsx)(n.h3,{id:"who-can-talk-to-the-agent",children:"Who can talk to the agent"}),"\n",(0,r.jsx)(n.p,{children:"Mercury, not the plugin, decides:"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Access:"})," only the ",(0,r.jsx)(n.code,{children:"owner"})," number and listed ",(0,r.jsx)(n.code,{children:"members"})," get through.\nUnknown senders are dropped, groups are ignored unless ",(0,r.jsx)(n.code,{children:"allowGroups"})," is\non, and your own messages are never answered. A ",(0,r.jsx)(n.code,{children:"desktop"})," channel only\never talks to the owner at the computer."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Formatting:"})," Mercury converts Markdown to the channel's formatting and\nsplits long replies."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Approvals:"})," prompts are answered by a text reply: 1 for yes, 2 for no,\n3 for always."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Linking:"})," owners link the account with ",(0,r.jsx)(n.code,{children:"mercury plugins pair ID"})," (QR\ncode) or ",(0,r.jsx)(n.code,{children:"/plugins pair ID PHONE"})," (pairing code)."]}),"\n"]}),"\n",(0,r.jsx)(n.h2,{id:"publishing",children:"Publishing"}),"\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.code,{children:"mercury plugins pack ."})," writes ",(0,r.jsx)(n.code,{children:"ID-VERSION.tgz"})," and prints its SHA-256 and\na catalog entry. Then:"]}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Share it from GitHub."})," Attach the file to a GitHub release as\n",(0,r.jsx)(n.code,{children:"mercury-plugin.tgz"})," (or ",(0,r.jsx)(n.code,{children:"mercury-plugin-PLATFORM.tgz"})," per platform).\nAnyone can then install it with ",(0,r.jsx)(n.code,{children:"mercury plugins install github:owner/repo"}),"."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsxs)(n.strong,{children:["List it in ",(0,r.jsx)(n.code,{children:"/plugins"}),"."]})," Open a pull request adding the entry to the\ncatalog at ",(0,r.jsx)(n.code,{children:"website/static/plugins/catalog.json"}),". Catalog installs are\nchecksum-verified."]}),"\n"]})]})}function a(e={}){let{wrapper:n}={...(0,c.R)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},28453(e,n,s){s.d(n,{R:()=>t,x:()=>d});var i=s(96540);let r={},c=i.createContext(r);function t(e){let n=i.useContext(c);return i.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function d(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:t(e.components),i.createElement(c.Provider,{value:n},e.children)}}}]);