The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
docs(mcp): add README for the MCP module
Steven Enamakel2c7a5177ba3e
diff --git a/crates/openhuman-core/src/mcp/README.md b/crates/openhuman-core/src/mcp/README.mdindex 38b8281435..75dfa7bf8b 100644--- a/crates/openhuman-core/src/mcp/README.md+++ b/crates/openhuman-core/src/mcp/README.md@@ -1,114 +1,214 @@-# mcp: MCP host--Host-side half of Model Context Protocol support. Both transports, the-static config-declared server set, the dynamic (Smithery/official-catalog)-registry with its store, its reconnect supervisor and browser sign-in, and-the write-audit log moved out to [`tinymcp`](https://github.com/tinyhumansai/tinymcp).-What is here is what belongs to this application: the one holder of that-library's services, the RPC surface over it, the agent-facing tools, and the-`openhuman mcp` server that exposes this application's own tools to external-MCP hosts.--## Responsibilities--- Hold the `tinymcp` service, one per workspace, and open it at boot- ([`host`]).-- Expose the `mcp_clients` RPC namespace (including the user's `mcp.json`- document), the agent-facing `mcp_registry_*` tools, and the- prompt-injection scan over remote tool definitions ([`registry`]).-- Expose the RPC surface over the write-audit log ([`audit`]).-- Run the `openhuman mcp` stdio/HTTP server that serves this application's- own tools to external MCP clients ([`server`]), the *server* side, which- did not move because it is bound to the tool registry, the permission- model and the agent turn machinery.--## Where the boundary fell--Three things stayed here on purpose, each because it is host policy rather-than protocol:--- **Prompt-injection detection** over remote tool definitions- (`registry::tools_safe_for_agent`). The detector, its rules, and what a hit- means belong to this application's threat model. The *lexical* half- (control characters, prompt-template fences, length caps) lives in the- contract instead, applied by the display accessors on every remote- description.-- **Events.** `tinymcp` reports what happened in its return values;- translating that into a `DomainEvent` happens here, where the vocabulary is- known (`registry::ops`/`setup_ops` for the RPC-driven lifecycle events,- `registry::supervisor_events` for what the reconnect supervisor observed,- `registry::tools_safe_for_agent` for `McpToolRejected`). `audit` publishes+# mcp++The host half of Model Context Protocol support. The MCP client itself (both+transports, the config-declared server set, the dynamic server registry with+its store, reconnect supervisor and browser sign-in, and the write-audit log)+lives in the vendored `tinymcp` library. This folder holds what belongs to+OpenHuman: the one `tinymcp` service per workspace, the RPC surface over it,+the agent-facing tools, the prompt-injection screen over remote tool+definitions, and the `openhuman-core mcp` server that exposes OpenHuman's own+tools to external MCP hosts such as Claude Desktop or Cursor.++## How it works++There are two directions. As a client, OpenHuman connects to MCP servers the+user declared and lets its agents call their tools. As a server, it answers+other MCP hosts that call into it.++```text+ client side server side+ +-------------------------------+ +------------------------------++ | agent tools | | external MCP host |+ | mcp_registry_* (registry/) | | (Claude Desktop, Cursor, |+ | mcp_<server>_<tool> | | sandboxed claude subprocess)|+ | installed-server actions | +--------------+---------------++ | mcp_list_servers/... (tools/ | | stdio or HTTP+ | impl/network, static set) | v+ +---------------+---------------+ +------------------------------++ | | server/ OpenHumanMcpHandler |+ RPC mcp_clients.*, mcp_audit.* | over tinymcp::server |+ | +--------------+---------------++ v |+ +-------------------------------+ v+ | host.rs McpHost per workspace| registered core RPC methods+ | dynamic() static_servers() | (memory, agent, search, ...)+ | audit() | under SecurityPolicy, with+ +---------------+---------------+ writes recorded to the audit log+ |+ v+ vendor/tinymcp+```++### The service holder++`host.rs` keeps a process-wide map (`HOSTS`) from workspace path to one+`McpHost`. An `McpHost` wraps the `tinymcp` service and exposes its three+parts: `dynamic()` (the user-declared registry), `static_servers()` (the+TOML-declared set) and `audit()` (the write-audit store). The library holds no+globals of its own, so two hosts in one process do not share connections;+this holder is the one place that decides there is one per workspace.++`host::init` opens the service at boot. A caller that arrives earlier gets+`None` from `try_service` rather than a service built on a configuration+nobody chose. `for_config` opens or returns the host for a specific+workspace, and `all_hosts` lets the supervisor walk every workspace opened so+far. `client_config` converts OpenHuman's `[mcp_client]` config into+`tinymcp`'s `McpClientConfig`.++### Startup++```text+ core/runtime/subscribers.rs (RPC enable path) core/runtime/services.rs+ | |+ v v+ mcp::start mcp::start_boot_jobs+ registry::bus::init() mcp::start+ host::init() (failure logged, ignored) spawn installed-server boot+ spawn configured tool-cache refresh+ spawn reconnect supervisor (Once)+```++Both entry points are idempotent, so the two startup paths can both call+them. `mcp::start` never fails: MCP being unavailable must not stop the core+coming up. The boot jobs dial installed servers, refresh every configured+server's cached tool list once per app load, and start the reconnect+supervisor exactly once per process. Between loads the tool cache changes+only on an MCP change (connect, credentials, disable, uninstall, an edited+definition).++### What stayed host-side, and why++Three things are host policy rather than protocol:++- Prompt-injection detection over remote tool definitions.+ `registry::tools_safe_for_agent` (`registry/mod.rs`) drops a tool whose+ description trips a rule, and logs and publishes `McpToolRejected` with the+ rule code only, never the offending text. The lexical half (control+ characters, prompt-template fences, length caps) lives in the+ `tinymcp-bus` contract and is applied by its display accessors.+- Events. `tinymcp` reports outcomes in return values. Turning them into+ `DomainEvent`s happens here: `registry/ops.rs` for RPC-driven lifecycle+ events, `registry/supervisor_events.rs` for what the reconnect supervisor+ observed, and `tools_safe_for_agent` for rejections. `audit/` publishesnothing.-- **The proxy decision.** Whether a proxy applies to MCP traffic is decided- by this application's proxy scope setting, per-service list and no-proxy- list, `host::proxy_for_mcp` consults them and hands `tinymcp` the answer.+- The proxy decision. `host::proxy_for_mcp` applies OpenHuman's proxy scope+ setting, per-service list and no-proxy list, and hands `tinymcp` a resolved+ proxy (or none).-## Key files+### Two server sets-| Path | Purpose |+The static set is declared in config TOML (`[[mcp_client.servers]]`) and is+reached through `mcp::config_servers` and the `mcp_list_servers`,+`mcp_list_tools` and `mcp_call_tool` bridge tools plus per-tool+`mcp_<server>_<tool>` tools in `tools/impl/network/`. The dynamic set is the+user's `mcp.json` document, edited through `mcp_clients.config_get` and+`config_set`, browsed from the Smithery and official catalogs, and reached+through the `mcp_registry_*` tools and installed-server actions. Both are+compiled out with the `mcp` feature.++## Layout++| Path | What it does || --- | --- |-| `mod.rs` | Family root, entry points, and the two re-export facades below. |-| `host.rs` / `host_tests.rs` | The per-workspace `tinymcp` service holder, see [its own doc comment](host.rs) for the shape (`HOSTS` map, `McpHost`, `for_config`/`try_service`/`init`, `client_config`, `proxy_for_mcp`). |-| [`registry/README.md`](registry/README.md) | `mcp_clients` RPC (incl. `mcp.json`), agent tools, reconnect-supervisor events. |-| [`audit/README.md`](audit/README.md) | `mcp_audit` RPC over the write-audit log. |-| [`server/README.md`](server/README.md) | The `openhuman mcp` server (this application as an MCP host's target). |--## The two re-export modules--`mcp::http_client` and `mcp::config_servers` are not directories. They no-longer hold transport source, only `pub use` re-exports of `tinymcp`:--- `http_client` (ungated), the Streamable HTTP transport:- `tinymcp::transport::http::{McpHttpClient, McpHttpClientBuilder}`,- `tinymcp::Error` as `McpError`, `redact_endpoint`, `render_tool_result`, and- the `tinymcp_bus` wire types (`McpRemoteTool`, `McpServerToolResult`,- `McpSseEvent`, the OAuth challenge/metadata types). Always compiled because- the ungated `gitbooks` tool (`tools/impl/network/gitbooks.rs`) dials- `McpHttpClient`; `mcp::server`'s test-only HTTP round-trip names it too.-- `config_servers` (`mcp` feature), the statically declared, TOML-configured- server set: `tinymcp::transport::stdio::McpStdioClient`,- `McpRegistrySource`, `McpServerDefinition`, `McpServerRegistry`,- `McpTransportClient`, and `tinymcp_bus::McpAuthConfig` re-exported as- `McpDefinitionAuth` (distinct from this application's own- `config::McpAuthConfig`, which the TOML file declares).--Neither module implements a transport, a handshake, or OAuth discovery any-more. That all lives in `tinymcp` now. Read-[the tinymcp repo](https://github.com/tinyhumansai/tinymcp) for that half.--## Startup wiring--`mcp::start(config)` initializes the registry's bus subscriber and opens the-host service; it never fails (MCP being unavailable must not stop the core-coming up). `mcp::start_boot_jobs(config)` additionally spawns the-installed-server boot pass and the reconnect supervisor. Both are called from-`core/runtime/subscribers.rs` (`start` on the RPC-enable path) and-`core/runtime/services.rs` (`start_boot_jobs` on the boot path); each is-idempotent so the two callers can't double-register or double-spawn.--## Compile-time gate (`mcp` feature)--`pub mod mcp;` is always compiled. The family root is a facade. `host` and-`http_client` are ungated because the startup path and always-on consumers-reach them unconditionally. `registry`, `audit`, and `server` keep-their own gate and their own `stub.rs`, so a build without the feature still-serves `/rpc` without those namespaces; `config_servers` is simply-`#[cfg(feature = "mcp")]` with no stub.--## Dependencies--- `tinymcp` (path dependency on `vendor/tinymcp`, `default-features = false`):- the extracted client library.-- `tinymcp-bus`: the wire contract: payload types and member names, with no- transport and no runtime, also used to generate the desktop settings- schema.-- `crate::config`: `McpClientConfig`/`McpServerConfig`/`McpAuthConfig` and- the runtime proxy config `host::client_config`/`proxy_for_mcp` convert- from.-- `crate::core::bus` / `crate::core::events`: `DomainEvent` publishing for- everything that stayed host-side.--See `Cargo.toml` (`crates/openhuman-core/Cargo.toml`, the `tinymcp` block)-for why this stays a path dependency rather than the pinned release, and-`crates/openhuman-core/src/modules/registry/records_mcp_connectors.rs` for-the release version this application does pin for the loadable-module path.+| `mod.rs` | Family root: `start`, `start_boot_jobs`, the configured tool-cache refresh, the supervisor spawn, and the `http_client` and `config_servers` re-export modules. |+| `host.rs` | The per-workspace `McpHost` holder, config conversion (`client_config`, `static_registry`), `oauth_redirect_uri`, `proxy_for_mcp`. |+| [`registry/`](registry/README.md) | The `mcp_clients` RPC namespace (including `mcp.json`), the `mcp_registry_*` agent tools, installed-server action tools (`action_tool.rs`), supervisor event translation, the injection screen, and the `boot`, `supervisor`, `oauth` and `connections` helpers. |+| [`audit/`](audit/README.md) | The `mcp_audit` RPC namespace over the write-audit log. |+| [`server/`](server/README.md) | The `openhuman-core mcp` stdio and Streamable HTTP server, its tool catalog and dispatch, the write-audit pipeline, prompt resources, and the in-process loopback endpoint used by the sandboxed Claude Code provider. |++`mcp::http_client` and `mcp::config_servers` are modules in `mod.rs`, not+directories, and hold only `pub use` re-exports of `tinymcp`:++- `http_client` (ungated): the Streamable HTTP transport+ (`McpHttpClient`, `McpHttpClientBuilder`), `tinymcp::Error` as `McpError`,+ `redact_endpoint`, `render_tool_result`, and `tinymcp_bus` wire types+ (`McpRemoteTool`, `McpServerToolResult`, `McpSseEvent`, the OAuth challenge+ and metadata types). It is always compiled because the ungated `gitbooks`+ tool (`tools/impl/network/gitbooks.rs`) dials `McpHttpClient`.+- `config_servers` (`mcp` feature): `McpStdioClient`, `McpRegistrySource`,+ `McpServerDefinition`, `McpServerRegistry`, `McpTransportClient`, and+ `tinymcp_bus::McpAuthConfig` re-exported as `McpDefinitionAuth`. That is a+ different type from OpenHuman's own `config::McpAuthConfig`, which is what+ the TOML declares.++## Key types and entry points++- `McpHost` (`host.rs`) and `host::{init, for_config, try_service, service,+ all_hosts}`.+- `host::client_config`, `host::static_registry`, `host::proxy_for_mcp`.+- `mcp::start`, `mcp::start_boot_jobs` (`mod.rs`).+- `registry::connections::{connected_overview,+ connected_overview_for_config}`: the connected-server view the tool+ registry and diagnostics read.+- `registry::types`: `InstalledServer`, `McpTool`, `ConnStatus` and the+ catalog types, re-exported from `tinymcp_bus` (the Smithery names are+ aliases for the contract's `Registry*` types).+- `server::{run_stdio_from_cli, run_http, ensure_local_http, tool_specs}`+ (see [server/README.md](server/README.md)).++## RPC surface++Registered through `core/all.rs`:++- `mcp_clients.*` (`registry/schemas/`): `registry_search`,+ `registry_get`, `registry_settings_get`, `registry_settings_set`,+ `installed_list`, `config_get`, `config_set`, `update_env`, `uninstall`,+ `set_enabled`, `detect_auth`, `oauth_begin`, `connect`, `disconnect`,+ `status`, `list_tools`, `tool_call`. On the wire these are+ `openhuman.mcp_clients_<function>`.+- `mcp_audit.list` (`audit/schemas.rs`): rows from the write-audit log.++The `openhuman-core mcp` server is not an RPC domain. It is a CLI entry wired+through `core/cli.rs` that translates each MCP `tools/call` into an existing+registered core RPC method.++Agent tools registered from this folder: `mcp_registry_search`,+`mcp_registry_get`, `mcp_registry_installed_list`, `mcp_registry_status`,+`mcp_registry_list_tools`, `mcp_registry_connect`,+`mcp_registry_disconnect`, `mcp_registry_tool_call` and+`mcp_registry_uninstall`, plus deferred per-action tools for installed+servers. There is no install tool: servers are added by the user in+`mcp.json`.++## Boundaries++- `tinymcp` (`vendor/tinymcp`, repo `tinyhumansai/tinymcp`) owns the+ transports, handshakes, OAuth discovery, the dynamic registry and its+ SQLite store, the supervisor, the write-audit store, and the generic server+ half (`tinymcp::server`). Fix protocol or client behavior there and move the+ gitlink.+- `tinymcp-bus` is the wire contract: payload types and member names with no+ transport or runtime. It also generates the desktop settings schema. Never+ redeclare its types here.+- `crate::config` owns `McpClientConfig`, `McpServerConfig` and+ `McpAuthConfig`, which `host.rs` converts from.+- The `mcp_*` bridge tools over the static set live in+ `tools/impl/network/`; MCP tools in the cross-surface discovery registry+ are assembled by `tools/registry/`.+- `tinymcp` is a path dependency on `vendor/tinymcp` with+ `default-features = false` (see the `tinymcp` block in+ `crates/openhuman-core/Cargo.toml` for why it is not the pinned release).+ The loadable-module release pin is in+ `modules/registry/records_mcp_connectors.rs`.++## Gotchas++- The `mcp` feature gates `registry`, `audit` and `server`, each of which has+ its own `stub.rs` so a build without the feature still serves `/rpc`+ without those namespaces. `host` and `http_client` are ungated because the+ startup path and always-on consumers reach them without a `cfg`.+ `config_servers` is `#[cfg(feature = "mcp")]` with no stub.+- The server's HTTP transport also needs the `http-server` feature, which+ forwards `tinymcp/server-http`.+- `host::try_service` returns `None` before boot. Code that can run early must+ handle an absent service rather than build one.+- Rejected remote tools are published by rule code only. Do not add the+ description text to logs or events; it is the dangerous payload.++## Tests++Each module has a sibling `*_tests.rs` (`host_tests.rs`, and the suites under+`registry/`, `audit/` and `server/`, including the wire and HTTP golden tests+in `server/`). Run with `cargo test -p openhuman mcp::` or+`pnpm debug rust mcp`, and check the disabled build with+`cargo check --no-default-features`.