Skip to main content
Glama

Fetch Source Code Snippets by Line Range

fetch_code_snippets
Read-onlyIdempotent

Reads exact source code line ranges from workspace files for graph nodes or file coordinates, returning YAML snippets and per-item errors without failing the batch.

Instructions

Read exact source code line ranges from workspace files on disk for a batch of graph nodes or file coordinates passed as a YAML list. Use when inspecting implementation bodies of symbols discovered via find_symbol, get_callers, or execute_custom_read_cypher; to view a file's structural symbol list without reading source text use get_file_outline. Resolves each item's file_path relative to workspacePath, clamps start_line..end_line to valid file bounds (recording per-item errors if a file is missing without failing the batch), and returns YAML snippets in input order.

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": {
      "nodes": "<nodes>"
    },
    "name": "fetch_code_snippets"
  }
}

Input Schema

NameRequiredDescriptionDefault
nodesYesRequired YAML list of snippet request objects, each specifying 'file_path' (workspace-relative or absolute path), 'start_line' (1-based inclusive start line), and 'end_line' (1-based inclusive end line).
workspacePathNoOptional absolute path to the target workspace root directory. Omit to use the bound workspace, active client root, or sticky session workspace.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changedv1.85.1
    • changedInput schema / properties / nodes / description
      Previous value: -"YAML list of node objects with file_path, start_line, end_line."New value: +"Required YAML list of snippet request objects, each specifying 'file_path' (workspace-relative or absolute path), 'start_line' (1-based inclusive start line), and 'end_line' (1-based inclusive end line)."
    • changedInput schema / properties / workspacePath / description
      Previous value: -"Optional workspace root path."New value: +"Optional absolute path to the target workspace root directory. Omit to use the bound workspace, active client root, or sticky session workspace."
  2. First observedv1.80.5

TDQS

A4.8/5.0
Behavior5/5

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

Annotations already declare readOnly/idempotent/non-destructive, and the description adds behavior beyond them: paths are resolved relative to workspacePath, line ranges are clamped to valid file bounds, missing files produce per-item errors rather than failing the batch, and results come back in input order. This is exactly the operational detail an agent needs before issuing a multi-item read.

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?

Three sentences, front-loaded with purpose then usage then behavior, and nothing is filler. The first sentence is heavily packed with clauses, which slightly slows parsing but does not cost information.

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

Completeness5/5

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

Despite having only two parameters and no output schema, the description covers input format, path resolution, boundary handling, partial-failure semantics, and return ordering/format. Nothing an agent needs to call this correctly is missing.

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 100%, so the baseline is 3, but the description adds meaning the schema does not: resolution of file_path against workspacePath and the clamping of start_line..end_line. It does not spell out how clamping is reported or what a per-item error looks like, keeping it just short of a 5.

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?

States a specific verb and resource ('Read exact source code line ranges from workspace files on disk') plus the input shape (batch of graph nodes or file coordinates as a YAML list). It also explicitly distinguishes itself from the sibling get_file_outline by scope of output.

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

Usage Guidelines5/5

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

Gives an explicit when-to-use trigger ('inspecting implementation bodies of symbols discovered via find_symbol, get_callers, or execute_custom_read_cypher') and names the alternative for the adjacent need ('to view a file's structural symbol list without reading source text use get_file_outline'). The selection boundary between the two tools is unambiguous.

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