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): document TinyMCP module ownership and session lifecycle
Steven Enamakel0cf80b5a96ac
diff --git a/crates/openhuman-core/src/mcp/README.md b/crates/openhuman-core/src/mcp/README.mdindex 9a329a6409..977e8ff02e 100644--- a/crates/openhuman-core/src/mcp/README.md+++ b/crates/openhuman-core/src/mcp/README.md@@ -30,11 +30,18 @@ OpenHuman configuration to bus DTOs and applies product proxy and credentialtransport policy. Registry handlers and agent tools call module operations,then translate outcomes into OpenHuman RPC results and domain events.+The configured object's bus path remains private to `module_client.rs`. Open+and close operations keep transition receipts so retries can finish after a+caller is cancelled or loses its reply. Calls that carry client credentials+use TinyBus confidential delivery.+The local MCP server keeps its OpenHuman tool catalog, authorization policy,write audit decisions, and RPC dispatch. TinyMCP owns the protocol session,stdio/HTTP framing, HTTP session admission, and transport lifecycle. The hostpasses requests and callbacks through bus operations rather than parsing MCP-protocol messages itself.+protocol messages itself. A successful HTTP DELETE closes the module session+before the host cancels and joins its in-flight callback and removes the local+session; a rejected DELETE leaves the host session intact.## Host responsibilitiesdiff --git a/crates/openhuman-core/src/mcp/registry/README.md b/crates/openhuman-core/src/mcp/registry/README.mdindex e907fbafd3..f715fd5ac7 100644--- a/crates/openhuman-core/src/mcp/registry/README.md+++ b/crates/openhuman-core/src/mcp/registry/README.md@@ -35,6 +35,11 @@ calls must not be used for secrets. The module manages protocol state andreports typed outcomes. The host translates those outcomes into OpenHuman'sRPC response shape and domain events.+`McpConfiguredClient` keeps each workspace's module object path private and+serializes its open, call, and close transitions. It retains transition+receipts across caller cancellation or lost replies so cleanup can be retried+without exposing TinyMCP's internal service implementation to host code.+`tools_safe_for_agent` is intentionally host-owned because it is the product'sprompt-injection policy. Remote descriptions and schemas are scrubbed by themodule before the host sees them; the host then applies this admission filterdiff --git a/crates/openhuman-core/src/mcp/server/README.md b/crates/openhuman-core/src/mcp/server/README.mdindex 6200fd38f7..9ac63a14b5 100644--- a/crates/openhuman-core/src/mcp/server/README.md+++ b/crates/openhuman-core/src/mcp/server/README.md@@ -15,6 +15,19 @@ TinyMCP owns MCP framing, protocol state, callbacks, and HTTP admission through- Provide two transports: newline-delimited JSON-RPC over stdio, and Axum-based Streamable HTTP + SSE with session-id and protocol-version handshakes and optional bearer auth.- Capture client provenance from `initialize` `clientInfo.name` into a per-session `source_type` (e.g. `mcp:claude-desktop`) used for audit attribution.+## Session lifetime and cleanup++Each host session serializes request handling and owns any pending host callback.+If a request is cancelled, the adapter cancels the matching module operation+and joins its callback before returning. Retries after a lost module reply+reuse the operation identity and completed callback reply.++For Streamable HTTP, the host asks TinyMCP to validate and apply DELETE first.+Only an accepted DELETE terminally closes the local session: the host rejects+new work, aborts and joins a running callback, then removes the session from+its table. A rejected DELETE leaves the session available for later requests.+Process shutdown closes the module sessions and drains their callbacks.+## Key files| File | Role |diff --git a/gitbooks/developing/architecture.md b/gitbooks/developing/architecture.mdindex 022072fdaf..74c665a1cd 100644--- a/gitbooks/developing/architecture.md+++ b/gitbooks/developing/architecture.md@@ -216,9 +216,9 @@ Recurring work belongs to the `cron` domain (with `scheduler_gate`), not to skil## AI and tool protocol (MCP)-OpenHuman implements the Model Context Protocol on both sides of the connection. As a client, the core browses Smithery and the official MCP registry, connects servers a user declares in `mcp.json`, and surfaces their tools to agents through the same tool registry native tools use; see [MCP registry](architecture/mcp-registry.md). As a server, `openhuman-core mcp` exposes OpenHuman's own tools over stdio or HTTP so external MCP hosts such as Claude Desktop, Cursor, and Zed can call them; see [MCP server](mcp-server.md).+OpenHuman implements the Model Context Protocol on both sides of the connection. As a client, the core browses registries, connects servers declared in `mcp.json`, and offers their tools through the native tool registry; see [MCP registry](architecture/mcp-registry.md). As a server, `openhuman-core mcp` exposes OpenHuman's curated tools over stdio or Streamable HTTP; see [MCP server](mcp-server.md).-Every remote tool definition, whether coming in through a connected server or served out to a host, passes a prompt-injection scan before it reaches a model. Tool execution itself runs through the same Tool Registry as native tools: native Rust handlers or shell commands using the host toolchain, gated by `SecurityPolicy` and the active sandbox backend.+MCP protocol, transport, registry, and server-session behavior run inside the TinyMCP TinyBus module. OpenHuman links the `tinymcp-bus` contract and keeps product configuration, credentials, proxy policy, approvals, prompt-injection admission, and typed host callbacks. Its configured module client keeps object paths private and retains lifecycle receipts across cancellation or lost replies. For HTTP DELETE, the host drains and joins an in-flight callback only after the module accepts the close; a rejected DELETE leaves the session available. This keeps product policy in the host while protocol state and transport behavior remain module-owned.## Memorydiff --git a/gitbooks/developing/architecture/mcp-registry.md b/gitbooks/developing/architecture/mcp-registry.mdindex 5a36f40137..1865271341 100644--- a/gitbooks/developing/architecture/mcp-registry.md+++ b/gitbooks/developing/architecture/mcp-registry.md@@ -1,111 +1,95 @@---description: >-- How OpenHuman browses MCP registries, connects the servers you declare in- mcp.json, and gives their tools to agents.+ How OpenHuman connects MCP servers, applies product policy, and exposes their+ tools to agents through TinyBus modules.icon: plug---# MCP registry-`crates/openhuman-core/src/mcp/registry/` is the host half of OpenHuman's Model Context Protocol (MCP) client support. It browses the supported upstream registries (Smithery and the official modelcontextprotocol registry) and reconciles the install store against your `mcp.json` document. For servers launched as local subprocesses or HTTP-remote endpoints, it also supervises the connection. The tools of installed servers reach agents through the unified tool registry (`crate::tools::registry`).+`crates/openhuman-core/src/mcp/registry/` is OpenHuman's host adapter for the+Model Context Protocol (MCP) client. It preserves the `mcp_clients` RPC and+agent-tool surfaces while the TinyMCP module owns registry and connection+behavior. The module is loaded through TinyBus; OpenHuman uses the published+`tinymcp-bus` vocabulary and does not link the TinyMCP implementation into its+normal dependency graph.-There is no install-from-catalog RPC and no setup agent. In the Registry tab, a hosted server that needs no setup (one http(s) endpoint, no required or secret inputs) is added in one click: the app declares it in mcp.json through `config_get` / `config_set`, then connects it or opens the sign-in dialog. For any other server you open its own page, read the install instructions there, and declare the server in the mcp.json tab: `{ "mcpServers": { name: { command, args, env } | { url, headers } } }`. The document's contract and its reconciliation live in `tinymcp::registry::config_doc`. `config_ops.rs` here is the RPC envelope over them (`mcp_clients_config_get` and `mcp_clients_config_set`).+The Registry tab browses the supported catalogs and adds servers through the+user's `mcp.json` document. There is no install-from-catalog RPC or agent+install tool. A simple hosted server can be declared in one click; other+servers are declared from their own setup instructions. The existing+`mcp_clients.*` RPC names and persisted `mcp_clients` name remain stable.-The client half lives in the vendored `tinymcp` crate (`vendor/tinymcp`): both transports, the Smithery and official catalogs, the SQLite store, the live connection map, the subprocess supervisor, browser sign-in and the write-audit log. This directory holds only what belongs to the application:--- `host.rs` (one level up, `crates/openhuman-core/src/mcp/host.rs`) holds the one `tinymcp` service this process runs per workspace, and converts config to `tinymcp` types.-- `registry/` holds the `mcp_clients` RPC surface, the agent-facing tools and the prompt-injection scan applied to remote tool definitions.-- `audit/` (next to `registry/`) is the RPC surface over `tinymcp`'s write-audit log.-- `server/` (next to `registry/`) is the `openhuman-core mcp` stdio and HTTP server that exposes this application's own tools to external MCP hosts. See [MCP server](../mcp-server.md). That is the server side, a separate thing from this client code.--The Rust module path is `crate::mcp::registry`, but the RPC namespace and the on-disk SQLite filename are `mcp_clients`. They stay that way so existing frontend code and stored user state keep working. Search for both names when you trace call sites.--All payload types (`InstalledServer`, `McpTool`, `ConnStatus` and the Smithery and official-registry DTOs) come from `tinymcp_bus` and are re-exported under `registry::types`, not redefined here. Types for the static, config-declared server set (`[[mcp_client.servers]]` in `config.toml`) and the shared HTTP/stdio transport primitives are re-exported from `crate::mcp::config_servers` and `crate::mcp::http_client` (thin `pub use tinymcp::...` modules in `mcp/mod.rs`, not directories).+## Ownership and request flow```text- ┌────────────────────────────────────────────────┐- Registries ───► tinymcp (catalogs, store, supervisor) │- └────────────────────┬───────────────────────────┘- │ browse / declare- ▼- ┌──────────────────────┐- Frontend (Skills UI) ─►│ ops.rs / schemas.rs │ RPC controllers (mcp_clients_*)- └──────────┬───────────┘- │ delegates to- ▼- ┌──────────────────────┐- │ host::for_config │ the tinymcp service this- │ / host::try_service │ workspace's host holds- └──────────┬───────────┘- │ tools_safe_for_agent (prompt-injection scan)- ▼- tool_registry (agents)-- supervisor_events.rs ── reconnect-supervisor ticks → DomainEvent+Frontend / agent tools+ │ mcp_clients RPCs and MCP tool calls+ ▼+OpenHuman host adapters+ product config, credentials, proxy policy, approvals,+ prompt-injection admission, RPC outcomes and domain events+ │ typed TinyBus calls+ ▼+TinyMCP module+ catalogs, mcp.json reconciliation, stores, connections,+ OAuth protocol, tool preparation, transports and supervisor```-## Server transport model--An `InstalledServer` (from `tinymcp_bus`, re-exported as `registry::types::InstalledServer`) carries a `Transport` discriminator with stdio and HTTP-remote variants: a local subprocess (`npx`, `uvx`, or a direct binary) speaking stdio JSON-RPC, or a hosted server (the majority of what Smithery lists) dialled over streamable HTTP. A declaration in `mcp.json` becomes such a row directly (`tinymcp::registry::config_doc`): `command`/`args` → stdio, `url` → HTTP-remote, `env`/`headers` → the credential table. `tinymcp` dials whatever the row says; this domain only decides what the row says.--## Boot-time spawn and the reconnect supervisor--Installed servers are connected as the core comes up, and `mcp::registry::supervisor` (see `crates/openhuman-core/src/mcp/registry/mod.rs`) runs `tinymcp::Supervisor::tick` on an interval against every open workspace host, turning each tick's report into `supervisor_events::publish` calls. Errors never block boot. A broken MCP install should not stop the desktop app from starting. Non-nominal ticks (stays-down, restored, parked) become `DomainEvent`s that reach the Event Log and the desktop notification bridge.--## Layout--| Path | Role |-| ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |-| `mod.rs` | Module docs, `types`/`connections` re-export shims over `tinymcp_bus`/`super::host`, the reconnect-supervisor loop, the OAuth-callback completion helper, and `tools_safe_for_agent` (the prompt-injection scan applied to every remote tool definition). |-| `host.rs` (parent `mcp/`) | One `tinymcp` service per workspace, opened on first use; proxy resolution for MCP traffic (`proxy_for_mcp`). |-| `helpers.rs` | Shared RPC-handler plumbing: `Outcome` encoding, identifier guards, workspace-service resolution, credential-name injection. |-| `ops.rs` | `mcp_clients_*` RPC handler implementations (uninstall, list, browse, connect/disconnect, tool call, `update_env`, registry settings). One-to-one with `schemas.rs` handlers; publishes `DomainEvent`s `tinymcp` does not. |-| `config_ops.rs` | `mcp_clients_config_get` / `config_set`: the `Outcome` envelope, domain events and background connects over `tinymcp`'s `McpRegistry::render_config_doc` / `apply_config_doc`. The `mcp.json` shape, its refusals and the reconciliation (add, rewrite in place under the same `server_id`, or uninstall, merging write-only credentials) live in `tinymcp::registry::config_doc`. |-| `action_tool.rs` | One deferred agent tool per action on a connected server, built from `tinymcp_bus::agent_tools::action_tool_specs` with `tools_safe_for_agent` as the admission filter. Execution goes through `InstalledServerInvoker::invoke`, which re-checks the live safe-tool list and then calls `service.dynamic().invoke(...)` on the `tinymcp` service, rather than back through `ops.rs`. |-| `schemas/` (`mod.rs`, `registry.rs`, `handlers.rs`, `params.rs`) | Controller schemas + handler dispatch. Re-exported from `mod.rs` as `all_mcp_registry_controller_schemas` / `all_mcp_registry_registered_controllers`. |-| `bus.rs` | `DomainEvent` subscriber (`McpClientEventSubscriber`) that logs `McpServer*` / `McpClientToolExecuted` lifecycle events. |-| `supervisor_events.rs` | Turns a `tinymcp::Supervisor` tick report into this domain's `DomainEvent`s, stamped with the workspace whose host was ticked. |-| `tools.rs` | Agent-facing `mcp_registry_*` tools (search catalog, inspect/list/connect/disconnect/call), thin shims over `ops.rs`. The one mutator (`mcp_registry_uninstall`) ships default-OFF behind the `mcp_manage` toggle; there is no install tool. Distinct from the generic `mcp_list_servers`/`mcp_call_tool` bridge tools. |-| `stub.rs` | The disabled facade compiled when the `mcp` feature is off. |--## Public surface--The exports from `mod.rs` are narrow on purpose:--```rust-pub use schemas::{- all_controller_schemas as all_mcp_registry_controller_schemas,- all_registered_controllers as all_mcp_registry_registered_controllers,- schemas as mcp_registry_schemas,-};--pub use types::{ConnStatus, InstalledServer, McpTool};-```--`types` and `connections` are thin `pub mod`s. They re-export the `tinymcp_bus` wire vocabulary and the `super::host`-backed lookups. This domain does not define its own copies. Everything else (`bus`, `ops`, `action_tool`, `supervisor_events`, `tools`) is `pub mod` for in-crate callers but not re-exported from `mod.rs`.--## Calls into--- `crate::mcp::host`: resolves the `tinymcp` service for a workspace (`host::for_config`, `host::try_service`, `host::all_hosts`).-- `tinymcp` / `tinymcp_bus`: the catalogs, store, connection map, supervisor, OAuth flow, and wire types.-- `crate::security::prompt_injection::scan_tool_definition`: the scan `tools_safe_for_agent` applies before a remote tool reaches the model.-- `crate::tools::registry`: installed servers' tools land here so agents see them alongside native tools.-- `crate::core::bus::BUS`: publishes `DomainEvent`s (`McpToolRejected`, lifecycle events, supervisor observations).--## Called by--- Core startup, via `mcp::host::init` and the reconnect-supervisor loop.-- The frontend Connections UI. The MCP Servers page (`McpServersTab`) has three tabs over the `openhuman.mcp_clients_*` RPC namespace: Servers (rows, status and the credential form: connect, disconnect, `update_env`, sign-in), mcp.json (`config_get` and `config_set`, the only way to add or remove a server) and Registry (`registry_search` and `registry_get`; a hosted server that needs no setup is declared into mcp.json in one click, any other row opens the server's own page in the browser). `registry_settings_get` / `registry_settings_set` hold the Smithery / official-registry credentials (secret values are write-only). Agents use connected servers directly. The orchestrator finds a connected server's tool through `tool_search`, or loads the `mcp` skill (`use_skill`, guide in `crates/openhuman-core/src/tools/toolpacks/guides/mcp.md`) for the `mcp_registry_*` status, list-tools and tool-call fallback. Agents do not install servers.--## Tests--Focused `*_tests.rs` siblings cover each file: `bus_tests.rs`, `ops_tests.rs`, `schemas_tests.rs`, `action_tool_tests.rs`, `supervisor_events_tests.rs`, `tools_tests.rs`.--## Related--- [`mcp/registry/mod.rs`](https://github.com/tinyhumansai/openhuman/blob/main/crates/openhuman-core/src/mcp/registry/mod.rs) and [`mcp/mod.rs`](https://github.com/tinyhumansai/openhuman/blob/main/crates/openhuman-core/src/mcp/mod.rs): the rustdoc this page mirrors.-- `crate::mcp::config_servers` / `crate::mcp::http_client` (`mcp/mod.rs`): re-export modules for the static config-declared server set and the shared transport primitives, both implemented in `tinymcp`.-- `crates/openhuman-core/src/mcp/audit/`: the RPC surface over `tinymcp`'s write-audit log.-- [MCP server](../mcp-server.md): the `openhuman-core mcp` stdio and HTTP server side.-- [Agent harness](agent-harness.md): how the agent ends up calling MCP tools through `tool_registry`.-- [Architecture](../architecture.md): where this fits in the wider system.+`mcp::host` converts OpenHuman configuration to `McpClientConfig` and applies+the product proxy and endpoint credential policy. `mcp::module_client` owns+the configured module object for each workspace, serializes access to its+private object path, and retains open/close transition receipts so a retry can+finish lifecycle work after cancellation or a lost reply. Configuration sent+to the module uses confidential TinyBus delivery.++The registry controllers keep the public `mcp_clients_*` RPC contract,+translate module results into OpenHuman outcomes, and publish OpenHuman domain+events. The host also owns product permission and exposure mapping and the+prompt-injection scan applied before remote tools are offered to an agent. The+module prepares stable tool names, schemas, and metadata; execution and+protocol handling stay inside the module.++## Server transports++An installed server's typed `Transport` is either a local subprocess speaking+stdio JSON-RPC or an HTTP-remote endpoint. TinyMCP owns transport startup,+protocol, connection state, and cleanup. OpenHuman decides which server+configuration and credentials are approved and passes them over the bus.++The same ownership split applies when OpenHuman acts as an MCP server. The+TinyMCP module owns protocol sessions, stdio framing, Streamable HTTP+admission, and response metadata. OpenHuman keeps the curated tool catalog,+security policy, RPC dispatch, and typed host callbacks. For HTTP DELETE, the+host retires its local session and aborts and joins any running callback only+after the module accepts the request; a rejected DELETE leaves the session+usable. Session close and process shutdown drain callback work before+releasing its local handle.++## Host layout++| Path | Responsibility |+| --- | --- |+| `crates/openhuman-core/src/mcp/host.rs` | Product configuration conversion, proxy selection, and OAuth redirect URL. |+| `crates/openhuman-core/src/mcp/module_client.rs` | Workspace-scoped configured object lifecycle and typed/confidential bus calls. |+| `registry/ops.rs`, `config_ops.rs`, `schemas/` | Stable RPC handlers, `mcp.json` adapter, and controller schemas. |+| `registry/action_tool.rs`, `registry/tools.rs` | Deferred host tool adapters, product admission, and execution event mapping. |+| `registry/supervisor_events.rs`, `registry/bus.rs` | Convert module reports and lifecycle events to OpenHuman domain events. |+| `audit/` | OpenHuman RPC surface over module-owned MCP write-audit records. |+| `server/` | OpenHuman's tool catalog, security policy, and typed callbacks for the local MCP server. |++## Security and compatibility++- Keep credentials in OpenHuman's configuration and credential stores. Use+ confidential bus methods whenever calls carry credentials or other sensitive+ tool data; ordinary module calls must not carry secrets.+- Preserve the existing `mcp_clients.*` RPC names and user-visible server+ names. Bus DTOs and member names come from `tinymcp-bus`; do not define local+ wire copies.+- Keep product policy in OpenHuman and generic MCP protocol, transport,+ catalog, persistence, and tool-preparation behavior in `vendor/tinymcp`.+- Do not put user data, credentials, provider responses, or raw tool arguments+ in analytics or logs. Use the shared endpoint redactor for endpoint logging.++For implementation details, see the [MCP server](../mcp-server.md) and+[`crates/openhuman-core/src/mcp/README.md`](../../../crates/openhuman-core/src/mcp/README.md).