Skip to main content
Glama

expand_context_tool

Fetches the previous and next chunks for a search result to restore surrounding context and improve retrieval accuracy.

Instructions

擴展 Chunk 上下文(Small-to-Big Retrieval)

search_knowledge 命中某個 chunk 後,用此工具取得 該 chunk 的「前一段」與「後一段」完整內容, 補充搜尋結果的上下文脈絡。

Args: chunk_id: 搜尋結果 context.chunk_id parent_id: 搜尋結果 context.parent_id

Returns: { "before": {id, header_path, content, preview} | null, "current": {id, header_path, content, preview}, "after": {id, header_path, content, preview} | null }

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": {
      "chunk_id": "<chunk_id>",
      "parent_id": "<parent_id>"
    },
    "name": "expand_context_tool"
  }
}

Input Schema

NameRequiredDescriptionDefault
chunk_idYes
parent_idYes

Output Schema

NameRequiredDescriptionDefault

No arguments

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.2601.5

TDQS

A4.2/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 it does disclose the key behavior: this is a read-only supplementary lookup that returns neighboring segments, with before/after nullable at boundaries. It does not discuss failure modes such as an invalid or stale chunk_id/parent_id, which would be valuable for a retrieval tool with no annotation coverage.

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

Conciseness3/5

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

The purpose statement is front-loaded and efficient, but nearly half the text restates the return object shape even though an output schema already exists and makes that block largely redundant. The Args block earns its place; the Returns block does not.

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 simple two-parameter read tool with an output schema, the description supplies purpose, workflow trigger, and parameter sourcing, which is close to enough to call it correctly. The remaining gap is error/boundary behavior, which the description only hints at via the nullable before/after fields.

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 coverage is 0%, so the description must compensate, and it does: it tells the agent that chunk_id comes from the search result's context.chunk_id and parent_id from context.parent_id, which is exactly the information missing from the bare schema. It does not explain what parent_id represents or how the two ids must relate, leaving some ambiguity.

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

Purpose5/5

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

The description names a specific action (expanding a chunk's context) and the exact resource involved, and it positions the tool in the retrieval workflow: after search_knowledge hits a chunk, retrieve that chunk's previous and next sections. That 'Small-to-Big Retrieval' framing plus the before/current/after neighbors distinguishes it clearly from sibling tools like search_knowledge_tool or read_knowledge_tool.

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

Usage Guidelines4/5

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

It gives a concrete trigger condition — use it only after search_knowledge_tool returns a hit — which is genuinely actionable sequencing guidance. It stops short of stating when not to use it (e.g. that it is unnecessary when the chunk alone suffices) or what happens if the chunk is at a boundary, so it is clear but not exhaustive.

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