Skip to main content
Glama

get_source

Get the exact source body of a C/C++ symbol using its qualified name, with precise line numbers and metadata from libclang's AST.

Instructions

Read a C/C++ function/method/enum/macro body using libclang exact extents — no guessing line numbers. Uses AST-precise {start, end} extents so you get exactly the function body. Generic file readers don't know where a function actually ends — libclang tracks exact {start, end} from the AST.

For enums, includes a constants array listing all member constants with their values. For macros, returns kind="macro" with value (raw definition) and expanded_value (preprocessor-resolved).

For rich context (who calls this, what does it call) use get_symbol_context instead — it returns body, callers, and callees in a single call. For the full file, use a normal file read.

Read-only. No side effects.

Args: name: Fully qualified symbol name. Returns exact function body via libclang extent. project_root: Project root. Auto-detected if omitted.

Returns: dict: {name, qualified_name, kind, file, line, signature, docstring, is_definition, is_template, is_virtual, is_pure_virtual, source (str — the function/enum/macro body, truncated at 8000 chars), warning (str, optional — when source file cannot be read)}. May also include template_usr, parent_usr, enum_value, constants (list for enums), value (raw macro definition), expanded_value (preprocessor-resolved macro value) when applicable.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesFully qualified symbol name. Returns exact function body via libclang extent.
imageNoSysbuild image name within the variant (multi-project). Omit for all images of the variant.
variantNoBuild variant name (multi-project). Omit to use default_variant or fail-closed. Use '*' for all variants.
project_rootNoProject root. Auto-detected if omitted.
Behavior4/5

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

No annotations are provided, so the description carries the full burden. It discloses read-only/no side effects, truncation at 8000 chars, optional warning when source file cannot be read, and exact AST-based extents. A minor gap is that it doesn't specify behavior if the symbol is not found.

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 longer than strictly necessary but well-structured: clear purpose first, then why it's better, usage alternatives, read-only note, and finally Args and Returns sections. It is front-loaded and each section adds value, though there is mild redundancy between 'exact extents' and 'AST-precise extents'.

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?

Given the absence of an output schema, the description thoroughly explains return values, including optional fields for enums, macros, template_usr, etc. It also covers edge cases like truncation and warnings. The image/variant parameters are not explained in prose, but the schema covers them, so the overall context is sufficient for correct usage.

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

Parameters3/5

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

The input schema already documents all four parameters with 100% description coverage. The description repeats the semantics for name and project_root but adds no new information beyond the schema; image and variant are not mentioned in the description but are adequately described in the schema.

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 opens with a specific verb and resource: 'Read a C/C++ function/method/enum/macro body using libclang exact extents'. It explicitly distinguishes itself from generic file readers and refers to alternative tools (get_symbol_context and normal file read), so it clearly differentiates from siblings.

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?

The description gives explicit usage guidance: 'For rich context... use get_symbol_context instead' and 'For the full file, use a normal file read.' It also states 'Read-only. No side effects,' which helps an agent decide when it is safe to call.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/turbyho/fw-context-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server