Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(mcp): serve TinyFlows agent prompts as MCP resources

Steven Enamakel50d029b357c1
diff --git a/crates/openhuman-core/src/mcp/server/README.md b/crates/openhuman-core/src/mcp/server/README.md
index f4e6c1aa36..b6b9351c98 100644
--- a/crates/openhuman-core/src/mcp/server/README.md
+++ b/crates/openhuman-core/src/mcp/server/README.md
@@ -11,7 +11,7 @@ TinyMCP owns MCP framing, protocol state, callbacks, and HTTP admission through
- Map validated module callbacks to registered core RPC params and dispatch via `all::try_invoke_registered_rpc`.
- Enforce `SecurityPolicy` per call: read tools require `ToolOperation::Read`; `agent.run_subagent` and the two write tools (`memory.learn`, `memory.forget`) require `ToolOperation::Act`.
- Run write tools (`memory.learn`, `memory.forget`) through a dedicated write-dispatch + audit pipeline that records every attempt (success and rejection) to the MCP write-audit log.
-- Serve bundled prompt assets (`IDENTITY.md`, `SOUL.md`, `USER.md`, and each built-in subagent's `prompt.md`) as static MCP resources under the `openhuman://prompts/...` URI scheme.
+- Serve bundled prompt assets and TinyFlows' two bus-owned agent archetypes as MCP resources under the `openhuman://prompts/...` URI scheme. Static markdown is embedded; flow prompts are fetched with the request's scoped config.
- 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.
@@ -37,7 +37,7 @@ Process shutdown closes the module sessions and drains their callbacks.
| `crates/openhuman-core/src/mcp/server/handler.rs` | Applies host policy and dispatches typed `ServerHostCall`s to OpenHuman tool/resource behavior. |
| [`crates/openhuman-core/src/mcp/server/tools/`](./tools/) | Tool catalog and dispatch: `mod.rs` (facade; re-exports `tinymcp_bus::ToolCallError`), `types.rs` (`McpToolSpec` and the limit/tag constants, ungated so `McpToolSpec` is one real type in both builds), `specs.rs` (catalog builders and the `ServerToolSpec` conversion), `params.rs` (OpenHuman's per-tool argument policy → RPC params), `dispatch.rs` (`call_tool`/`list_tool_specs`, policy enforcement, subagent handlers). |
| [`crates/openhuman-core/src/mcp/server/write_dispatch.rs`](./write_dispatch.rs) | Write/audit pipeline for `memory.learn`/`memory.forget`: config load, act-policy enforcement, RPC dispatch to `openhuman.memory_learn` / `openhuman.memory_forget`, audit-record write (success/rejection) via `crate::mcp::audit::record_write`, PII-redacting arg summaries. |
-| [`crates/openhuman-core/src/mcp/server/resources.rs`](./resources.rs) | Static `RESOURCE_CATALOG` of compile-time-embedded prompt markdown, declared and read through bus vocabulary. Test cross-checks catalog vs `agent::agents::BUILTINS`. |
+| [`crates/openhuman-core/src/mcp/server/resources.rs`](./resources.rs) | Static prompt markdown catalog plus request-scoped TinyFlows `GetPrompt` reads for the flow builtins. Test cross-checks exposed agent resources against `agent::registry::agents::BUILTINS`. |
| [`crates/openhuman-core/src/mcp/server/http.rs`](./http.rs) | Thin Axum transport adapter; passes raw request bodies and headers to module operations and uses module-selected response metadata. Gated on `all(feature = "mcp", feature = "http-server")`. |
| [`crates/openhuman-core/src/mcp/server/local.rs`](./local.rs) | Lazily-started, process-wide in-process loopback HTTP MCP server (`ensure_local_http`, `LocalMcpEndpoint`). Lets the sandboxed `claude` subprocess (Claude Code provider) reach OpenHuman's memory/tools over loopback without the MCP server inheriting Claude Code's OS jail; a per-process random bearer token stops any other local process from talking to it. |
| [`crates/openhuman-core/src/mcp/server/subagent_depth.rs`](./subagent_depth.rs) | Per-delegation-chain depth tracking for `agent.run_subagent`, propagated across the loopback MCP HTTP hop via the `X-OpenHuman-Subagent-Depth` header (read by `handler.rs` from `tinymcp`'s `RequestContext`) so nested Claude Code subagent calls are bounded without penalizing unrelated parallel callers. |
@@ -119,7 +119,7 @@ No `store.rs`. The only durable side effect is the **MCP write-audit log**, writ
- **Write audit is fire-and-forget but mandatory:** rejections are audited even before config is loaded (`audit_write_rejection_without_config`), and `dispatch_write_tool` returns `Ok(tool_error(...))` (not `Err`) on RPC-handler failure so the client gets an MCP `isError` result while the failure is still recorded.
- **Protocol negotiation:** owned by TinyMCP and covered by its module protocol fixtures. The host routes HTTP methods and passes raw headers/frames without parsing MCP methods.
- **HTTP security:** bearer auth is optional (`--auth-token`); the default bind is `127.0.0.1:9300`.
-- **Resource catalog parity is CI-enforced:** `resources.rs` content is `include_str!`-embedded at compile time and the `catalog_mirrors_builtins` test fails if a built-in subagent lacks a matching `openhuman://prompts/agents/<id>` entry.
+- **Resource catalog parity is CI-enforced:** static prompt files are `include_str!`-embedded and the `catalog_mirrors_builtins` test fails if a built-in subagent lacks a matching `openhuman://prompts/agents/<id>` entry. Flow resource reads fetch their current text through TinyFlows Copilot.
- **`agent.run_subagent` limits:** runs a fresh single-turn agent session tagged with an `mcp:<agent_id>:<uuid>` event context.
- **stdio logging defaults to `warn`** on stderr (so failures surface in client UIs); `--verbose` → `debug`; a user-set `RUST_LOG` always wins. Stdout is reserved for protocol messages only.
diff --git a/crates/openhuman-core/src/mcp/server/handler.rs b/crates/openhuman-core/src/mcp/server/handler.rs
index 0b9539c554..437a0afbf4 100644
--- a/crates/openhuman-core/src/mcp/server/handler.rs
+++ b/crates/openhuman-core/src/mcp/server/handler.rs
@@ -49,7 +49,8 @@ pub(super) async fn dispatch(ctx: DispatchCtx, call: ServerHostCall) -> ServerHo
.await;
result.map_or_else(reply_error, |value| ServerHostReply::Success { value })
}
- ServerHostCall::ReadResource { uri, .. } => resources::read_resource(&uri)
+ ServerHostCall::ReadResource { uri, .. } => resources::read_resource(&ctx, &uri)
+ .await
.map_or_else(reply_error, |value| ServerHostReply::Success { value }),
ServerHostCall::ListPrompts { .. } => ServerHostReply::Success {
value: Value::Array(Vec::new()),
diff --git a/crates/openhuman-core/src/mcp/server/resources.rs b/crates/openhuman-core/src/mcp/server/resources.rs
index 7cf87117ea..c81e3ac02c 100644
--- a/crates/openhuman-core/src/mcp/server/resources.rs
+++ b/crates/openhuman-core/src/mcp/server/resources.rs
@@ -169,7 +169,23 @@ pub fn resource_specs() -> Vec<ResourceSpec> {
/// The `resources/read` result for `uri`, or
/// [`ToolCallError::ResourceNotFound`] (`-32002`) when the catalog has no such
/// entry. TinyMCP has already rejected a missing or blank `uri`.
-pub fn read_resource(uri: &str) -> Result<Value, ToolCallError> {
+pub async fn read_resource(
+ ctx: &crate::core::runtime::DispatchCtx,
+ uri: &str,
+) -> Result<Value, ToolCallError> {
+ #[cfg(feature = "flows")]
+ if let Some(agent_id) = flow_prompt_agent_id(uri) {
+ let config = ctx
+ .load_config()
+ .await
+ .map_err(|_| ToolCallError::Internal("TinyFlows prompt config is unavailable".into()))?;
+ return read_flow_prompt(&config, uri, agent_id).await;
+ }
+
+ read_static_resource(uri)
+}
+
+fn read_static_resource(uri: &str) -> Result<Value, ToolCallError> {
let resource = RESOURCE_CATALOG
.iter()
.find(|r| r.uri == uri)
@@ -183,13 +199,38 @@ pub fn read_resource(uri: &str) -> Result<Value, ToolCallError> {
resource.content.len()
);
- Ok(json!({
+ Ok(resource_contents(uri, resource.content))
+}
+
+#[cfg(feature = "flows")]
+fn flow_prompt_agent_id(uri: &str) -> Option<&'static str> {
+ match uri {
+ "openhuman://prompts/agents/flow_discovery" => Some("flow_discovery"),
+ "openhuman://prompts/agents/workflow_builder" => Some("workflow_builder"),
+ _ => None,
+ }
+}
+
+#[cfg(feature = "flows")]
+async fn read_flow_prompt(
+ config: &crate::config::Config,
+ uri: &str,
+ agent_id: &str,
+) -> Result<Value, ToolCallError> {
+ let text = crate::agent::prompts::flow_archetype::fetch_prompt(config, agent_id)
+ .await
+ .map_err(|_| ToolCallError::Internal("TinyFlows prompt is unavailable".into()))?;
+ Ok(resource_contents(uri, &text))
+}
+
+fn resource_contents(uri: &str, text: &str) -> Value {
+ json!({
"contents": [{
- "uri": resource.uri,
+ "uri": uri,
"mimeType": MIME_TYPE,
- "text": resource.content
+ "text": text
}]
- }))
+ })
}
#[cfg(test)]
diff --git a/crates/openhuman-core/src/mcp/server/resources_tests.rs b/crates/openhuman-core/src/mcp/server/resources_tests.rs
index d0395617c9..99a4950aea 100644
--- a/crates/openhuman-core/src/mcp/server/resources_tests.rs
+++ b/crates/openhuman-core/src/mcp/server/resources_tests.rs
@@ -4,10 +4,11 @@ use super::*;
fn catalog_mirrors_builtins() {
use crate::agent::registry::agents::BUILTINS;
+ let resources = resource_specs();
for b in BUILTINS {
let expected_uri = format!("openhuman://prompts/agents/{}", b.id);
assert!(
- RESOURCE_CATALOG.iter().any(|r| r.uri == expected_uri),
+ resources.iter().any(|r| r.uri == expected_uri),
"RESOURCE_CATALOG is missing an entry for built-in agent `{}` \
(expected URI `{}`). Add it to RESOURCE_CATALOG in resources.rs.",
b.id,
@@ -15,14 +16,14 @@ fn catalog_mirrors_builtins() {
);
}
- let catalog_agent_count = RESOURCE_CATALOG
+ let catalog_agent_count = resources
.iter()
.filter(|r| r.uri.starts_with("openhuman://prompts/agents/"))
.count();
assert_eq!(
catalog_agent_count,
BUILTINS.len(),
- "RESOURCE_CATALOG has {catalog_agent_count} agent entries but BUILTINS has {}. \
+ "resource_specs has {catalog_agent_count} agent entries but BUILTINS has {}. \
Remove stale entries from RESOURCE_CATALOG.",
BUILTINS.len()
);
@@ -31,10 +32,11 @@ fn catalog_mirrors_builtins() {
#[test]
fn list_resources_returns_all_catalog_entries() {
let resources = resource_specs();
+ let expected_len = RESOURCE_CATALOG.len() + if cfg!(feature = "flows") { 2 } else { 0 };
assert_eq!(
resources.len(),
- RESOURCE_CATALOG.len(),
- "resources/list count mismatch"
+ expected_len,
+ "resources/list includes static assets and the bus-backed flow prompts"
);
for entry in &resources {
assert!(!entry.uri.is_empty(), "uri must be set");
@@ -43,6 +45,22 @@ fn list_resources_returns_all_catalog_entries() {
}
}
+#[cfg(feature = "flows")]
+#[tokio::test]
+async fn flow_prompt_resource_fails_closed_when_tinyflows_is_disabled() {
+ let mut config = crate::config::Config::default();
+ config.components.tinyflows = false;
+ let error = read_flow_prompt(
+ &config,
+ "openhuman://prompts/agents/flow_discovery",
+ "flow_discovery",
+ )
+ .await
+ .expect_err("disabled TinyFlows must not expose a copied prompt");
+ assert_eq!(error.code(), -32603);
+ assert!(error.message().contains("unavailable"));
+}
+
#[test]
fn list_resources_includes_core_and_agent_uris() {
let resources = resource_specs();
@@ -60,7 +78,7 @@ fn list_resources_includes_core_and_agent_uris() {
#[test]
fn read_resource_returns_content_for_known_uri() {
- let result = read_resource("openhuman://prompts/identity").expect("should succeed");
+ let result = read_static_resource("openhuman://prompts/identity").expect("should succeed");
let contents = result["contents"].as_array().expect("contents array");
assert_eq!(contents.len(), 1);
assert_eq!(contents[0]["uri"], "openhuman://prompts/identity");
@@ -70,18 +88,29 @@ fn read_resource_returns_content_for_known_uri() {
#[test]
fn read_resource_returns_minus_32002_for_unknown_uri() {
- let err = read_resource("openhuman://prompts/agents/nonexistent")
+ let err = read_static_resource("openhuman://prompts/agents/nonexistent")
.expect_err("should fail for unknown URI");
assert_eq!(err.code(), -32002);
assert!(err.message().contains("nonexistent"));
}
-#[test]
-fn read_resource_returns_content_for_each_subagent() {
+#[tokio::test]
+async fn read_resource_returns_content_for_each_subagent() {
use crate::agent::registry::agents::BUILTINS;
+ let config = crate::config::Config::default();
for b in BUILTINS {
let uri = format!("openhuman://prompts/agents/{}", b.id);
- let result = read_resource(&uri)
+ #[cfg(feature = "flows")]
+ let result = if let Some(agent_id) = flow_prompt_agent_id(&uri) {
+ read_flow_prompt(&config, &uri, agent_id)
+ .await
+ .unwrap_or_else(|_| panic!("read_resource failed for agent `{}`", b.id))
+ } else {
+ read_static_resource(&uri)
+ .unwrap_or_else(|_| panic!("read_resource failed for agent `{}`", b.id))
+ };
+ #[cfg(not(feature = "flows"))]
+ let result = read_static_resource(&uri)
.unwrap_or_else(|_| panic!("read_resource failed for agent `{}`", b.id));
let text = result["contents"][0]["text"].as_str().unwrap_or("");
assert!(
@@ -94,7 +123,8 @@ fn read_resource_returns_content_for_each_subagent() {
#[test]
fn all_catalog_uris_are_unique() {
- let mut uris: Vec<&str> = RESOURCE_CATALOG.iter().map(|r| r.uri).collect();
+ let resources = resource_specs();
+ let mut uris: Vec<&str> = resources.iter().map(|r| r.uri.as_str()).collect();
let original_len = uris.len();
uris.sort_unstable();
uris.dedup();