Logo von Rag Mcp Tool Selection

Rag Mcp Tool Selection

Community
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.

Übersicht

HerausgeberAnthonyAlcaraz
Repositoryagentic-graph-rag-skills
Skill-Namerag-mcp-tool-selection
Sterne
29
Forks
9
Mitgelieferte Dateien
3
LizenzMIT
Links
  • Anweisungen in Markdown

    Eine SKILL.md-Datei, die das Modell bei Bedarf lädt. So werden nur dann Token verbraucht, wenn eine Anfrage tatsächlich dazu passt.

  • Funktioniert mit jedem LLM

    KI-Skills bestehen aus reinem Markdown, nicht aus anbieterspezifischem Code. Daher funktionieren sie mit GPT, Claude, Gemini, Grok oder einem lokalen Modell.

  • Mitgelieferte Dateien: 3

    Skripte, Vorlagen und Referenzmaterial, die das Modell bei der Arbeit lesen kann. Die Dateien sind schreibgeschützt und werden niemals ausgeführt.

  • Open Source

    Von AnthonyAlcaraz auf GitHub veröffentlicht. Prüfen Sie vor der Installation die Quelldateien.

Installation

Installieren Sie den KI-Skill Rag Mcp Tool Selection in TypingMind, um ihn mit jedem LLM zu nutzen, oder fügen Sie ihn einem anderen Agenten hinzu, der SKILL.md lesen kann.

1

In TypingMind installieren

TypingMind installiert einen Skill direkt aus seinem GitHub-Ordner. Dabei liest die App SKILL.md, bündelt die Ressourcendateien und speichert das Ergebnis lokal.

  1. Öffnen Sie die App und gehen Sie zu Plugins → Skills.
  2. Wählen Sie „Von GitHub installieren“.
  3. Fügen Sie die unten angegebene URL des Skill-Ordners ein und bestätigen Sie.
    https://github.com/AnthonyAlcaraz/agentic-graph-rag-skills/tree/main/skills/tool-orchestration/rag-mcp-tool-selection
  4. Aktivieren Sie den Skill in jedem Chat, in dem er verfügbar sein soll.
Plugins → Skills → Skill hinzufügen → Über GitHub-URL. Fügen Sie dann die Ordner-URL ein und klicken Sie auf „Weiter“.
2

In einem anderen Agenten installieren

Jeder Agent, der das Agent-Skills-Format unterstützt, kann diesen Skill nutzen. Kopieren Sie den Ordner in das Skill-Verzeichnis des jeweiligen Agenten.

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
Starten Sie Claude Code nach dem Kopieren neu, damit der neue Skill erkannt wird.

In TypingMind verwenden

Aktivieren Sie Rag Mcp Tool Selection in einem beliebigen Chat in TypingMind. Den Rest übernimmt das Modell. Name und Beschreibung des Skills stehen im System-Prompt. Sobald eine Anfrage passt, lädt das Modell selbstständig die vollständigen Anweisungen — Sie müssen den Skill nie manuell aufrufen, und er verbraucht erst Token, wenn er tatsächlich genutzt wird.

Das Modell lädt Rag Mcp Tool Selection automatisch, sobald eine passende Anfrage gestellt wird.

Funktioniert mit jedem KI-Modell

KI-Skills bestehen aus reinen Markdown-Anweisungen statt aus anbieterspezifischem Code. Daher ist Rag Mcp Tool Selection nicht an das Modell gebunden, für das der Skill geschrieben wurde. Installieren Sie ihn einmal in TypingMind und nutzen Sie ihn mit GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder einem selbst betriebenen lokalen Modell — alles mit Ihren eigenen API-Schlüsseln.

  • Wird nur bei Bedarf geladen

    Der System-Prompt enthält nur den Namen und die Beschreibung. Die Anweisungen werden bei der ersten passenden Anfrage geladen. Ein ungenutzter Skill verursacht daher keine Kosten.

  • Modell im laufenden Chat wechseln

    Da der Skill aus Anweisungen statt aus Code besteht, funktioniert er auch nach einem Modellwechsel — das nächste Modell liest dieselbe SKILL.md-Datei.

Skill-Anweisungen

Dies ist der Inhalt von SKILL.md, den das Modell lädt. Lesen Sie ihn vor der Installation — ein Skill besteht aus Anweisungen, denen Ihr Modell folgt.

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.

Mitgelieferte Dateien

Das Modell liest diese Dateien bei Bedarf, während der Skill geladen ist. Sie werden als lesbare Dateien bereitgestellt und niemals ausgeführt.

Häufig gestellte Fragen

Was macht der 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.

Warum Rag Mcp Tool Selection in TypingMind nutzen?

Weil Sie den Skill einmal installieren und mit jedem Modell verwenden können. Rag Mcp Tool Selection besteht aus reinem Markdown statt aus anbieterspezifischem Code. So funktioniert derselbe Skill mit GPT-5, Claude, Gemini, Grok oder einem lokalen Modell – und Sie können das Modell mitten im Chat wechseln, ohne dass der Skill seine Funktion verliert. TypingMind verwendet Ihre eigenen API-Schlüssel. Sie bezahlen die Anbieter daher direkt statt über ein Abonnement pro Nutzerplatz, und Ihre Skills und Chats bleiben in Ihrem eigenen Speicher.

Wie installiere ich Rag Mcp Tool Selection in TypingMind?

Öffnen Sie in TypingMind Plugins → Skills → Von GitHub installieren und fügen Sie https://github.com/AnthonyAlcaraz/agentic-graph-rag-skills/tree/main/skills/tool-orchestration/rag-mcp-tool-selection ein. TypingMind liest die Datei SKILL.md, bündelt die zugehörigen Dateien und installiert alles als Skill, den Sie für jeden Chat einzeln aktivieren können.

Welche KI-Modelle können Rag Mcp Tool Selection nutzen?

Jedes Modell, das Sie mit TypingMind verbinden. KI-Skills bestehen aus reinen Markdown-Anweisungen statt aus anbieterspezifischem Code. Daher können GPT, Claude, Gemini, Grok und lokale Modelle diesen Skill laden, wenn eine Anfrage dazu passt.

Wie viele KI-Modelle kann ich mit Rag Mcp Tool Selection verwenden?

So viele Sie möchten. In TypingMind können Sie Rag Mcp Tool Selection mit jedem Modell verwenden, das Skills unterstützt, etwa mit GPT, Claude, Gemini, Grok, DeepSeek, Mistral oder Llama. Dabei nutzen Sie Ihre eigenen API-Schlüssel.

Ist der KI-Skill Rag Mcp Tool Selection kostenlos?

Ja. Der Skill wird von AnthonyAlcaraz auf GitHub unter der Lizenz MIT veröffentlicht. Sie bezahlen nur Ihren eigenen KI-Anbieter für die verwendeten Token.

Was sind KI-Skills?

Ein KI-Skill ist ein wiederverwendbares Anweisungspaket, das einem KI-Modell vermittelt, wie es eine bestimmte Aufgabe erledigt. Es folgt dem offenen Format Agent Skills: Die Datei SKILL.md enthält den Namen und die Beschreibung des Skills. Hinzu kommen bei Bedarf Skripte, Vorlagen oder Referenzdateien für das Modell. Das Modell liest die Anweisungen nur, wenn Ihre Anfrage zum Skill passt. Ein installierter Skill verursacht daher erst Kosten, wenn er verwendet wird.

Wie unterscheiden sich KI-Skills von Plugins oder MCP-Servern?

Ein Plugin oder MCP-Server stellt einem Modell neue aufrufbare Tools bereit – Code, der auf einem System ausgeführt wird und ein Ergebnis zurückgibt. Ein KI-Skill vermittelt dem Modell stattdessen Wissen und Vorgehensweisen: wie es eine Aufgabe angeht, welche Schritte es befolgt und wie eine gute Ausgabe aussieht. Skills bestehen aus reinem Markdown und kommen daher ohne Server, API-Schlüssel und Laufzeitumgebung aus. Sie funktionieren mit jedem Modell.

Alle anzeigen

Jetzt eigenen KI-Arbeitsbereich einrichten

Abonnieren Sie unseren Newsletter und erfahren Sie mehr über neue Funktionen und kommende Gewinnspiele 👇