Skip to content

ai-assistant: docs/mcp: Add MCP tool routing design#882

Open
illume wants to merge 1 commit into
headlamp-k8s:mainfrom
illume:docs/ai-assistant-mcp-tool-routing
Open

ai-assistant: docs/mcp: Add MCP tool routing design#882
illume wants to merge 1 commit into
headlamp-k8s:mainfrom
illume:docs/ai-assistant-mcp-tool-routing

Conversation

@illume

@illume illume commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Adds docs/mcp/mcp-tool-routing.md describing the MCPToolRouter and MCPEmbeddingRouter design: 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and MCPEmbeddingRouter (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)
@illume illume force-pushed the docs/ai-assistant-mcp-tool-routing branch 2 times, most recently from fb12fa4 to 934f486 Compare July 8, 2026 11:52
@illume illume requested a review from Copilot July 8, 2026 11:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 5 comments.

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>
@illume illume force-pushed the docs/ai-assistant-mcp-tool-routing branch from 934f486 to d0c6bd7 Compare July 8, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants