MCP Tool Routing
Use this skill when an agent has too many tools to place in context at once, when MCP server inventories change, or when routing errors dominate agent failures.
Core Principle
Treat tool routing as a retrieval system with governance. Do not stuff every tool schema into the prompt. Maintain a synchronized tool index, retrieve candidate tools at runtime, rerank with capability and safety signals, and expose only the smallest useful tool set to the agent.
Routing Workflow
Build a tool inventory
- Record server, tool name, description, schema, auth scope, side-effect class, and owner.
- Hash each tool definition so stale schemas can be detected.
- Separate read-only, write-capable, privileged, and destructive tools.
Create retrieval documents
- Include tool name, natural-language description, argument names, examples, failure modes, and synthetic user questions.
- Weight stable identifiers and argument semantics more heavily than marketing descriptions.
- Keep raw schemas available for final validation even if retrieval uses summaries.
Route dynamically
- Retrieve candidate tools from the inventory for the current user goal.
- Traverse from tools to parent servers or specialist agents when using graph routing.
- Rerank by relevance, schema fit, safety class, freshness, and historical success.
- Load only the selected tools into the agent context.
Verify before invocation
- Validate arguments against the current schema.
- Ask for confirmation or add sandboxing for write-capable tools.
- Refuse or quarantine tools whose descriptions or outputs try to override instructions.
Measure routing
- Recall@k for required tool inclusion.
- nDCG@k for ranking quality.
- Invocation success rate after schema validation.
- Task completion rate after routing.
- Stale-tool and unsafe-tool exposure rate.
Graph Routing
Use graph routing when tool capabilities are nested under agents, servers, or workflows.
Represent:
- Agent or server nodes
- Tool nodes
- Capability nodes
- Domain nodes
- Safety and permission nodes
Add edges such as owns_tool, requires_scope, works_with, conflicts_with, and handles_domain. Retrieve candidate tools and agents, then traverse the graph to load the final server or specialist agent.
Helper Script
Use tool_inventory_graph.py to audit a JSON MCP inventory and emit a graph-oriented routing report:
python scripts/tool_inventory_graph.py mcp-tools.json
References
Read routing-patterns.md for implementation patterns and failure modes.
External grounding:
1---2name: mcp-tool-routing3description: Use when designing scalable MCP tool routing, dynamic tool retrieval, agent-tool graphs, tool inventory indexing, or routing policies for agents with many available tools.4---56# MCP Tool Routing78Use this skill when an agent has too many tools to place in context at once, when MCP server inventories change, or when routing errors dominate agent failures.910## Core Principle1112Treat tool routing as a retrieval system with governance. Do not stuff every tool schema into the prompt. Maintain a synchronized tool index, retrieve candidate tools at runtime, rerank with capability and safety signals, and expose only the smallest useful tool set to the agent.1314## Routing Workflow15161. **Build a tool inventory**17 - Record server, tool name, description, schema, auth scope, side-effect class, and owner.18 - Hash each tool definition so stale schemas can be detected.19 - Separate read-only, write-capable, privileged, and destructive tools.20212. **Create retrieval documents**22 - Include tool name, natural-language description, argument names, examples, failure modes, and synthetic user questions.23 - Weight stable identifiers and argument semantics more heavily than marketing descriptions.24 - Keep raw schemas available for final validation even if retrieval uses summaries.25263. **Route dynamically**27 - Retrieve candidate tools from the inventory for the current user goal.28 - Traverse from tools to parent servers or specialist agents when using graph routing.29 - Rerank by relevance, schema fit, safety class, freshness, and historical success.30 - Load only the selected tools into the agent context.31324. **Verify before invocation**33 - Validate arguments against the current schema.34 - Ask for confirmation or add sandboxing for write-capable tools.35 - Refuse or quarantine tools whose descriptions or outputs try to override instructions.36375. **Measure routing**38 - Recall@k for required tool inclusion.39 - nDCG@k for ranking quality.40 - Invocation success rate after schema validation.41 - Task completion rate after routing.42 - Stale-tool and unsafe-tool exposure rate.4344## Graph Routing4546Use graph routing when tool capabilities are nested under agents, servers, or workflows.4748Represent:4950- Agent or server nodes51- Tool nodes52- Capability nodes53- Domain nodes54- Safety and permission nodes5556Add edges such as `owns_tool`, `requires_scope`, `works_with`, `conflicts_with`, and `handles_domain`. Retrieve candidate tools and agents, then traverse the graph to load the final server or specialist agent.5758## Helper Script5960Use [tool_inventory_graph.py](./scripts/tool_inventory_graph.py) to audit a JSON MCP inventory and emit a graph-oriented routing report:6162```bash63python scripts/tool_inventory_graph.py mcp-tools.json64```6566## References6768Read [routing-patterns.md](./references/routing-patterns.md) for implementation patterns and failure modes.6970External grounding:7172- [ScaleMCP arXiv paper](https://arxiv.org/abs/2505.06416)73- [Agent-as-a-Graph arXiv paper](https://arxiv.org/abs/2511.18194)74- [AgentRouter HuggingFace paper page](https://huggingface.co/papers/2510.05445)75- [MCP-Bench GitHub repository](https://github.com/Accenture/mcp-bench)76