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
feat(storage): add storage grant module with tinymcp integration
Steven Enamakel1107eed0ed32
diff --git a/crates/openhuman-core/src/modules/mod.rs b/crates/openhuman-core/src/modules/mod.rsindex a88334c077..71518ccd54 100644--- a/crates/openhuman-core/src/modules/mod.rs+++ b/crates/openhuman-core/src/modules/mod.rs@@ -87,6 +87,8 @@ pub mod search;mod search_path;mod source;#[cfg(feature = "modules")]+mod storage_grant_tinymcp;+#[cfg(feature = "modules")]pub mod storage_grants;#[cfg(feature = "modules")]mod storage_host;diff --git a/crates/openhuman-core/src/modules/storage_grant_tinymcp.rs b/crates/openhuman-core/src/modules/storage_grant_tinymcp.rsnew file mode 100644index 0000000000..41a1e8e798--- /dev/null+++ b/crates/openhuman-core/src/modules/storage_grant_tinymcp.rs@@ -0,0 +1,60 @@+//! What the `tinymcp` module may touch through the storage bus.+//!+//! The collections, indexes, stream and secret names are the module's own+//! declaration (`tinymcp::storage::grant()` and `collection_specs()` in+//! tinyhumansai/tinymcp, docs/specs/storage-ports.md), restated here because a+//! host never links a module's implementation library: a grant is a reviewable+//! build-time decision, like the registry's digests. When the module's+//! declaration changes, this table changes in the same re-pin; the test in+//! `storage_grant_tinymcp_tests.rs` pins the shape.++use tinystoragedrivers::{CollectionSpec, IndexSpec};++use super::storage_grants::StorageGrant;++/// The registry id the grant is declared under.+pub(super) const MODULE_ID: &str = "tinymcp";++/// Installed servers, one document each.+const SERVERS: &str = "mcp_servers";+/// Claims on qualified names, so installing one service twice is one install.+const SERVER_NAMES: &str = "mcp_server_names";+/// Upstream browse responses, with a timestamp.+const REGISTRY_CACHE: &str = "mcp_registry_cache";+/// Each server's last advertised tool list.+const TOOL_CACHE: &str = "mcp_tool_cache";+/// The local copy of an upstream catalog, one document per server.+const REGISTRY_INDEX: &str = "mcp_registry_index";+/// Where each catalog's sync stands.+const REGISTRY_INDEX_STATE: &str = "mcp_registry_index_state";++/// The append-only stream of tool-write audit records.+const AUDIT_STREAM: &str = "mcp_audit";+/// Prefix of the secret holding one server's environment and OAuth values.+const ENV_SECRET_PREFIX: &str = "mcp_client_env/";+/// The secret holding the key the tool-cache fingerprints are keyed with.+const CACHE_KEY_SECRET: &str = "mcp_cache_fingerprint_key";++/// The grant the host serves the `tinymcp` module under.+pub(super) fn grant() -> StorageGrant {+ StorageGrant {+ collections: vec![+ CollectionSpec::new(SERVERS)+ .index(IndexSpec::new("qualified_name", ["qualified_name"]))+ .index(IndexSpec::new("installed_at", ["installed_at"])),+ CollectionSpec::new(SERVER_NAMES),+ CollectionSpec::new(REGISTRY_CACHE).index(IndexSpec::new("cache_key", ["cache_key"])),+ CollectionSpec::new(TOOL_CACHE),+ CollectionSpec::new(REGISTRY_INDEX).index(IndexSpec::new("source", ["source"])),+ CollectionSpec::new(REGISTRY_INDEX_STATE),+ ],+ stream_prefixes: vec![AUDIT_STREAM.into()],+ blob_prefixes: Vec::new(),+ secret_prefixes: vec![ENV_SECRET_PREFIX.into(), CACHE_KEY_SECRET.into()],+ writable: true,+ }+}++#[cfg(test)]+#[path = "storage_grant_tinymcp_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/modules/storage_grant_tinymcp_tests.rs b/crates/openhuman-core/src/modules/storage_grant_tinymcp_tests.rsnew file mode 100644index 0000000000..3beef988b4--- /dev/null+++ b/crates/openhuman-core/src/modules/storage_grant_tinymcp_tests.rs@@ -0,0 +1,77 @@+use super::*;+use crate::modules::storage_grants::{authorize, declared, Denied, Object, Plan};+use serde_json::json;++fn allowed(object: Object, selector: &str, request: serde_json::Value) -> bool {+ matches!(+ authorize(&grant(), object, selector, &request),+ Ok(Plan::Forward { .. })+ )+}++#[test]+fn the_grant_is_declared_for_tinymcp_and_validates() {+ let declared = declared(MODULE_ID).expect("tinymcp declares storage");+ assert_eq!(declared, grant());+ declared.validate().expect("a valid grant");+ assert!(declared.writable);+ assert!(declared.blob_prefixes.is_empty());+}++#[test]+fn the_declared_module_id_is_a_registry_module() {+ assert!(crate::modules::registry::ALL+ .iter()+ .any(|record| record.id == MODULE_ID));+}++#[test]+fn tinymcp_reaches_exactly_its_own_collections() {+ for name in grant().collections.iter().map(|spec| spec.name.clone()) {+ assert!(+ allowed(Object::Documents, "Get", json!({"collection": name, "id": "x"})),+ "{name}"+ );+ }+ for other in ["approvals", "mcp_servers_extra", "_secrets", "mcp_audit"] {+ assert_eq!(+ authorize(+ &grant(),+ Object::Documents,+ "Put",+ &json!({"collection": other})+ ),+ Err(Denied::Target),+ "{other}"+ );+ }+}++#[test]+fn the_catalog_index_is_declared_for_the_modules_own_search_filters() {+ let grant = grant();+ let spec = |name: &str| grant.collections.iter().find(|spec| spec.name == name).unwrap();+ assert_eq!(spec("mcp_servers").indexes.len(), 2);+ assert_eq!(spec("mcp_registry_index").indexes.len(), 1);+ assert!(spec("mcp_server_names").indexes.is_empty());+}++#[test]+fn the_audit_stream_and_env_secrets_are_granted_and_nothing_else() {+ assert!(allowed(Object::Streams, "Append", json!({"stream": "mcp_audit", "payload": {}})));+ assert_eq!(+ authorize(&grant(), Object::Streams, "Append", &json!({"stream": "other"})),+ Err(Denied::Target)+ );+ for name in ["mcp_client_env/srv-1", "mcp_cache_fingerprint_key"] {+ assert!(allowed(Object::Secrets, "Get", json!({"name": name})), "{name}");+ }+ assert_eq!(+ authorize(&grant(), Object::Secrets, "Get", &json!({"name": "wallet/seed"})),+ Err(Denied::Target)+ );+ assert_eq!(+ authorize(&grant(), Object::Blobs, "Get", &json!({"key": "any"})),+ Err(Denied::Object)+ );+}diff --git a/crates/openhuman-core/src/modules/storage_grants.rs b/crates/openhuman-core/src/modules/storage_grants.rsindex ba11240280..0528b49f1d 100644--- a/crates/openhuman-core/src/modules/storage_grants.rs+++ b/crates/openhuman-core/src/modules/storage_grants.rs@@ -180,13 +180,18 @@ type Declaration = (&'static str, fn() -> StorageGrant);/// The modules whose build declares storage, and what each may use.///-/// Empty today: no loadable module consumes the storage bus yet. A module-/// that does adds its row here (a declaration is a reviewable build-time+/// A module adds its row here (a declaration is a reviewable build-time/// decision, like the registry's digests) and then calls-/// `ai.tinyhumans.tinystorage.Storage`; until then it has no storage at all.+/// `ai.tinyhumans.tinystorage.Storage`; a module with no row has no storage at+/// all. `tinymcp` declares its grant ahead of the release that consumes it: the+/// pinned module does not call the storage bus yet, so the row serves nothing+/// until the registry moves to a release that does.#[must_use]pub fn declared(module_id: &str) -> Option<StorageGrant> {- let table: &[Declaration] = &[];+ let table: &[Declaration] = &[(+ super::storage_grant_tinymcp::MODULE_ID,+ super::storage_grant_tinymcp::grant,+ )];table.iter().find(|(id, _)| *id == module_id)diff --git a/crates/openhuman-core/src/modules/storage_grants_tests.rs b/crates/openhuman-core/src/modules/storage_grants_tests.rsindex a9fc580ac8..1edd758fb8 100644--- a/crates/openhuman-core/src/modules/storage_grants_tests.rs+++ b/crates/openhuman-core/src/modules/storage_grants_tests.rs@@ -329,9 +329,9 @@ fn validate_refuses_grants_that_reach_past_a_modules_own_data() {}#[test]-fn no_module_declares_storage_yet() {+fn only_modules_with_a_declared_grant_have_storage() {for record in crate::modules::registry::ALL {- assert!(declared(record.id).is_none(), "{}", record.id);+ assert_eq!(declared(record.id).is_some(), record.id == "tinymcp", "{}", record.id);}}