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
fix(mcp): handle missing tool spec fields gracefully
Steven Enamakel92eaefdb857e
diff --git a/crates/openhuman-core/src/mcp/server/tools/specs.rs b/crates/openhuman-core/src/mcp/server/tools/specs.rsindex 122092da47..9c844f4c36 100644--- a/crates/openhuman-core/src/mcp/server/tools/specs.rs+++ b/crates/openhuman-core/src/mcp/server/tools/specs.rs@@ -1,7 +1,10 @@use serde_json::{json, Value};use tinymcp::ServerToolSpec;-use super::types::{McpToolSpec, DEFAULT_LIMIT, MAX_LIMIT, SEARCH_MAX_RESULTS};+use super::types::{+ McpToolSpec, FETCH_MODES, ITEM_KINDS, LEARNING_KINDS, MEMORY_FORGET_MAX_IDS, MEMORY_MAX_LIMIT,+ SEARCH_MAX_RESULTS, SOURCE_KINDS,+};pub fn tool_specs() -> Vec<McpToolSpec> {let mut specs = base_tool_specs();@@ -119,117 +122,59 @@ pub fn base_tool_specs() -> Vec<McpToolSpec> {"openWorldHint": true}),},- McpToolSpec {- name: "memory.search",- title: "Search Memory",- description: "Keyword-search OpenHuman's local memory tree and return matching chunks \- ordered by recency. Every token in the query must appear in the stored \- chunk preview (ASCII case-insensitive, any order); punctuation between tokens \- does not matter. Results are preview-based, so zero hits do not prove that \- content is absent; try fewer/shorter tokens or `memory.recall` (semantic).",- rpc_method: Some("openhuman.memory_tree_search"),- input_schema: query_schema(- "Keywords; each must appear in the stored chunk preview (any order). Prefer a few \- short, distinctive tokens over long exact phrases; zero hits do not prove absence.",- ),- annotations: read_only_local_annotations(),- },McpToolSpec {name: "memory.recall",title: "Recall Memory",- description: "Semantically recall local memory-tree chunks relevant to a natural-language query.",- rpc_method: Some("openhuman.memory_tree_recall"),- input_schema: query_schema("Natural-language query to embed and rerank against memory summaries."),- annotations: read_only_local_annotations(),- },- McpToolSpec {- name: "tree.read_chunk",- title: "Read Memory Chunk",- description: "Read one memory-tree chunk by id. Use this to inspect the source text behind search or recall results.",- rpc_method: Some("openhuman.memory_tree_get_chunk"),- input_schema: json!({- "type": "object",- "properties": {- "chunk_id": {- "type": "string",- "description": "Chunk id returned by memory.search or memory.recall."- }- },- "required": ["chunk_id"],- "additionalProperties": false- }),- annotations: read_only_local_annotations(),- },- McpToolSpec {- name: "tree.browse",- title: "Browse Memory",- description: "Paginated listing of memory-tree chunks in reverse-chronological order, \- with optional filters by source kind, source id, entity id, time window, \- and token-AND keyword. Every token must appear in the stored chunk preview \- (ASCII case-insensitive, any order; punctuation does not matter). Use this \- when the user wants to enumerate (\"what's \- recent in my Gmail\", \"show me everything from last week about Alice\") \- rather than search by query. Returns chunks plus a total match count for \- pagination.",- rpc_method: Some("openhuman.memory_tree_list_chunks"),- input_schema: tree_browse_schema(),+ description: "Ask OpenHuman's memory a natural-language question and get a synthesised \+ answer with citations to the stored items it rests on. Read-only. Fails \+ with MEMORY_OFF when no memory engine is usable.",+ rpc_method: Some("openhuman.memory_recall"),+ input_schema: memory_recall_schema(),annotations: read_only_local_annotations(),},McpToolSpec {- name: "tree.top_entities",- title: "Top Memory Entities",- description: "List the most-referenced canonical entities (people, organizations, \- topics, emails) across the local memory tree. Call this for entity \- discovery before drilling in with `tree.browse` (passing `entity_ids`) \- or `memory.search`. Returns entities ordered by reference count.",- rpc_method: Some("openhuman.memory_tree_top_entities"),- input_schema: tree_top_entities_schema(),+ name: "memory.fetch",+ title: "Fetch Memory",+ description: "Raw retrieval over stored memory items: returns matching hits (text, \+ metadata, score) best first, optionally narrowed by a metadata filter. \+ `mode` must be one the active engine supports; both launch engines \+ (`tinyhumans`, `cortexdb`) support only `hybrid`, so omit `mode` unless \+ you know otherwise. Pass the returned `next_cursor` as `cursor` for the \+ next page. Read-only.",+ rpc_method: Some("openhuman.memory_fetch"),+ input_schema: memory_fetch_schema(),annotations: read_only_local_annotations(),},McpToolSpec {- name: "tree.list_sources",- title: "List Memory Sources",- description: "List every distinct ingest source (Gmail account, Slack channel, Notion \- workspace, email thread, …) that has data in the memory tree, with \- chunk counts and last-activity timestamps. Use this when the user asks \- \"what data sources do I have\" or to discover source ids to pass into \- `tree.browse`.",- rpc_method: Some("openhuman.memory_tree_list_sources"),- input_schema: tree_list_sources_schema(),+ name: "memory.list",+ title: "List Memory Items",+ description: "Page through stored memory items, newest first, optionally narrowed by a \+ metadata filter. Use this to enumerate (\"what did I store last week\") \+ rather than search by query. Pass the returned `next_cursor` as `cursor` \+ for the next page. Read-only.",+ rpc_method: Some("openhuman.memory_items_list"),+ input_schema: memory_list_schema(),annotations: read_only_local_annotations(),},McpToolSpec {- name: "memory.store",- title: "Store Memory",- description: "Create a new memory document from content. The document is stored in \- the specified namespace (default `mcp`) and can be retrieved via \- `memory.search` or `memory.recall`.",- rpc_method: Some("openhuman.memory_doc_put"),- input_schema: memory_store_schema(),- annotations: write_local_annotations(),- },- McpToolSpec {- name: "memory.note",- title: "Annotate Memory Chunk",- description: "Append a note to an existing memory chunk by storing a linked annotation \- document. The note references the original chunk_id for provenance and \- can be retrieved alongside it.",- rpc_method: Some("openhuman.memory_doc_put"),- input_schema: memory_note_schema(),- annotations: write_local_annotations(),+ name: "memory.learn",+ title: "Learn Memory",+ description: "Store one explicit learning (a preference, fact, procedure or correction) \+ in OpenHuman's memory. Returns the new item id. Adds an item; never \+ modifies or removes existing ones.",+ rpc_method: Some("openhuman.memory_learn"),+ input_schema: memory_learn_schema(),+ annotations: learn_annotations(),},McpToolSpec {- name: "tree.tag",- title: "Tag Memory Chunk",- description: "Apply one or more category tags to an existing memory chunk. \- Stored as an upsertable tag-record document linked to the target \- chunk_id, so re-tagging the same chunk replaces the prior tag set \- rather than accumulating duplicate annotations. Differs from \- `memory.note` in that the payload is a categorical label list — \- queryable via the document `tags` field — rather than free-form text.",- rpc_method: Some("openhuman.memory_doc_put"),- input_schema: tree_tag_schema(),- annotations: write_local_annotations(),+ name: "memory.forget",+ title: "Forget Memory",+ description: "Permanently remove memory items by id (ids come from memory.fetch, \+ memory.list or the citations of memory.recall). Returns how many were \+ forgotten. This cannot be undone.",+ rpc_method: Some("openhuman.memory_forget"),+ input_schema: memory_forget_schema(),+ annotations: forget_annotations(),},]}@@ -247,15 +192,21 @@ pub fn read_only_local_annotations() -> Value {})}-/// Annotation preset for the MCP write tools (`memory.store`, `memory.note`,-/// `tree.tag`) that upsert documents into OpenHuman's local memory tree.-/// Writes are keyed deterministically (slug-from-title, `mcp-note-<chunk_id>`,-/// `mcp-tag-<chunk_id>`) so repeating a call with identical arguments yields-/// the same stored state — `idempotentHint: true`. The upsert can replace a-/// previously stored document for the same key, which is a destructive update-/// in MCP-spec terms — `destructiveHint: true`. Local-only, no external I/O —-/// `openWorldHint: false`.-pub fn write_local_annotations() -> Value {+/// Annotation for `memory.learn`: writes a new item into the local memory+/// engine, never overwrites or removes (`destructiveHint: false`). Each call+/// stores another item, so it is not idempotent. Closed-world.+pub fn learn_annotations() -> Value {+ json!({+ "readOnlyHint": false,+ "destructiveHint": false,+ "idempotentHint": false,+ "openWorldHint": false+ })+}++/// Annotation for `memory.forget`: permanently deletes items (destructive);+/// repeating the same call leaves the same state (idempotent). Closed-world.+pub fn forget_annotations() -> Value {json!({"readOnlyHint": false,"destructiveHint": true,@@ -330,184 +281,159 @@ pub fn no_args_schema() -> Value {})}-pub fn query_schema(query_description: &str) -> Value {- json!({- "type": "object",- "properties": {- "query": {- "type": "string",- "description": query_description,- "minLength": 1- },- "k": {- "type": "integer",- "description": format!("Maximum chunks to return. Defaults to {DEFAULT_LIMIT}; capped at {MAX_LIMIT}."),- "minimum": 1,- "maximum": MAX_LIMIT- }- },- "required": ["query"],- "additionalProperties": false- })-}--fn tree_browse_schema() -> Value {+/// JSON Schema for the `MetaFilter` object of the memory-v2 spec.+pub fn meta_filter_schema() -> Value {+ let text = |description: &str| json!({"type": "string", "minLength": 1, "description": description});json!({"type": "object",+ "description": "Metadata filter; every given field must match. An empty filter matches everything.","properties": {- "source_kinds": {+ "workspace": text("Exact workspace (absolute path or logical id)."),+ "folder": text("Folder, exact or as a path prefix."),+ "file_path": text("File path, exact or as a path prefix."),+ "language": text("Exact language (`rust`, `python`, `en`, ...)."),+ "repo": text("Exact repository, `owner/name` or a remote URL."),+ "commit": text("Exact commit."),+ "url": text("Exact URL the item was read from."),+ "thread_id": text("Exact conversation thread id."),+ "agent_id": text("Exact id of the agent that produced the item."),+ "kinds": {"type": "array",- "items": { "type": "string" },- "description": "Restrict to one or more source kinds (e.g. `email`, `chat`, `document`). Omit to include all kinds."+ "items": {"type": "string", "enum": ITEM_KINDS},+ "description": "Item kinds to include; omit for all."},- "source_ids": {+ "sources": {"type": "array",- "items": { "type": "string" },- "description": "Restrict to specific logical source ids (e.g. a Slack channel id). Use `tree.list_sources` to discover these."+ "items": {"type": "string", "enum": SOURCE_KINDS},+ "description": "Source kinds to include; omit for all."},- "entity_ids": {+ "tags_any": {"type": "array",- "items": { "type": "string" },- "description": "Restrict to chunks referencing any of these canonical entity ids (e.g. `person:Alice`, `email:[email protected]`). Use `tree.top_entities` to discover these."- },- "since_ms": {- "type": "integer",- "minimum": 0,- "description": "Inclusive lower bound on chunk timestamp, in milliseconds since Unix epoch."+ "items": {"type": "string", "minLength": 1},+ "description": "Match items carrying any one of these tags."},- "until_ms": {- "type": "integer",- "minimum": 0,- "description": "Inclusive upper bound on chunk timestamp, in milliseconds since Unix epoch."+ "observed_after": {+ "type": "string", "format": "date-time",+ "description": "Inclusive lower bound on when the fact was observed (RFC 3339)."},- "query": {- "type": "string",- "minLength": 1,- "description": "Keywords matched against the stored chunk preview; every token must appear (ASCII case-insensitive, any order; punctuation does not matter). Zero hits do not prove absence."- },- "k": {- "type": "integer",- "minimum": 1,- "maximum": MAX_LIMIT,- "description": format!("Maximum chunks per page. Defaults to {DEFAULT_LIMIT}; capped at {MAX_LIMIT}.")- },- "offset": {- "type": "integer",- "minimum": 0,- "description": "Pagination offset (number of rows to skip). Defaults to 0."+ "observed_before": {+ "type": "string", "format": "date-time",+ "description": "Exclusive upper bound on when the fact was observed (RFC 3339)."}},- "required": [],"additionalProperties": false})}-fn tree_top_entities_schema() -> Value {+fn limit_schema(what: &str) -> Value {+ json!({+ "type": "integer",+ "minimum": 1,+ "maximum": MEMORY_MAX_LIMIT,+ "description": format!("Maximum {what} to return. Defaults to 10; capped at {MEMORY_MAX_LIMIT}.")+ })+}++fn cursor_schema() -> Value {+ json!({+ "type": "string",+ "minLength": 1,+ "description": "`next_cursor` from the previous page."+ })+}++fn memory_recall_schema() -> Value {json!({"type": "object","properties": {- "kind": {+ "question": {"type": "string","minLength": 1,- "description": "Restrict to a single entity kind (`person`, `email`, `topic`, `org`, …). Omit to span all kinds."+ "description": "The question to answer from memory, in natural language."},- "k": {- "type": "integer",- "minimum": 1,- "maximum": MAX_LIMIT,- "description": format!("Maximum entities to return. Defaults to {DEFAULT_LIMIT}; capped at {MAX_LIMIT}.")- }+ "filter": meta_filter_schema(),+ "limit": limit_schema("citations")},- "required": [],+ "required": ["question"],"additionalProperties": false})}-fn tree_list_sources_schema() -> Value {+fn memory_fetch_schema() -> Value {json!({"type": "object","properties": {- "user_email_hint": {+ "query": {"type": "string","minLength": 1,- "description": "When provided, the user's own email is stripped from email-thread display names so the other party shows up instead. Optional."- }+ "description": "What to search for."+ },+ "mode": {+ "type": "string",+ "enum": FETCH_MODES,+ "description": "Retrieval mode. Must be one the active engine supports; both launch engines support only `hybrid`. Omit to use the engine's default."+ },+ "filter": meta_filter_schema(),+ "limit": limit_schema("hits"),+ "cursor": cursor_schema()},- "required": [],+ "required": ["query"],"additionalProperties": false})}-fn memory_store_schema() -> Value {+fn memory_list_schema() -> Value {json!({"type": "object","properties": {- "title": {- "type": "string",- "minLength": 1,- "description": "Human-readable title for the memory document."- },- "content": {- "type": "string",- "minLength": 1,- "description": "The text content to store as a memory document."- },- "namespace": {- "type": "string",- "minLength": 1,- "description": "Namespace to store the document in. Defaults to `mcp` when omitted."- },- "tags": {- "type": "array",- "items": { "type": "string" },- "description": "Optional tags for categorisation and filtering."- }+ "filter": meta_filter_schema(),+ "limit": limit_schema("items"),+ "cursor": cursor_schema()},- "required": ["title", "content"],+ "required": [],"additionalProperties": false})}-fn memory_note_schema() -> Value {+fn memory_learn_schema() -> Value {json!({"type": "object","properties": {- "chunk_id": {+ "text": {"type": "string","minLength": 1,- "description": "ID of the memory chunk to annotate. Use an ID from memory.search or memory.recall results."+ "description": "What was learned, as a self-contained statement."},- "note_text": {+ "kind": {"type": "string",- "minLength": 1,- "description": "The note text to attach to the chunk."+ "enum": LEARNING_KINDS,+ "description": "What kind of learning this is. Defaults to `fact`."+ },+ "confidence": {+ "type": "number",+ "minimum": 0,+ "maximum": 1,+ "description": "Confidence in the learning, 0 to 1. Defaults to 0.8."}},- "required": ["chunk_id", "note_text"],+ "required": ["text"],"additionalProperties": false})}-fn tree_tag_schema() -> Value {+fn memory_forget_schema() -> Value {json!({"type": "object","properties": {- "chunk_id": {- "type": "string",- "minLength": 1,- "description": "ID of the memory chunk to tag. Use an ID from `memory.search`, `memory.recall`, or `tree.browse` results."- },- "tags": {+ "ids": {"type": "array",- "items": {- "type": "string",- "minLength": 1- },+ "items": {"type": "string", "minLength": 1},"minItems": 1,- "description": "One or more category labels to attach (e.g. `[\"todo\", \"q3-planning\"]`). Re-tagging the same chunk replaces the prior tag set; supply the complete desired set on each call."+ "maxItems": MEMORY_FORGET_MAX_IDS,+ "description": "Ids of the memory items to remove permanently."}},- "required": ["chunk_id", "tags"],+ "required": ["ids"],"additionalProperties": false})}