openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

Add MCP tools for memory navigation and integration discovery

Open justinhsu1477 opened this issue 6 months ago • 1 comments

Summary

Add three read-only MCP tools on top of the Phase 1 surface (memory.search, memory.recall, tree.read_chunk):

  • tree.browse — paginated chunk listing with source / topic / time filters.
  • tree.search_entities — find chunks by named entity (person, org, project).
  • integrations.list_connections — list connected sources so a client can scope subsequent queries.

All three are thin adapters over existing controller-registry RPCs, follow the Phase 1 ToolCallError / enforce_read_policy model, and stay strictly read-only.

Problem

The Phase 1 surface (#1760 + #1790) is enough for "find a chunk by keyword / semantic query and read it." It leaves three gaps that show up the moment an MCP client tries to be useful beyond direct keyword recall:

  1. No way to browse. A client can only call memory.search / memory.recall and hope the query is right. There is no listing, no filtering by source, no time-window scan. A user asking "what's recent in my Gmail?" forces the LLM to guess search terms instead of paging through.
  2. No entity awareness. A client cannot ask "what does my memory say about Alice / Acme Corp?" without pretending it's a keyword. memory_tree_search_entities already exists in the registry — Phase 1 just doesn't expose it.
  3. No source discovery. Before running any query the client has no way to know which integrations (Gmail, Slack, Notion, …) actually have data. Models end up calling memory.search against keywords that have no chance of matching anything.

These are the three single-call shapes a Claude Desktop / Cursor session most often needs after the initial "I know roughly what I'm looking for" interaction.

Solution (optional)

Sketch, happy to revise per maintainer input:

MCP tool Backing RPC Why this one
tree.browse openhuman.memory_tree_list_chunks Paginated listing already supports the source_kind / source_id / entity_ids / time-window / keyword filters we want.
tree.search_entities openhuman.memory_tree_search_entities Lets the LLM say "Alice" instead of guessing every keyword permutation.
integrations.list_connections composio.list_connections Cheap discovery call. Lets the LLM pre-filter searches to sources that actually have data, instead of fishing on dead ones.

Same module + adapter pattern as Phase 1:

  • Tools live next to the existing three in src/openhuman/mcp_server/tools.rs.
  • Each runs through validate_controller_params and enforce_read_policy(ToolOperation::Read).
  • New ToolCallError variants not required — the new tools surface as InvalidParams for bad input and Internal for config-load failures, matching #1790.
  • Tool descriptions are tuned so the LLM picks the right tool: "browse when you want pagination or a source filter; recall/search when you have a query string."

Acceptance criteria

  • [ ] tree.browse — accepts source_kind?, source_id?, entity_ids?, since?, until?, keyword?, page?, k? (defaults & caps mirror Phase 1's k); rejects unexpected args.
  • [ ] tree.search_entities — accepts entity (required, non-empty string) and k? (≤ 50); rejects unexpected args.
  • [ ] integrations.list_connections — no args; returns connected toolkits with their last-sync time. Skips sensitive fields (tokens).
  • [ ] Schema validation — every new tool round-trips through validate_controller_params against its mapped RPC schema; mapping regression caught at unit test time (same pattern as mapped_rpc_methods_are_registered).
  • [ ] enforce_read_policy — every new tool gated through SecurityPolicy with ToolOperation::Read.
  • [ ] Diff coverage ≥ 80% — happy path + at least one invalid-arg path per tool, per Testing Strategy.

Related

  • Feature IDs: 11.1.4 (MCP stdio server)
  • Builds on: #1760, #1790
  • Refs: #1586

justinhsu1477 avatar May 16 '26 09:05 justinhsu1477

Implementation up in #1974, with one scope refinement worth flagging here:

  • tree.search_entities (proposed) — memory_tree_search_entities lives only in the retrieval module, not the controller registry. Pivoted to tree.top_entities → openhuman.memory_tree_top_entities, which gives the LLM canonical-entity discovery before drilling in with tree.browse (entity_ids).
  • integrations.list_connections (proposed) — replaced with tree.list_sources → openhuman.memory_tree_list_sources. The memory-tree source list answers the LLM's "what data do I have" question more directly than OAuth state; happy to add the composio version in a separate PR if maintainers prefer.

tree.browse lands as proposed. Full rationale + 13 new unit tests in the PR.

justinhsu1477 avatar May 17 '26 00:05 justinhsu1477