Plan: plugins, MCP and the agent chat mode (t187u-t189u)

Status: P1-P6 done (P5 open questions 12-14 answered with the plan's proposals: chat on a, screen + 200 lines, transcripts kept; P6 questions 15-16 left open: the mouser engine alias stays, skia stays in the package; m3talsmith may change them) (docs/plugins.md, docs/mcp.md) (decisions below are m3talsmith's, t196u-t198u). Written 2026-10-31 after Phase 1 (commander) closed. Each step below has its scope, architecture, dependencies (⚠ = needs m3talsmith's install approval), security model, tests, rough size and open questions. Section 9 lists the sources behind the facts in it.

Decisions (m3talsmith, t196u-t198u)

These replace the provisional defaults the first draft proposed.

  1. Plugins connect three ways: MCP, Fuzzball, and a mouser command. A command plugin registers commands on the [mouser] command line, backed by an external executable: Mouser runs it with a JSON request on stdin and reads a JSON reply from stdout. (Interpretation; m3talsmith may clarify.) No native-library plugins in v1: engines keep their own C ABI, nothing else loads code in-process.
  2. Mouser's MCP server (P2) offers stdio, loopback HTTP, and an HTTPS option (TLS with the user's certificate, or a generated self-signed one).
  3. The local model is llama.cpp built in, plus an option to point at any OpenAI- and/or Anthropic-compatible inference URL (llama-server, Ollama, vLLM, …).
  4. The default local model is Gemma 4 E2B, with a setting to switch to E4B.
  5. Bringing in any model is a plugin. model-provider is a plugin kind; the Gemma/llama.cpp plugin is just the first one, and the frontier adapters (OpenAI, Anthropic, Google, xAI, Moonshot/Kimi, OpenRouter) are model-provider plugins too. Others can ship plugins for other models through the same interface.

0. Phases at a glance

# Phase Depends on Rough size Ships
P1 Plugin system core: manifest, registry, CLI, permissions, Fuzzball + MCP hooks – L (3-4 wk) mouser plugin …, approval prompts, example plugins
P2 Mouser as an MCP server P1 (permissions) M (1.5-2 wk) mouser mcp serve (stdio) + loopback Streamable HTTP + HTTPS option, token auth
P3 MCP client + sidebar P1 M (1.5 wk) [[mcp.servers]] in preferences.toml, sidebar section
P4 Model providers as plugins P1 M-L (2-3 wk) the model-provider plugin kind; frontier adapters as plugins; keys in the OS keychain
P4b Embedded local model plugin (optional) P4 M (1.5-2 wk) the first model plugin: llama.cpp + Gemma 4 E2B (E4B switch), or an OpenAI/Anthropic-compatible URL; downloads only with consent
P5 Agent chat mode P2, P3, P4 L (3 wk) dock above the prompt, tools with per-action approval, transcript, cancel
P6 Convert modes and engines to plugins (t189u) P1-P5 M-L (2-3 wk) commander, chat and the engines loaded through the plugin registry

Sizes assume one developer at the Phase 1 pace, with tests and docs. P2 and P3 can run side by side once P1 has landed, and P4 can overlap with them.

1. Principles

2. P1: the plugin system

Scope

Manifest (plugin.toml)

name = "chat"
        version = "0.1.0"
        api = 1                       # plugin API version
        description = "Agent chat mode"
        authors = ["WeirdBrains"]
        
        [[provides]]
        kind = "mode"                 # mode | engine | model-provider | tool-provider
        id = "chat"
        hotkey = "a"
        
        [run]                         # how it is reached: mcp | fuzzball | command
        transport = "mcp"
        command = ["mouser-chat-plugin", "--stdio"]   # mcp over stdio
        # transport = "command": command = [...] plus commands = ["hello"] on the [mouser] line
        
        [permissions]                 # asked for on install, shown in `plugin permissions`
        screen_read = true            # visible text of the active tab
        scrollback = false
        shell_type = "ask"            # type into / run in a shell: never | ask | allow
        files = { read = ["$CWD"], write = "ask" }
        network = ["api.anthropic.com"]
        models = "ask"                # may start / download a model
        

Architecture

Dependencies

Security

Testing

Size and open questions

3. P2: Mouser as an MCP server

Scope

Expose Mouser to any MCP client (Claude Desktop, Cursor, other agents, and Mouser's own chat mode).

Tool / resource What Permission
tabs.list, tabs.focus, tabs.new, tabs.close tabs and titles, cwd/place (local or user@host:/dir) read: allow; others: ask
screen.read (resource mouser://tab/<id>/screen) visible text with the cursor position screen_read
scrollback.read (range, search) history lines scrollback
shell.type type text into a tab, no Enter shell_type (ask)
shell.run keep_line run (the commander path), waits for the prompt (OSC 133 if present), returns the output shell_type (ask, shows the command)
files.list, files.read, files.copy, files.move, files.mkdir, files.trash commander file ops, local or remote via fetch files.read / files.write (ask)
commander.view switch the view, select or open an item allow

Architecture

Security

Dependencies

Testing

Size and open questions

4. P3: MCP client and the sidebar

Done (as built):

  • Hand-rolled client on std + rustls, like P2, not rmcp: stdio plus Streamable HTTP(S) with JSON/SSE replies.
  • [[mcp.servers]] takes command/env/url/token/ca/enabled; the token is sent as a bearer.
  • Per-server threads reconnect with backoff and ping.
  • The sidebar MCP section has expandable tool lists; the [mouser] line has mcp ….
  • Broker capability tool.<name>.
  • Deferred: resources, prompts, list-changed, server/discover, OAuth (Q7), project-local config (Q8), per-server enable toggles in the sidebar.

Scope

Config (preferences.toml)

[[mcp.servers]]
        name = "github"
        command = ["github-mcp-server", "stdio"]     # stdio: Mouser starts it
        env = { GITHUB_TOKEN = "keychain:github" }   # secrets by reference, never inline
        enabled = true
        
        [[mcp.servers]]
        name = "docs"
        url = "https://example.com/mcp"              # Streamable HTTP
        auth = "keychain:docs-token"                 # or "oauth" (rmcp auth feature)
        

Architecture

Security

Testing

Size and open questions

5. P4: model providers as plugins

Done (as built), see docs/models.md:

  • Hand-rolled streaming HTTP/SSE on std + rustls, not reqwest.
  • Adapters: OpenAI-compatible Chat Completions, Anthropic Messages, and native Google (Gemini's compatible URL goes through openai).
  • [models] prefs, mouser model list/add/remove/test/default, and keys via --key-stdin into the keychain.
  • Built-in model-provider plugins, plus plugins with a [model] table (transport = "http").
  • gemma-local is stubbed (E2B default, E4B switch).
  • Deferred: Responses API, images, retries, server-side model lists, the network grant for plugin hosts, and mouser model key set with a no-echo prompt (add --key-stdin does that job).

One interface (mouser_core::models)

trait ModelProvider: Send + Sync {
            fn id(&self) -> &str;                          // "anthropic", "local-gemma", …
            fn models(&self) -> Vec<ModelInfo>;            // name, context, tools?, vision?
            fn chat(&self, req: ChatRequest, sink: &mut dyn ChatSink) -> Result<(), ModelError>;
            // ChatRequest: system, messages (text/image/tool results), tools (JSON schema),
            // tool_choice, max_tokens, temperature (optional; some models fix it)
            // ChatSink: text deltas, tool-call deltas, usage, done; cancel via a token
        }
        

API keys

Dependencies

Testing

Size

M-L, 2-3 weeks.

6. P4b: the embedded local model (optional plugin)

Choice of model

Gemma 4 E2B-it as the default, E4B as the step up.

FunctionGemma 270M (Gemma 3 based, about 290 MB, Gemma Terms of Use) is the lightest tool caller. Its own model card and independent benchmarks say it needs fine-tuning: base multi-turn tool calling scores 10-39%. So it is offered as an "experimental / tiny" option, not the default. A Mouser-specific FunctionGemma fine-tune is possible later (open question).

Runtime

Dependencies ⚠ (need m3talsmith's approval)

Security

Testing

Size and open questions

7. P5: the agent chat mode

Scope

Architecture

Security

Testing

Size and open questions

8. P6: modes and engines become plugins (t189u)

Scope

Register commander, chat and the built-in engines (mouser/wgpu, skia, flat) through the plugin registry, with their own plugin.toml, instead of hard-coded lists. Behaviour and keymaps stay the same.

How it stays a refactor

Testing

The existing commander and engine tests run unchanged against the registry path. A test checks that mouser engine list and mouser plugin list --kind engine agree, plus a migration test for old preferences.

Size and open questions

As built (P6)

9. Sources (checked 2026-10-31)

Source: docs/historical/mcp-agent.md