Skip to main content

Quick Reference: Intelligent Tool Discovery & Selection + MCP

ARCHIVE — This document is historical reference only. It may contain outdated information. See docs/status.md for current project state.

Feature: Smart Skill/Integration/MCP Tool Discovery via Semantic Search Phase: 3e.6 (Post-Phase 3e.5) Date: February 15, 2026 Includes: MCP (Model Context Protocol) Integration support


What Changed?

Before

  • System prompt included ALL 50+ tools in every request
  • LLM had to parse entire tool list, even when most were irrelevant
  • Token overhead: 3-5 KB per request
  • Scaled poorly as users downloaded more skills/integrations

Now

  • System prompt includes only ~10 most relevant tools selected by semantic search
  • LLM gets focused, concise tool list
  • Token overhead: 1-1.5 KB per request (60-70% savings)
  • Scales to 100+ user-downloaded tools without degradation
  • LLM can ask for more tools if needed via escape hatch

How It Works

1. Smart Tool Selection (Automatic)

When you send a message, Morphee:

  1. Embeds your message using the embedding model (same as memory search)
  2. Searches LanceDB locally to find the ~20 most similar tools
  3. Filters by your permissions (Space inheritance + ACL)
  4. Selects top 8-12 tools, always including core tools
  5. Passes only those tools to the LLM
User: "Schedule a meeting for tomorrow at 2pm"

System embeds the request

Finds: calendar, memory, frontend, notifications, tool_discovery

Morphee: "I've selected these tools based on your request:"
→ calendar__list_events
→ calendar__create_event
→ memory__search
→ notifications__send
→ frontend__show_form

Morphee schedules your meeting

2. Tool Discovery (Escape Hatch)

If Morphee selects tools that don't match your need, you can ask:

User: "Can you send an email?"
Morphee: "I don't have email in my current selection. Let me search for you..."

Morphee calls: tool_discovery__find("send email")

Found tools:
- gmail__send_email
- gmail__draft_email
- gmail__reply_email

Morphee: "I found email tools. Shall I send an email?"

Or explicitly ask to explore:

User: "What tools do I have?"

Morphee calls: tool_discovery__list_all()

Morphee shows all available tools grouped by category:
- Communication (email, chat, messaging)
- Planning (calendar, tasks, reminders)
- Memory (search, store, recall, forget)
- Frontend (show card, form, list, table)
- etc.

3. Transparency in System Prompt

The system prompt now explicitly tells the LLM:

# Tools Available for This Request

I've selected these tools based on your message:
1. calendar__list_events
2. calendar__create_event
3. memory__search
4. notifications__send
5. tool_discovery__find

These are the most relevant for what you asked.

# Discover More Tools

If you need something else, ask me: "What other tools do I have?"
I can search all available tools and suggest more options.

Benefits

For Users

  • Faster responses — LLM has smaller context, responds quicker
  • Smarter tool selection — Morphee picks relevant tools automatically
  • Transparent — You can see which tools were selected and why
  • Discoverable — Easy to find tools you need via tool_discovery__find()
  • Scales with marketplace — Add 50-100+ tools without degradation

For Developers

  • 60-70% token savings — Smaller system prompt = lower costs
  • Better performance — Embedding lookup (~50-100ms) offset by token savings
  • Marketplace-ready — New skills/integrations automatically embedded
  • ACL-aware — Respects Space inheritance and user permissions
  • Graceful fallback — Discovery tool handles edge cases

Technical Summary

Components Added

  1. ToolCatalogService (backend/chat/tool_catalog.py)

    • Embeds all tool descriptions at startup
    • Stores embeddings in LanceDB (desktop) + pgvector (server)
    • Provides vector search + text search APIs
  2. SmartToolSelector (backend/chat/tool_selector.py)

    • Selects top-K tools based on user message
    • Applies ACL filtering (per-Space/user permissions)
    • Always includes core tools (memory, tasks, frontend, notifications, discovery)
  3. ToolDiscoveryIntegration (backend/interfaces/integrations/tool_discovery.py)

    • New integration with find(), list_all(), describe() actions
    • Lets LLM and users explore available tools
    • Escape hatch when pre-selected tools aren't enough

Changes to Existing Code

  1. Orchestrator (backend/chat/orchestrator.py)

    • Calls SmartToolSelector before building tool list
    • Passes only selected tools to LLM
  2. Tool Bridge (backend/chat/tools.py)

    • Added tools_to_include parameter
    • Filters tools list to selected tools only
  3. System Prompt (backend/chat/prompts.py)

    • Shows selected tools + transparency message
    • Includes discovery guidance
    • Tool usage guidelines only for selected tools

Data Flow

User sends message

Orchestrator calls SmartToolSelector

SmartToolSelector:
1. Embeds user message
2. Searches LanceDB for top-20 similar tools
3. Filters by ACL (user permissions)
4. Always includes core tools
5. Returns top-K tools

Orchestrator builds Anthropic tools list from selected tools only

Orchestrator builds system prompt with selected tools + transparency

LLM receives request with focused tool list

LLM can:
- Use selected tools directly
- Call tool_discovery__find() for more tools if needed

Configuration

Max Tools to Select

Default: 10

  • Can be tuned in SmartToolSelector constructor
  • Trade-off: more tools = more context but better coverage

Core Tools (Always Included)

memory__search, memory__store, memory__recall, memory__forget
tasks__list, tasks__create, tasks__update_status
frontend__show_card, frontend__show_form, frontend__show_choices
notifications__send
tool_discovery__find

Embedding Provider

  • Uses existing RAG pipeline provider (FastEmbed or OpenAI)
  • Same 384-dim or 1536-dim vectors as memory search

Tool Catalog Invalidation

  • TTL-based: 1-hour automatic rebuild
  • Event-based: triggered when new skill/integration installed
  • Manual: admin command to force rebuild

Performance Metrics

MetricBeforeAfterSavings
System prompt size3-5 KB1-1.5 KB60-70%
Tools in context50+8-1280%
Per-request token overhead~500-1000~150-30060-70%
Embedding lookup latencyN/A~50-100ms(net gain)
Total request latencyX msX-600msnet win

Why latency improves: Smaller system prompt + fewer tool descriptions → LLM processes faster. Token savings >> embedding lookup cost.


MCP (Model Context Protocol) Integration

What is MCP?

MCP is an open protocol for AI systems to access external capabilities. Morphee's MCPIntegration acts as a broker:

  1. Register an MCP server (local or remote)
  2. Fetch its tool schema automatically
  3. Expose tools in tool_discovery immediately
  4. Execute MCP tools like any other tool

Example: Web Research MCP Server

User: "Find recent news about AI safety"

Morphee: "I have web research tools available. Let me search..."

Morphee calls: mcp_web_research__search_web(query="AI safety news")

MCP server (running locally or remotely):
1. Receives request
2. Searches the web
3. Returns results

Morphee: "Here are the latest articles..."

MCP Tool Registration

User: "Install the Web Research MCP server"

Morphee calls: mcp__register_server(
name="Web Research",
endpoint="https://mcp-web-research.example.com",
api_key="sk_xxx"
)

MCPIntegration:
1. Validates endpoint reachable
2. Fetches available tools:
- search_web
- fetch_page
- extract_content
3. Registers each as a callable tool

SmartToolSelector:
1. Next message considers all web research tools

tool_discovery__find("search the web"):
1. Returns: mcp_web_research__search_web + others

Key Benefits

  • Extensible ecosystem — Users can add MCP servers (marketplace, third-party, custom)
  • Transparent to user — MCP tools work like any other tools
  • Discoverable — All MCP tools appear in tool_discovery
  • Selective — SmartToolSelector picks relevant MCP tools per request
  • Secure — API keys stored in vault, ACL rules apply


Last Updated: February 15, 2026 Status: Ready to Implement