feat(mcp): embedding-based semantic tool discovery (#2321)#2342
Merged
feat(mcp): embedding-based semantic tool discovery (#2321)#2342
Conversation
8f9a16b to
8f87220
Compare
Add SemanticToolIndex to zeph-mcp that embeds MCP tools once at connect time and retrieves top-K by cosine similarity per query, replacing the LLM call in prune_tools() when strategy = "embedding". - SemanticToolIndex: build() embeds tools concurrently (buffer_unordered 8), select() returns top-K filtered by min_similarity threshold - always_include resolved from original tool list (not only indexed entries) so failed-to-embed tools can still be pinned - ToolDiscoveryStrategy defined in zeph-mcp (no circular dep); config type ToolDiscoveryConfig in zeph-config with serde conversion in agent_setup - Description sanitization before embedding (strips control chars, 200 char cap) to prevent embedding poisoning via keyword-stuffed tool descriptions - Explicit warn! on all fallback paths; strict = true skips tool sync instead of silently passing all tools on embedding failure - Default strategy is "none" (opt-in); backward compatible - Fixes pre-existing gap: apply_mcp_pruning() was parsed but never wired - Fixes pre-existing bug: Llm + pruning_enabled=false skipped sync_mcp_executor_tools(); added explicit else clause - --init wizard: step_mcp_discovery() prompts for strategy/top_k/provider - --migrate-config: handled automatically via default.toml additions Closes #2321
f04adb8 to
718d989
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SemanticToolIndextozeph-mcp: embeds MCP tools once at connect time, retrieves top-K by cosine similarity per query — replaces the per-turn LLM call inprune_tools()whenstrategy = "embedding"ToolDiscoveryConfiginzeph-configwithstrategy,top_k,min_similarity,strict,embedding_providerfields; default strategy is"none"(backward compatible, opt-in)warn!on all fallback paths;strict = trueskips tool sync on failure instead of silently passing all toolsapply_mcp_pruning()was wired but never called inrunner.rsLlmstrategy +pruning_enabled=falseskippedsync_mcp_executor_tools()--initwizard updated withstep_mcp_discovery();--migrate-confighandled automatically viadefault.tomlCloses #2321
Test plan
cargo nextest run -p zeph-mcp --features full --lib— 315 tests pass (17 insemantic_index)cargo nextest run --workspace --features full --exclude exarch-python --exclude exarch-node --lib --bins— 6963 passed[mcp.tool_discovery] strategy = "embedding"in config and verify top-K tool selection in a session with 10+ MCP toolsstrict = true, kill embedding provider, verify warn log and no tool sync on that turn--initwizard and verify[mcp.tool_discovery]section is prompted and written to output config