Logo: Rag Mcp Tool Selection

Rag Mcp Tool Selection

Communautéit
AnthonyAlcaraz
rag-mcp-tool-selection

Select the top-K tools from a registry of 30+ MCP / AWS / internal-API tools for a given natural-language query, replacing MCP's tools/list dump with a RAG-style filter that reduces prompt tokens 50-70%. Three-step pipeline: retrieve / validate / format. Use when the agent has access to many tools and prompt bloat is killing response quality. NOT for cases with under 10 tools (just include them all), NOT a replacement for an MCP server (this filters what an MCP server exposes), NOT for one-off scripts where the toolset is known and fixed.

Iwwersiicht

EditeurAnthonyAlcaraz
Repositoryagentic-graph-rag-skills
Skill-Nummrag-mcp-tool-selection
Stären
29
Forks
9
Matgeliwwert Dateien
3
LizenzMIT
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • 3 matgeliwwert Dateien

    Skripten, Virlagen a Referenzen, déi de Modell beim Schaffe liese kann. D'Dateie kënnen nëmme gelies ginn a ginn ni ausgeféiert.

  • Open Source

    AnthonyAlcaraz huet de Skill op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Rag Mcp Tool Selection an TypingMind, fir e mat all LLM ze benotzen, oder setzt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vu GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier, déi hei drënner steet, an a bestätegt d'Installatioun.
    https://github.com/AnthonyAlcaraz/agentic-graph-rag-skills/tree/main/skills/tool-orchestration/rag-mcp-tool-selection
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill derbäisetzen → Iwwer eng GitHub-URL. Pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an d'Skill-Verzeechnes vun deem KI-Agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/AnthonyAlcaraz/agentic-graph-rag-skills.git /tmp/agentic-graph-rag-skills
mkdir -p .claude/skills
cp -r /tmp/agentic-graph-rag-skills/skills/tool-orchestration/rag-mcp-tool-selection .claude/skills/rag-mcp-tool-selection
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Rag Mcp Tool Selection an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Rag Mcp Tool Selection automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Rag Mcp Tool Selection net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Schlësselen.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

RAG-MCP Tool Selection

Overview

The Model Context Protocol's tools/list operation returns every tool an agent has access to. At enterprise scale this consumes the context window before the agent has done any reasoning. The book's worked anchor is Block's Goose agent — 12,000 employees, 60+ MCP servers — where employees enabled every server "just in case" and tool descriptions ate the entire prompt budget.

The chapter cites measurable degradation from the RAG-MCP research:

Tools availableSelection accuracy (baseline LLM)
10Near-perfect
100Begins to degrade
1,000Below 40%

RAG-MCP replaces tools/list with a semantic search over tool metadata. Reported benchmarks: 50-70% prompt-token reduction, selection accuracy 13.62% → 43.13%, response time -60%. This skill is the smallest unit of that pattern — a function you can run before any LLM call to filter the tools you actually inject.

When to Use

Trigger contexts:

  • Building an MCP-based agent with 30+ tools exposed
  • A user asks the agent something that could match many tools, you want top-K
  • Migrating an existing single-shot prompt to MCP and the prompt is too big
  • Authoring a new tool registry — you want to verify each tool is findable

Phrases that should invoke this skill: "filter the tools", "which tools should the agent use", "the prompt is too big", "RAG-MCP", "tool selection", "reduce prompt bloat".

When NOT to Use

  • Under 10 tools. The book is explicit: with 10 tools the model achieves near-perfect selection. Filtering buys you nothing and adds latency.
  • Fixed-pipeline scripts where the tool sequence is hardcoded — no retrieval needed.
  • As a replacement for an MCP server. This skill picks WHICH tools an MCP server should expose for a query; it does not replace the server.
  • As a quality gate. Use the SkillNet five-dimension framework (Ch6) for skill-quality evaluation, not this skill.
  • For multi-tool workflow planning. This returns top-K tools by query similarity, not a dependency graph of tools. For collaborative-tool retrieval, see Baidu's COLT (Ch6) — out of scope here.

Process

StepInputActionOutputVerification
1Tool registry JSON (Toolshed five-component shape per tool)lib.load_registry(path)List of tool dictslen(registry) > 0; each tool has name, description, synthetic_queries, key_topics
2User query stringlib.retrieve(query, registry, top_k=5)Top-K scored tools (sorted by descending score)At least one tool with score > 0; otherwise registry has no relevant coverage
3Top-K scored toolslib.validate(scored, query)Filtered list (drops obvious-but-wrong matches)Validated count ≤ top-K; verify domain-token overlap
4Validated toolslib.invoke_prompt(validated, query)Formatted prompt-injection stringString contains only the validated tool descriptions (no full registry leakage)
5Baseline + filtered promptslib.approximate_token_count(...) on bothReduction percentageReduction > 50% for registries with 30+ tools; if not, registry is too small or retrieval is broken
6Selected tool names(your agent runtime) calls the chosen tool via boto3 / MCP / etc.Tool call resultTool call returns shaped data; if AccessDenied or signature error, the wrong tool was picked

Rationalizations

Agent rationalizationDocumented rebuttal
"I'll just send all tools — context windows are big now."The Block / Goose anchor in Ch5 is 60+ MCP servers exposing thousands of tools. Context windows expand; tool catalogs expand faster. The architectural shape is permanent.
"Word-overlap retrieval is too simple — I should use embeddings first."Production should use embeddings. The seam in lib.score_tool is one function. Replace it; the contract (returns float, higher = more relevant) is stable. The spike validates the pipeline, not the retriever.
"Validation can be skipped — top-K retrieval is enough."The chapter explicitly notes the false-positive failure mode: a tool that seems relevant by description keywords but serves a different purpose. The validate step is cheap (domain-token check); leaving it out re-introduces a known failure mode.
"I should pick top-1 instead of top-3 — fewer tools = less bloat."SkillsBench finding cited in Ch6: 2-3 focused skills per task is optimal. Top-1 forces a brittle commitment; top-3-to-5 gives the LLM room to pick the right one and reason about adjacent options.
"The token-reduction percentage doesn't matter if accuracy is high."The chapter pairs both metrics: 50-70% token reduction AND 13.62% → 43.13% accuracy. They compose. Optimizing one without the other defeats the architectural intent.

Red Flags

  • Token reduction below 30%. The registry is too small (under ~15 tools) for the filter to pay its way. Either skip the filter or grow the registry.
  • Top scored tool has score < 0.1 across many queries. Tool descriptions are too generic; rewrite them or add synthetic queries (Toolshed pattern).
  • Same tool wins every query. Either the registry has a "swiss army knife" tool with too-broad descriptions, or the retriever is degenerate. Inspect tool tokens and de-duplicate semantic hooks.
  • CLI --help exits non-zero. SKILL.md / CLI mismatch; the multi-harness invariant is broken.
  • No domain-token overlap between validated tools and query. Validation is collapsing to top-K-only (it should drop description-keyword false positives).

Non-Negotiable Verification

Before shipping a downstream agent built on this skill:

  1. Run the benchmark battery.

    python cli.py benchmark

    Confirm avg reduction > 50% across 8 scenarios. The shipped registry sample-aws-tools.json produces 88.2% avg.

  2. Inspect at least one filtered prompt visually.

    python cli.py show-prompt "your query here"

    Confirm the selected tools are the right tools (not just plausible by description). The spike documented one known failure mode: the query "audit who changed the production database" picks dynamodb_scan over cloudtrail_lookup_events because the simple word-overlap scoring rewards semantic-hook density. Production should swap to embeddings.

  3. JSON output round-trips.

    python cli.py select "..." --json | python -c "import json,sys; json.load(sys.stdin)"

    No exception means the CLI is harness-portable.

  4. Domain test against the DevOps latency scenario. Run the bundled notebook notebooks/spike-a-rag-mcp-tool-selection.ipynb. Confirm the moto-mocked CloudWatch Logs Insights call returns shaped data and the reduction percentage prints.

Security Posture

  • Prompt injection. Tool registry descriptions are author-controlled content. If you ingest descriptions from untrusted sources (auto-scraped API docs, community contributions), sanitize before indexing — a malicious description could embed instructions that bias retrieval. The Toolshed five-component representation makes the injection surface explicit; treat description and synthetic_queries as untrusted strings until validated.
  • Data exfiltration. This skill emits the filtered prompt back to the caller. No external network calls in lib.py. CLI --json output is printed to stdout; the caller is responsible for downstream piping.
  • Privilege escalation. No shell invocation, no concatenated input to shell, no file writes outside the registry path. The registry path comes from --registry flag or the bundled default — both are explicit.

Composition

  • Composes with Anthropic agent-skills Generator pattern at the pattern layer and Ghosh Primitive layer. The output (a filtered prompt string + selected tool list) is consumable by any orchestration layer above.
  • Composes with the MCP Gateway pattern (Writer's two-meta-tool design, Ch5) — the gateway can call this skill internally to decide which of its registered tools to surface.
  • Replaces, does not compose with, raw tools/list MCP calls when the registry exceeds ~15 tools.
  • Pairs with the evaluation discipline in skills/self-evolution/ (e.g. four-layer-eval-cascade) — measure top-K accuracy on a labeled query set before deploying.

Source Attribution

Distilled from Agentic GraphRAG (O'Reilly, by Anthony Alcaraz and Sam Julien), Chapter 5/6 — Tool Orchestration. Key references named in the chapter:

  • RAG-MCP framework (selection-accuracy and token-reduction benchmarks)
  • Block / Goose enterprise anchor (12,000 employees, 60+ MCP servers)
  • Toolshed (Zhu et al.) — five-component enhanced tool representation
  • COLT (Baidu) — collaborative tool retrieval graph (out of scope, see Ch6)
  • Anthropic Agent Skills specification — SKILL.md format
  • Microsoft Core AI Platform research on prompt bloat at MCP scale
  • Writer enterprise MCP gateway — two-meta-tool architecture

This skill is the smallest Generator-pattern primitive from that chapter, suitable as a starting point for any agent that needs to filter a large tool registry before invocation.

Matgeliwwert Dateien

De Modell liest dës Dateie bei Bedarf, wärend de Skill gelueden ass. Si ginn als liesbar Dateie bereetgestallt a ginn ni ausgeféiert.

Heefeg gestallte Froen

Wat mécht de KI-Skill Rag Mcp Tool Selection?

Select the top-K tools from a registry of 30+ MCP / AWS / internal-API tools for a given natural-language query, replacing MCP's tools/list dump with a RAG-style filter that reduces prompt tokens 50-70%. Three-step pipeline: retrieve / validate / format. Use when the agent has access to many tools and prompt bloat is killing response quality. NOT for cases with under 10 tools (just include them all), NOT a replacement for an MCP server (this filters what an MCP server exposes), NOT for one-off scripts where the toolset is known and fixed.

Firwat Rag Mcp Tool Selection op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Rag Mcp Tool Selection besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt, amplaz en Abonnement pro Benotzerplaz ze bezuelen. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Rag Mcp Tool Selection an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/AnthonyAlcaraz/agentic-graph-rag-skills/tree/main/skills/tool-orchestration/rag-mcp-tool-selection an. TypingMind liest d'Datei SKILL.md, bëndelt déi zougehéiereg Dateien an installéiert dat Ganzt als Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Rag Mcp Tool Selection benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Rag Mcp Tool Selection benotzen?

Esou vill wéi Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Rag Mcp Tool Selection domat benotzen – zum Beispill mat GPT, Claude, Gemini, Grok, DeepSeek, Mistral oder Llama – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Rag Mcp Tool Selection gratis?

Jo. AnthonyAlcaraz huet de Skill ënner der Lizenz MIT op GitHub publizéiert. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbare Pak vun Instruktiounen, deen engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt e maache soll a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a kee Lafzäitëmfeld a funktionéiere mat all Modell.

Alleguer weisen

Elo Ären eegene KI-Aarbechtsberäich ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇