Dynamic Tool Discovery is a revolutionary feature in HasMCP designed to handle MCP servers with massive toolsets (e.g., 50+ tools) without saturating the model’s context window or incurring massive token costs.
In a standard MCP implementation, when a client connects to a server, it calls tools/list. The server returns the full JSON schema for every available tool.
For a server with 50 tools:
Each tool schema might average 200–500 tokens.
Total token cost for a single
tools/listcall: 10,000 – 25,000 tokens.This bloat consumes the context window, increases latency, and raises API costs before the agent has even performed a single action.
HasMCP’s Dynamic Tool Discovery implements a “Wrapper Pattern.” Instead of exposing every tool directly, the server hides its entire toolset and exposes only three standard discovery tools:
searchTools: Allows the agent to search for relevant tools or toolkits using BM25 (relevance) or Regex (pattern) search.getToolDefinition: Fetches the full JSON schema for a single specific tool only when the agent decides to use it.useTool: Executes a tool by name and arguments.
HasMCP employs a high-performance discovery engine that combines probabilistic ranking with pattern matching to ensure agents find the right tool with minimal trial and error.
Discovery uses a two-pronged approach to indexing:
BM25 (Best Matching 25):
Relevance Ranking: Uses a state-of-the-art probabilistic model to rank tools based on the semantic match between the agent’s keyword and the tool’s name, title, and description.
Configuration: Chosen for balance between precision and recall.
k1 = 1.2: Controls term frequency saturation.b = 0.75: Controls document length normalization (crucial for varying description lengths).
Custom Tokenization: Our engine doesn’t just split on spaces; it understands programming conventions by splitting on underscores, hyphens, and mixed casing, ensuring a search for
getUsermatchesget_userorget-user.
Regular Expressions (Regex):
Pattern Matching: Enables advanced discovery for specific patterns (e.g.,
^stripe.*(charge|refund)$).Case-Insensitivity: All searches are automatically enforced as case-insensitive (
(?i)) to prevent missed matches due to casing mismatches.
When an agent searches, HasMCP runs both algorithms in parallel and merges the indices uniquely. We prioritize BM25 results first to give the most “human-relevance” matches top billing, followed by Regex matches to capture specific structural patterns.
By using this wrapper approach, HasMCP achieves a token usage reduction of up to 95% for large toolsets.
While Claude’s tool-search-tool provides a way for agents to find tools in a large registry, HasMCP’s implementation is a generic MCP-level wrapper.
Universal: It works with any MCP-compliant client, not just Claude-specific agents.
Protocol-First: It doesn’t require “deferred loading” logic on the client side; the server itself manages the exposure of capabilities.
Docker’s dynamic-mcp focuses on the discovery and adding of new servers to an environment on-demand.
Granularity: HasMCP focuses on fine-grained tool discovery within a server.
Zero Reloads: In HasMCP, the client never needs to reload or re-initialize. The interaction interface (the 3 discovery tools) remains constant even as the available tool pool grows to hundreds of items.
Zero Client-Side Reloads: The client “sees” a stable set of 3 tools. New tools can be added to the backend without the client ever needing to restart or re-fetch a massive list.
On-Demand Precision: Full schemas are only injected into the context window when they are strictly necessary for execution.
Scalability: Enables the creation of “Mega-Servers” with hundreds of specialized tools without performance degradation.
Video link: