Skip to main content
Glama

Prune In-Memory Code Snippet to AST Signatures

prune_code_snippet
Read-onlyIdempotent

Strips implementation bodies from in-memory code, schemas, or diffs while preserving signatures, types, and docstrings 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.

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": {
      "code": "<code>"
    },
    "name": "prune_code_snippet"
  }
}

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.4/5.0
Behavior4/5

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

Annotations already cover readOnly, idempotent, destructive, and openWorld, so the restated 'Read-only' and 'Idempotent' bullets add no new information. However the description contributes genuinely new behavioral context beyond annotations: the specific supported languages/parsers, sub-10ms latency, zero auth, and especially the graceful regex fallback on malformed syntax. That error-handling disclosure is the kind of trait an agent cannot get from structured fields.

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?

Well organized with front-loaded verb statement followed by labeled Parameters/Behavior/Usage Guidelines/Returns sections, so an agent can scan it quickly. It loses a point for duplicating the schema's parameter text verbatim and restating annotation-covered traits (read-only, idempotent) in a separate Behavior block.

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?

For a three-parameter in-memory transform, the definition covers selection guidance, parser/language support, degradation behavior, and cost profile. An output schema exists, so the brief Returns line is a bonus rather than a requirement; nothing needed to call it correctly is missing.

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% and all three parameter blurbs in the description are near-verbatim copies of the schema descriptions, so little meaning is added beyond structured data. Baseline 3 applies since the schema already carries the full parameter documentation.

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 (prune) and resource (implementation bodies from in-memory snippets/schemas/diffs) plus what is preserved (AST interfaces, signatures, type annotations). It explicitly names build_project_context and audit_code_quality as the tools it is not, so an agent can discriminate it from siblings without opening a 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?

Has explicit 'When to use' (compress code strings, SQL, diff patches before embedding in prompts, with a quantified 80-95% token savings) and 'When NOT to use' sections that route to the correct alternative tool for each excluded case. Nothing about tool selection is left to inference.

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