Skip to main content
Glama

prune_code_snippet

Read-onlyIdempotent

Compress in-memory code snippets, schemas, or diffs by stripping implementation bodies while preserving AST signatures and types to reduce LLM prompt tokens.

Instructions

Prunes implementation bodies from in-memory code snippets, API schemas, or unified diff streams while preserving AST interfaces, type annotations, and function signatures, distinguishing from 'build_project_context' and 'audit_code_quality' by stripping function bodies in memory rather than scanning repository file trees or auditing code quality.

Parameters:

  • code (str, required): Raw source code, schema definition (JSON/YAML), or unified diff text to compress.

  • file_name_or_lang (str, optional, default='snippet.py'): File name or language extension (e.g. 'service.ts', '.go', '.rs', 'schema.json') to select appropriate AST parser.

  • reduction_mode (str, optional, default='ultra'): AST reduction level: 'ultra' for signatures only, 'balanced' for signatures + control structures, 'micro_patch' for surgical unified diff pruning.

Behavior:

  • Read-only: Processes in-memory text buffers without touching disk files.

  • Idempotent: Deterministic AST reduction for identical code inputs.

  • 100% Offline: Local AST and regex parsers for Python, TypeScript, Go, Rust, Java, C#, C++, SQL, JSON, YAML.

  • Auth & Rate Limits: Zero authentication or credentials required; execution latency <10ms.

  • Error Handling: Gracefully falls back to regex line pruning if parser encounters malformed syntax.

Usage Guidelines:

  • When to use: Compress raw code strings, function definitions, SQL queries, or diff patches before embedding them in an LLM prompt to achieve 80-95% token savings.

  • When NOT to use: Do not use for scanning full repository files or building hierarchical project context from disk (use 'build_project_context' instead); do not use for detecting code duplication across modules (use 'audit_code_quality' instead).

Returns: Compact code snippet retaining only structural signatures, interfaces, and docstrings.

Input Schema

NameRequiredDescriptionDefault
codeYesRaw source code, schema definition (JSON/YAML), or unified diff text to compress.
reduction_modeNoAST reduction level: 'ultra' for signatures only, 'balanced' for signatures + control structures, 'micro_patch' for surgical unified diff pruning.ultra
file_name_or_langNoFile name or language extension (e.g. 'service.ts', '.go', '.rs', 'schema.json') to select appropriate AST parser.snippet.py

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed6 schema fields changedv7.3.2
    • changedInput schema / properties / code / description
      Previous value: -"Raw source code content to prune."New value: +"Raw source code, schema definition (JSON/YAML), or unified diff text to compress."
    • addedInput schema / properties / file_name_or_lang
      Added value: +{
      +  "default": "snippet.py",
      +  "description": "File name or language extension (e.g. 'service.ts', '.go', '.rs', 'schema.json') to select appropriate AST parser.",
      +  "title": "File Name Or Lang",
      +  "type": "string"
      +}
    • removedInput schema / properties / file_path_or_ext
      Removed value: -{
      -  "default": "snippet.py",
      -  "description": "File name or extension (e.g. 'service.ts', 'main.go', 'app.py', '.rs', '.java', '.cs', '.kt', '.swift') indicating language parser.",
      -  "title": "File Path Or Ext",
      -  "type": "string"
      -}
    • changedInput schema / properties / reduction_mode / description
      Previous value: -"Reduction tier: 'ultra' for AST signatures only (80-95% reduction), 'balanced' for signatures + control flow."New value: +"AST reduction level: 'ultra' for signatures only, 'balanced' for signatures + control structures, 'micro_patch' for surgical unified diff pruning."
    • changedInput schema / title
      Previous value: -"_legacy_prune_code_snippetArguments"New value: +"prune_code_snippetArguments"
    • changedOutput schema / title
      Previous value: -"_legacy_prune_code_snippetOutput"New value: +"prune_code_snippetOutput"
  2. Changed6 schema fields changedv7.0.1
    • changedInput schema / properties / code / description
      Previous value: -"Raw source code, schema definition (JSON/YAML), or unified diff text to compress."New value: +"Raw source code content to prune."
    • removedInput schema / properties / file_name_or_lang
      Removed value: -{
      -  "default": "snippet.py",
      -  "description": "File name or language extension (e.g. 'service.ts', '.go', '.rs', 'schema.json') to select appropriate AST parser.",
      -  "title": "File Name Or Lang",
      -  "type": "string"
      -}
    • addedInput schema / properties / file_path_or_ext
      Added value: +{
      +  "default": "snippet.py",
      +  "description": "File name or extension (e.g. 'service.ts', 'main.go', 'app.py', '.rs', '.java', '.cs', '.kt', '.swift') indicating language parser.",
      +  "title": "File Path Or Ext",
      +  "type": "string"
      +}
    • changedInput schema / properties / reduction_mode / description
      Previous value: -"AST reduction level: 'ultra' for signatures only, 'balanced' for signatures + control structures, 'micro_patch' for surgical unified diff pruning."New value: +"Reduction tier: 'ultra' for AST signatures only (80-95% reduction), 'balanced' for signatures + control flow."
    • changedInput schema / title
      Previous value: -"prune_code_snippetArguments"New value: +"_legacy_prune_code_snippetArguments"
    • changedOutput schema / title
      Previous value: -"prune_code_snippetOutput"New value: +"_legacy_prune_code_snippetOutput"
  3. Changed4 schema fields changedv7.0.0
    • changedInput schema / properties / code / description
      Previous value: -"Raw source code content to prune."New value: +"Raw source code, schema definition (JSON/YAML), or unified diff text to compress."
    • addedInput schema / properties / file_name_or_lang
      Added value: +{
      +  "default": "snippet.py",
      +  "description": "File name or language extension (e.g. 'service.ts', '.go', '.rs', 'schema.json') to select appropriate AST parser.",
      +  "title": "File Name Or Lang",
      +  "type": "string"
      +}
    • removedInput schema / properties / file_path_or_ext
      Removed value: -{
      -  "default": "snippet.py",
      -  "description": "File name or extension (e.g. 'service.ts', 'main.go', 'app.py', '.rs', '.java', '.cs', '.kt', '.swift') indicating language parser.",
      -  "title": "File Path Or Ext",
      -  "type": "string"
      -}
    • changedInput schema / properties / reduction_mode / description
      Previous value: -"Reduction tier: 'ultra' for AST signatures only (80-95% reduction), 'balanced' for signatures + control flow."New value: +"AST reduction level: 'ultra' for signatures only, 'balanced' for signatures + control structures, 'micro_patch' for surgical unified diff pruning."
  4. Changed3 schema fields changedv0.1.1
    • addedInput schema / properties / code / description
      Added value: +"Raw source code content to prune."
    • addedInput schema / properties / file_path_or_ext / description
      Added value: +"File name or extension (e.g. 'service.ts', 'main.go', 'app.py', '.rs', '.java', '.cs', '.kt', '.swift') indicating language parser."
    • addedInput schema / properties / reduction_mode / description
      Added value: +"Reduction tier: 'ultra' for AST signatures only (80-95% reduction), 'balanced' for signatures + control flow."
  5. First observedv0.1.0

TDQS

A4.2/5.0
Behavior4/5

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

Annotations already declare readOnly/idempotent/non-destructive/closed-world, and the description partly repeats those (Read-only, Idempotent, 100% Offline). It earns credit for genuinely new behavior: zero-auth requirement, <10ms latency, supported language list, and graceful regex fallback on malformed syntax — the fallback being the most decision-relevant detail an agent cannot get from annotations.

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?

Content is well-sectioned (Parameters / Behavior / Usage / Returns), but the opening sentence is a single cramped run-on that front-loads sibling differentiation awkwardly. Several lines (Read-only, Idempotent) restate annotations and the 'Returns' line duplicates the output schema, so not every sentence earns its place.

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 3-parameter transform tool, everything needed to invoke it correctly is present: input kinds, parser selection, reduction levels, fallback behavior. The explicit 'Returns' section is redundant given an output schema exists, and mode-selection guidance for mixed inputs is thin.

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?

Schema coverage is 100%, so the baseline is 3. The description's parameter entries are near-verbatim copies of the schema descriptions and add no format, constraint, or interaction detail beyond them (e.g. no guidance on how reduction_mode interacts with file_name_or_lang for diff inputs).

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+resource (prune implementation bodies from code snippets/schemas/diffs) plus the invariant it preserves (AST interfaces, signatures). It explicitly contrasts with 'build_project_context' and 'audit_code_quality', so an agent can separate it from siblings without opening any schema.

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?

Provides an explicit 'When to use' (compress code strings/diffs before LLM embedding for 80-95% token savings) and a 'When NOT to use' that names both alternative tools and the conditions selecting them. Both positive and negative routing are covered.

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