ai-assistant: docs/mcp: Add MCP tool routing design#882
Open
illume wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new MCP documentation page explaining the design approach for routing MCP tools (keyword-based and optional embedding-based) so the LLM only sees a relevant subset of tool schemas per query.
Changes:
- Add
MCPToolRouter(keyword overlap) andMCPEmbeddingRouter(semantic similarity + fallback) architecture/design description. - Document proposed configuration knobs and an integration example for producing a filtered MCP tool list.
- Add a “Tests” section and references to related routing concepts/docs.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+5
to
+6
| only the relevant tools per query — analogous to the | ||
| [skills router](../skills/skills-router.md). |
Comment on lines
+73
to
+74
| packages/ai-common | ||
| npx vitest run src/mcp/MCPToolRouter.test.ts src/mcp/MCPEmbeddingRouter.test.ts |
| ## Integration | ||
|
|
||
| ```typescript | ||
| import { routeMCPTools } from '@headlamp-k8s/ai-common/mcp/MCPToolRouter'; |
| ## References | ||
|
|
||
| - [LangChain Embeddings](https://js.langchain.com/docs/concepts/embedding_models/) | ||
| - [Skills Router](../skills/skills-router.md) |
fb12fa4 to
934f486
Compare
| When many MCP servers expose dozens of tools, sending every tool schema to | ||
| the LLM wastes context window and slows responses. MCP tool routing selects | ||
| only the relevant tools per query — analogous to the | ||
| [skills router](../skills/skills-router.md). |
| ## References | ||
|
|
||
| - [LangChain Embeddings](https://js.langchain.com/docs/concepts/embedding_models/) | ||
| - [Skills Router](../skills/skills-router.md) |
Comment on lines
+52
to
+58
| import { routeMCPTools } from '@headlamp-k8s/ai-common/mcp/MCPToolRouter'; | ||
|
|
||
| const allMCPTools = toolManager.getMCPTools(); | ||
| const toolInfos = allMCPTools.map(t => ({ | ||
| name: t.name, description: t.description, serverName: t.name.split('__')[0], | ||
| })); | ||
| const relevant = routeMCPTools(userQuery, toolInfos, { maxTools: 8, minScore: 0.1 }); |
Comment on lines
+70
to
+75
| ## Tests | ||
|
|
||
| ```bash | ||
| packages/ai-common | ||
| npx vitest run src/mcp/MCPToolRouter.test.ts src/mcp/MCPEmbeddingRouter.test.ts | ||
| ``` |
Comment on lines
+61
to
+68
| ## Comparison with skills routing | ||
|
|
||
| | Aspect | Skills router | MCP tool router | | ||
| |--------|--------------|----------------| | ||
| | Input | Parsed markdown files | MCP tool schemas | | ||
| | Output | Prompt text for system message | Filtered tool list bound to model | | ||
| | Embedding router | `EmbeddingRouter` | `MCPEmbeddingRouter` | | ||
| | Keyword router | `routeSkills()` | `routeMCPTools()` | |
Documents the MCP tool routing layer. When many MCP servers expose dozens of tools, sending every tool schema to the LLM wastes context window and slows responses. The routing layer selects only the tools relevant to each query: - `MCPToolRouter`: keyword-overlap scoring between the query and tool names / descriptions. Fast, zero-dependency, always available. - `MCPEmbeddingRouter`: semantic similarity via a pluggable LangChain Embeddings instance. Falls back to `MCPToolRouter` on any failure. Documents the routing pipeline, configuration knobs (score threshold, max tools selected), and the analogous relationship with the skills router. Signed-off-by: René Dudfield <renedudfield@microsoft.com> Co-authored-by: Ashu Ghildiyal <aghildiyal@microsoft.com> Signed-off-by: Ashu Ghildiyal <aghildiyal@microsoft.com>
934f486 to
d0c6bd7
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.
Adds
docs/mcp/mcp-tool-routing.mddescribing theMCPToolRouterandMCPEmbeddingRouterdesign: how tool calls are matched to MCP servers using keyword overlap and optional semantic embedding similarity.Assisted by Copilot.
Part of the ai-assistant MCP documentation series.