diff --git a/mcp/bun.lock b/mcp/bun.lock index 7e03a98d..52b157a4 100644 --- a/mcp/bun.lock +++ b/mcp/bun.lock @@ -5,7 +5,7 @@ "": { "name": "honcho-mcp-proxy", "dependencies": { - "@honcho-ai/sdk": "^2.1.0", + "@honcho-ai/sdk": "^2.2.0", "@modelcontextprotocol/sdk": "^1.26.0", "agents": "^0.4.0", "nanoid": "^5.1.7", diff --git a/mcp/package.json b/mcp/package.json index 2311020c..900df5cf 100644 --- a/mcp/package.json +++ b/mcp/package.json @@ -15,7 +15,7 @@ "deploy:staging": "wrangler deploy --env staging" }, "dependencies": { - "@honcho-ai/sdk": "^2.1.0", + "@honcho-ai/sdk": "^2.2.0", "@modelcontextprotocol/sdk": "^1.26.0", "agents": "^0.4.0", "nanoid": "^5.1.7", diff --git a/mcp/src/tools/workspace.ts b/mcp/src/tools/workspace.ts index 75f80f2c..cc35de5c 100644 --- a/mcp/src/tools/workspace.ts +++ b/mcp/src/tools/workspace.ts @@ -129,26 +129,40 @@ export function register(server: McpServer, ctx: ToolContext) { filters: message_filters, limit: message_limit, }; + + const searchMessages = async () => { + if (session_id) { + const session = await ctx.honcho.session(session_id); + return session.search(query, messageOptions); + } + if (peer) { + return peer.search(query, messageOptions); + } + return ctx.honcho.search(query, messageOptions); + }; + + // Conclusion search needs an (observer, observed) pair, so it only + // runs when peer_id is given. + const searchConclusions = async () => { + if (!peer) { + return []; + } + try { + return await peer.conclusions.query( + query, + conclusion_top_k, + undefined, + conclusion_filters, + ); + } catch (e) { + if (conclusion_filters) throw e; + return []; + } + }; + const [messages, conclusions] = await Promise.all([ - session_id - ? ctx.honcho - .session(session_id) - .then((session) => session.search(query, messageOptions)) - : peer - ? peer.search(query, messageOptions) - : ctx.honcho.search(query, messageOptions), - // Conclusion search needs an (observer, observed) pair, so it only - // runs when peer_id is given. Errors degrade to [] so message search - // still works, except when the caller passed filters: a bad filter - // must fail loudly, not look like zero matches. - peer - ? peer.conclusions - .query(query, conclusion_top_k, undefined, conclusion_filters) - .catch((e) => { - if (conclusion_filters) throw e; - return []; - }) - : [], + searchMessages(), + searchConclusions(), ]); return textResult({ messages: formatMessages(messages),