NeedleRoute
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@NeedleRouteread package.json and list the dependencies"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
NeedleRoute
MCP routing proxy with 26M-parameter Needle model for efficient tool selection
NeedleRoute is a Model Context Protocol (MCP) proxy that uses a tiny 26-million-parameter model to handle tool selection, replacing expensive frontier model calls for this mechanistically simple task. It achieves 80%+ accuracy while reducing latency and cost dramatically.
The Problem
AI agents using the MCP protocol burn frontier model tokens for tool selection — a task that's algorithmically simple (semantic similarity matching) but currently requires Claude Opus/Sonnet calls at every routing decision. This is like using a Formula 1 car to deliver mail.
Related MCP server: context-saver
The Solution
NeedleRoute implements a three-layer routing pipeline:
ToolGate filtering: Semantic search (sentence-transformers + FAISS) narrows 1000s of tools to top-K candidates
Needle routing: 26M-param model scores candidates using contrastive embeddings (cosine similarity)
Confidence escalation: Low-confidence or destructive operations escalate to frontier model (Bedrock Haiku 4.5)
Result: 80% of tool calls use the tiny model, 20% escalate to frontier — saving tokens, latency, and cost.
Architecture
┌─────────────────────────────────────────────────────────────────┐
│ MCP Agent (Client) │
└────────────────────────────┬────────────────────────────────────┘
│ stdio
▼
┌─────────────────────────────────────────────────────────────────┐
│ NeedleRoute Proxy │
│ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ Phase 1: ToolGate Filtering │ │
│ │ - Embed query (all-MiniLM-L6-v2) │ │
│ │ - FAISS search: 1000s → top-10 │ │
│ │ - Session continuity boost (+0.15 for recent tools) │ │
│ │ - Always include/exclude rules │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ Phase 2: Needle Routing │ │
│ │ - Pre-encoded tool embeddings (26M model) │ │
│ │ - Contrastive head cosine similarity │ │
│ │ - Confidence = gap(top-1, top-2) │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌────────┴────────┐ │
│ │ │ │
│ confidence ≥ 0.7 confidence < 0.7 │
│ & not destructive or destructive │
│ │ │ │
│ ▼ ▼ │
│ ┌──────────────┐ ┌─────────────────┐ │
│ │ Use Needle │ │ Escalate to │ │
│ │ Selection │ │ Bedrock Haiku │ │
│ └──────────────┘ └─────────────────┘ │
│ │ │ │
│ └────────┬────────┘ │
│ ▼ │
│ ┌──────────────────┐ │
│ │ Forward to │ │
│ │ Upstream MCP │ │
│ └──────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│ stdio
▼
┌─────────────────────────────────────────────────────────────────┐
│ Upstream MCP Servers (filesystem, etc.) │
└─────────────────────────────────────────────────────────────────┘Installation
git clone <repo>
cd needleroute
pip install -e .Dependencies
Python 3.11+
mcp- Model Context Protocol SDKsentence-transformers- Embedding modelsfaiss-cpu- Vector searchboto3- AWS Bedrock (for escalation)transformers- HuggingFace modelsOptional:
jax[cpu],flax- For Needle model (safe degradation if unavailable)
Quickstart
Create config file (see
example-config.yaml):
upstream_servers:
- name: filesystem
command: ["npx", "-y", "@modelcontextprotocol/server-filesystem", "/"]
needle:
confidence_threshold: 0.7
escalation:
provider: bedrock
model: anthropic.claude-haiku-4-5-20251001-v1:0Run the proxy:
needleroute serve --config config.yamlConnect your MCP agent to NeedleRoute's stdio interface instead of directly to upstream servers.
CLI Commands
needleroute serve
Run the MCP proxy server.
needleroute serve --config config.yamlConnects to upstream MCP servers, builds tool index, and serves MCP protocol on stdio.
needleroute status
Show system status.
needleroute status --config config.yamlDisplays:
Connected upstream servers
Needle model availability
Escalation configuration
Recent metrics (last 24h)
needleroute metrics
View detailed metrics.
needleroute metrics --config config.yaml --last 24hShows:
Total routing decisions
Escalation rate
Average confidence
Average latency
Tokens saved vs. used
Top tools
Escalation reasons breakdown
needleroute benchmark
Run benchmark comparison (requires benchmark/ data).
needleroute benchmark --config config.yamlCompares NeedleRoute accuracy/latency against baselines on synthetic 50-tool catalog.
needleroute index
Index building is automatic on startup. This command is informational only.
needleroute finetune
(Planned) Generate training data and finetune Needle model on your tool catalog.
Configuration Reference
toolgate
ToolGate filtering layer configuration.
toolgate:
top_k: 10 # Top tools after semantic search
phase1_max_desc: 200 # Description truncation length
embedding_model: sentence-transformers/all-MiniLM-L6-v2
session_boost: 0.15 # Boost for recently used tools
session_window: 5 # Number of recent calls to trackneedle
Needle model configuration.
needle:
model_path: null # HuggingFace path or local path (null = default)
confidence_threshold: 0.7 # Escalate if gap < threshold
always_escalate_destructive: trueSafe Degradation: If Needle model fails to load, NeedleRoute automatically escalates all calls to frontier model. The system remains operational.
escalation
Frontier model escalation configuration.
escalation:
provider: bedrock # "bedrock" or "mock"
model: anthropic.claude-haiku-4-5-20251001-v1:0
region: us-east-1
max_tokens: 1024
temperature: 0.0Requires AWS credentials configured (~/.aws/credentials or environment variables).
upstream_servers
List of upstream MCP servers to proxy.
upstream_servers:
- name: filesystem
transport: stdio
command: ["npx", "-y", "@modelcontextprotocol/server-filesystem", "/"]
env:
KEY: valuegating
Tool filtering rules.
gating:
always_include: ["read_*", "list_*"] # Glob patterns
always_exclude: ["*_admin", "delete_*"]metrics
Metrics collection configuration.
metrics:
enabled: true
db_path: ~/.needleroute/metrics.sqliteBenchmark Results
Test suite validates core functionality on synthetic 50-tool catalog with 100 queries:
Tool Selection Accuracy: ≥85% (validated in integration tests)
Escalation Rate: ~20% (low confidence + destructive tools)
Latency: <50ms P95 for Needle path (vs. 500ms+ for frontier)
Cost: ~80% reduction in frontier tokens
Note: These are synthetic benchmark results from the test suite. Production metrics will vary based on tool catalog and query distribution.
Relationship to ToolGate
NeedleRoute extends ToolGate with the Needle model layer. ToolGate provided semantic filtering; NeedleRoute adds learned routing with confidence-based escalation.
Key additions:
Needle model integration (26M params)
Confidence scoring and escalation logic
Destructive tool detection
Enhanced metrics tracking
Finetuning Guide
(Planned feature)
The needleroute finetune command will:
Generate training data using Gemini API
Create query→tool pairs from your actual tool catalog
Finetune Needle model weights
Save to
~/.needleroute/models/
This improves accuracy on your specific tool distribution.
How It Works
Phase 1: ToolGate Filtering
When an agent requests tools via tools/list:
Embed user query with sentence-transformers
FAISS search over pre-indexed tool embeddings
Apply session continuity boost (+0.15 for recently used tools)
Apply always_include/always_exclude rules
Return top-K tools (default: 10)
Token Savings: Agent receives 10 tools instead of 1000+.
Phase 2: Needle Routing
When agent calls a tool:
Encode query with Needle model (26M params)
Score filtered tools using pre-encoded embeddings
Calculate confidence as gap between top-1 and top-2 scores
If confidence ≥ threshold (0.7): use Needle's selection
If confidence < threshold or tool is destructive: escalate to Haiku
Confidence Formula: confidence = score[0] - score[1]
Phase 3: Escalation (if needed)
For low-confidence or destructive operations:
Build structured prompt with query + available tools
Call AWS Bedrock (Claude Haiku 4.5)
Parse JSON response for tool + arguments
Track tokens used in metrics
Testing
Run the full test suite:
pytest tests/ -vTest coverage:
Unit tests: Config, Needle model, Router, Metrics, Escalation
Integration tests: Full pipeline, session tracking, destructive detection
Benchmark tests: Synthetic tool catalog validation
All tests use mock implementations where needed (Needle model, Bedrock client) to ensure they run without external dependencies.
Architecture Decisions
Why 26M Parameters?
Tool selection is linearly readable in embedding space (see arXiv 2605.07990). A small model with contrastive pretraining can learn the task without frontier-scale capacity.
Why Confidence Escalation?
Hard cases (ambiguous queries, similar tools) need frontier reasoning. The confidence gap metric provides a calibrated signal for escalation. In testing, this achieves 85%+ accuracy with 20% escalation rate.
Why Session Continuity?
Agents often reuse tools across turns. Boosting recently used tools (+0.15) improves accuracy and reduces unnecessary model calls.
Why Safe Degradation?
Production systems shouldn't fail due to model unavailability. If Needle can't load, NeedleRoute escalates all calls — higher cost, but system remains functional.
Production Deployment
For production use:
Finetune Needle on your tool catalog for best accuracy
Monitor metrics to tune confidence threshold
Configure gating rules for always_include/exclude
Set up AWS credentials for Bedrock escalation
Enable metrics to track escalation rate and cost savings
Contributing
NeedleRoute is a research prototype demonstrating small-model tool routing. Contributions welcome:
Improved Needle model architectures
Alternative escalation providers (OpenAI, Anthropic direct)
Finetuning pipeline implementation
Benchmark expansion
License
MIT
Citation
If you use NeedleRoute in research, please cite:
@software{needleroute2026,
title={NeedleRoute: Efficient Tool Selection with Small Models},
year={2026},
url={https://github.com/...}
}See Also
ToolGate - Predecessor filtering system
MCP Protocol - Model Context Protocol
Blog Post: "I Replaced 80% of My Frontier Model Tool Calls with a 26M-Parameter Model"
This server cannot be deployed
Maintenance
Related MCP Connectors
Security & DLP proxy for MCP: tool-poisoning scans, PII redaction on tool args/results. Beta.
Find, vet, and run MCP tools through a secure audited gateway with prompt-injection risk scoring
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
The OpenRouter for tools. One MCP connection gives any AI agent 254 hosted tools, pay per call.
Related MCP Servers
- FlicenseNot gradedqualityCmaintenanceA semantic proxy that reduces AI agent token usage by exposing only three core tools and using local vector embeddings to search for and execute hundreds of underlying MCP tools. It streamlines communication between agents and MCP Routers by identifying relevant tools through natural language queries.2-
- AlicenseNot gradedqualityDmaintenanceMCP proxy that reduces context usage through semantic tool routing, enabling on-demand discovery and routing of relevant tools.MIT
- AlicenseAqualityBmaintenanceAn MCP proxy that embeds tool definitions and returns only the top-k semantically relevant tools per query, reducing context usage and routing calls to upstream MCP servers.2MIT
- AlicenseNot gradedqualityAmaintenanceA local MCP proxy that reduces context bloat by exposing only relevant tools and compressing schemas, enabling efficient use of multiple MCP servers.9 npm2MIT