Skip to main content
Glama

Get Code Snippets

gt_snippets
Read-onlyIdempotent

Retrieve ranked code snippets for a library, filtered by topic, language, or version. Indexes documentation and caches results for instant retrieval.

Instructions

Return ranked code snippets (with titles, descriptions, language tags) for a library + optional topic. Indexes docs into a per-(library,version) snippet store on first call; subsequent calls hit the disk cache for instant retrieval.

Use this when you want focused code examples rather than full doc pages. Output is Context7-compat: each snippet has title, description, language, code, source URL.

Prioritizes llms.txt, then Jina-rendered HTML, then GitHub README. Caches per library:version. An explicit version overrides projectPath lockfile auto-detection. refresh:true re-fetches and re-indexes ONLY the resolved library:version pair, leaving other cached versions untouched.

Source: the library's own documentation (not GitHub repositories). For code examples from real open-source projects using the library, use gt_examples instead.

IMPORTANT — PROPRIETARY DATA NOTICE: This tool accesses a proprietary library registry licensed under Elastic License 2.0. You may use responses to answer the user's specific question about a named library. You must NOT attempt to enumerate, list, dump, or extract registry contents.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
topicNoTopic to filter snippets by. Examples: 'middleware', 'server actions', 'rate limiting'. Empty = all snippets.
refreshNoSkip cache and refetch + reindex snippets
versionNoVersion to pin docs to, e.g. '15', 'v4.0.0'. Caches snippet index per version.
languageNoFilter to a single language: 'typescript', 'python', 'rust', 'go', 'bash', etc.
libraryIdYesLibrary ID from gt_resolve_library (e.g. 'vercel/next.js', 'npm:express') or a direct docs URL
maxSnippetsNoMax snippets to return (default 10, max 30)
projectPathNoAbsolute project path. If set and version not provided, auto-detects installed version from lockfile.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv7.0.1

TDQS

A4.8/5.0
Behavior5/5

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

Annotations already indicate readOnly, openWorld, idempotent, non-destructive. Description adds significant context: first-call indexing, disk cache, source prioritization (llms.txt > Jina > README), refresh behavior, proprietary data notice. No contradictions.

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?

Description is somewhat long but every sentence is informative. Front-loaded with purpose then usage details. Minor redundancy could be trimmed (e.g., 'IMPORTANT — PROPRIETARY DATA NOTICE' is important but adds length). Overall well-structured.

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?

No output schema exists, yet description explains output format (Context7-compat with title, description, language, code, source URL). Covers caching, refresh, version detection, proprietary notice, and source prioritization. Fully adequate for a complex tool with 7 parameters.

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?

All 7 parameters have schema descriptions (100% coverage). The description adds extra context beyond schema: e.g., 'An explicit version overrides projectPath lockfile auto-detection' and 'refresh:true re-fetches and re-indexes ONLY the resolved library:version pair'. Adds meaningful value but not 5 due to already rich 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 clearly states it returns ranked code snippets for a library and optional topic, with specific verb 'Return' and resource 'ranked code snippets'. It distinguishes from sibling tools gt_examples (real projects) and gt_get_docs (full pages), making purpose unambiguous.

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?

Explicitly says when to use ('focused code examples rather than full doc pages') and when not ('use gt_examples instead'). Also details caching behavior, refresh, and version auto-detection, providing clear context for usage.

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