Skip to main content
Glama
MCP Server RAG

MCP Server RAG

by atengk

rag_query_with_context

Retrieves relevant knowledge-base context and assembles a Markdown prompt with source citations for grounded LLM responses; supports cross-library search, filters, and nearby context expansion.

Instructions

检索知识库相关上下文并组装为带来源引用的 Markdown 增强提示词。

Args:
    kb_name: 目标知识库名称(支持单库名、知识库名称列表或通配符 "*" 跨库检索)
    query: 检索查询问题或主题
    top_k: 返回参考切片的最大数量(默认为 5)
    threshold: 相似度截断阈值,过滤掉低于此分数的切片
    keyword: 可选的精准关键词
    metadata_filter: 可选的元数据字典过滤条件
    expand_context: 邻近上下文窗口扩展步数(默认 0 不展开,允许安全范围 0 ~ 5)

Returns:
    str: 组装后的 Markdown 提示词字符串;若无匹配内容则返回未检索到上下文提示

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "kb_name": "<kb_name>",
      "query": "<query>"
    },
    "name": "rag_query_with_context"
  }
}

Input Schema

NameRequiredDescriptionDefault
queryYes
top_kNo
kb_nameYes
keywordNo
thresholdNo
expand_contextNo
metadata_filterNo

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A3.8/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden and does reasonably well: it discloses the return type (Markdown prompt string), the fallback behavior when nothing matches ("no context retrieved" notice), that wildcard "*" triggers cross-KB search, and that expand_context is bounded to 0-5. It omits any statement about read-only safety, permissions, or result size limits, so it stops short of a 5.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the one-line purpose, then structured into Args and Returns sections, with no filler. It is appropriately sized for a 7-parameter tool, though the Args/Returns layout repeats some schema field names rather than compressing.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 7-parameter retrieval tool with no annotations, the definition covers purpose, every parameter's meaning, and the failure-mode output, which is enough to invoke it correctly. It is slightly redundant in restating the return value, which the output schema already covers, and it lacks guidance about the expected prompt length or citation format.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate, and it mostly does: kb_name's string/list/wildcard forms, top_k default of 5, threshold as a similarity cutoff, expand_context default 0 and safe range, and keyword/metadata_filter as optional. metadata_filter is described only as "optional metadata dictionary filter conditions," with no key format or example given.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description gives a specific verb and resource: it retrieves knowledge-base context and assembles a Markdown enhanced prompt with source citations. That is clearly distinguishable from rag_search or rag_index_* tools in concept, but the description never names a sibling to contrast with, so it falls short of a 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Usage is only implied: the phrase "assembled into an enhanced prompt with source citations" signals that this tool prepares material for an LLM, unlike a raw search. However, it never explicitly states when to choose this over rag_search, and gives no prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.