mcp-context-forge
mcp-context-forge copied to clipboard
[Feature Request]: CRT-Based Semantic Tool Router for Dynamic MCP Servers
π§ Epic
Title: CRT-Based Semantic Tool Router Plugin for Dynamic MCP Servers
Goal: Introduce a new plugin (mcpgateway/plugins/crt_router) that enables the MCP Gateway to dynamically select and expose only the most semantically relevant tools based on the userβs prompt β without relying on LLM calls. This predictive router leverages a learned latent difficulty model (via Chinese Remainder Theorem fusion) to replace or complement existing LLM-based tool selection.
πββοΈ User Story 1
As a: developer using the MCP ecosystem
I want: the gateway to semantically filter and display only relevant tools for a given prompt
So that: the LLM isnβt overloaded by irrelevant tools and delivers faster, higher-quality responses.
β Acceptance Criteria
- Given a user prompt is received
When the CRT Router computes semantic relevance bins
Then only the top-K or below-threshold tools are exposed to the LLM context. - Given a registry with unrelated tools
When the prompt has no semantic connection to them
Then those tools are excluded from the final catalog.
πββοΈ User Story 2
As a: model integrator or AI engineer
I want: to reduce tool overload during dynamic server resolution
So that: inference latency and prompt length both decrease, and reasoning accuracy improves.
β Acceptance Criteria
- Given many tools registered in the MCP Gateway
When only the semantically relevant subset is injected into the prompt
Then tool invocation reliability improves and cost/latency are reduced.
π§ Implementation Sketch
Implementation Mode: Plugin
- Implement as a plugin under
mcpgateway/plugins/crt_router/ - Register a new routing mode
"crt"at startup:def register_plugin(app): from mcpgateway.plugins.crt_router.semantic_router import CRTRouter app.state.router_modes["crt"] = CRTRouter() - Core logic in
semantic_router.py:- Load calibration artifacts (difficulty bins
S, prime list, priorΟ(s), and calibrated success tablesaΜβ(s)). - Compute modular residues β fuse posteriors β compute expected loss β rank tools.
- Load calibration artifacts (difficulty bins
- Add config toggle:
MCPGATEWAY_ROUTER_MODE=crt - Extend
/dynamic/{id}/toolsendpoint:/dynamic/{id}/tools?router=crt&k=10&threshold=0.72 - Optional endpoint:
β returns model calibration checksum, entropy, and version info./router/health - Store calibration JSON under
/data/calibration/or/examples/.
π§© Dependencies
- Dynamic Server API (
/dynamic) β #123 - Taggable Tool Metadata β #586 / #676
- (Optional) LLM Router Mode parity β #130
π§ Design Rationale
Current Dynamic Server selection supports rule-based and LLM-based filtering.
However, LLM selection:
- incurs extra inference cost,
- introduces nondeterminism, and
- lacks transparent calibration.
The CRT Router is predictive, not generative.
It learns semantic βdifficultyβ and tool-relevance structure offline, then applies a modular Bayesian fusion (via CRT) to choose tools in microseconds β achieving deterministic, explainable selection.
π Expected Business Value
- Efficiency: avoids unnecessary LLM calls and shortens context windows.
- Predictability: deterministic behavior; can run in restricted or air-gapped deployments.
- Scalability: same architecture extends to hundreds of tools with no performance penalty.
- Auditability: route decisions can be explained using posterior entropy or expected loss metrics.
In short: CRT makes dynamic MCP servers intelligent selectors, not just LLM-driven filters.
π€ Ownership
Assignee: @pbarbas Reviewers: @crivetimihai
ποΈ Milestone
Target: Release 1.0.0
β Definition of Done
- [ ] Plugin module under
mcpgateway/plugins/crt_router/registered successfully. - [ ] CRT inference engine loads calibration and computes relevance deterministically.
- [ ]
/dynamic/{id}/tools?router=crtreturns filtered catalog consistent with top-K semantic bins. - [ ] Config and environment toggle fully functional (
MCPGATEWAY_ROUTER_MODE). - [ ] 90 %+ test coverage for new code paths.
- [ ] Admin UI lists βCRT Routerβ as a selectable routing strategy.
- [ ] Documentation updated with usage, configuration, and calibration steps.
- [ ] Prometheus metrics:
router_crt_requests_total, latency, and cache hit rate.
π§ References
- Blueprint: CRT Routing v2 β Robust, Information-Adaptive Router
- Related Works: FrugalGPT (Chen et al., 2024), Fusion of Experts (2024), Context Rot (Hong et al., 2025)
- Goal: Replace heuristic LLM filtering with predictive, modular semantic routing.