Skip to main content

Understanding Tool Definitions

Tool definitions are JSON schemas that specify the functions and capabilities available to AI coding assistants. They define what actions an assistant can take and how to invoke them.

What is a Tool Definition?

A tool definition is a structured JSON object that describes:
  • Name: The identifier used to invoke the tool
  • Description: What the tool does and when to use it
  • Parameters: Input schema with types and validation rules
  • Examples: Usage patterns and best practices

Basic Structure

Here’s a typical tool definition structure:
{
  "name": "read_file",
  "description": "Reads a file from the local filesystem.",
  "parameters": {
    "type": "object",
    "properties": {
      "target_file": {
        "type": "string",
        "description": "The path of the file to read"
      },
      "offset": {
        "type": "integer",
        "description": "Line number to start reading from"
      },
      "limit": {
        "type": "integer",
        "description": "Number of lines to read"
      }
    },
    "required": ["target_file"]
  }
}

Common Tool Categories

Tools for reading, writing, and manipulating files:
{
  "name": "Read",
  "description": "Reads a file from the local filesystem",
  "parameters": {
    "properties": {
      "file_path": {
        "type": "string",
        "description": "Absolute path to the file"
      },
      "offset": {"type": "number"},
      "limit": {"type": "number"}
    },
    "required": ["file_path"]
  }
}
Key features:
  • Absolute path requirements
  • Optional pagination (offset/limit)
  • Line number formatting
Tools for finding and understanding code:
{
  "name": "codebase_search",
  "description": "Semantic search that finds code by meaning",
  "parameters": {
    "properties": {
      "query": {
        "type": "string",
        "description": "Natural language question"
      },
      "target_directories": {
        "type": "array",
        "items": {"type": "string"},
        "description": "Directories to search"
      }
    },
    "required": ["query"]
  }
}
Capabilities:
  • Semantic understanding
  • Directory scoping
  • Context-aware results
Tools for running commands:
{
  "name": "run_terminal_cmd",
  "description": "Execute shell commands",
  "parameters": {
    "properties": {
      "command": {"type": "string"},
      "is_background": {"type": "boolean"},
      "explanation": {"type": "string"}
    },
    "required": ["command", "is_background"]
  }
}
Features:
  • Background execution support
  • Working directory context
  • Output capture and streaming
Tools for modifying files:
{
  "name": "edit_file",
  "description": "Edit existing files with precise replacements",
  "parameters": {
    "properties": {
      "target_file": {"type": "string"},
      "old_string": {"type": "string"},
      "new_string": {"type": "string"}
    },
    "required": ["target_file", "old_string", "new_string"]
  }
}

Real-World Examples

Cursor Agent Tools

Claude Code Tools

{
  "name": "Edit",
  "description": "Performs exact string replacements in files",
  "parameters": {
    "properties": {
      "file_path": {"type": "string"},
      "old_string": {"type": "string"},
      "new_string": {"type": "string"},
      "replace_all": {"type": "boolean", "default": false}
    },
    "required": ["file_path", "old_string", "new_string"]
  }
}
Key Features:
  • Must read file before editing
  • Exact string matching required
  • Optional replace_all for multiple instances
  • Preserves exact indentation

Advanced Features

Validation and Constraints

{
  "parameters": {
    "properties": {
      "todos": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "content": {"type": "string", "minLength": 1},
            "status": {
              "type": "string",
              "enum": ["pending", "in_progress", "completed"]
            }
          },
          "required": ["content", "status"]
        },
        "minItems": 2
      }
    }
  }
}

Conditional Parameters

{
  "description": "Read file with optional pagination",
  "parameters": {
    "properties": {
      "should_read_entire_file": {"type": "boolean"},
      "start_line": {
        "type": "integer",
        "description": "Required if should_read_entire_file is false"
      }
    }
  }
}

Tool Description Best Practices

Effective tool descriptions include:

When to Use

Clear guidelines on appropriate use cases
Use codebase_search when you need to:
- Explore unfamiliar codebases
- Find code by meaning rather than text

When NOT to Use

Explicit anti-patterns
Skip codebase_search for:
- Exact text matches (use grep)
- Reading known files (use read_file)

Usage Examples

Concrete examples with explanations
Query: "Where is MyInterface implemented?"
Good: Specific question with context

Technical Details

Important constraints and behaviors
- Output capped at 50 matches
- Results sorted by modification time
- Respects .gitignore rules

Parameter Patterns

Explanation Parameters

Many tools require brief explanations:
{
  "explanation": {
    "type": "string",
    "description": "One sentence explaining why this tool is being used"
  }
}
This helps with:
  • Debugging tool usage
  • Understanding agent reasoning
  • Audit trails

Path Specifications

{
  "file_path": {
    "type": "string",
    "description": "The absolute path to the file (must be absolute, not relative)"
  }
}
Common requirements:
  • Always absolute paths
  • No relative paths like ../file.txt
  • Platform-specific separators

Schema Validation

Tool schemas often use JSON Schema draft-07 or later:
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {...},
  "required": [...],
  "additionalProperties": false
}
The additionalProperties: false constraint means the AI cannot pass unexpected parameters, helping catch errors early.

Comparing Tool Approaches

AspectCursorClaude CodeAugment
Edit StyleSketch-based with // ... existing code ...Exact string replacementString replacement with line numbers
SearchSemantic + grep + file searchGrep + glob + Task agentCodebase retrieval + git history
ExecutionTerminal commands with background supportBash with working directoryProcess management with terminals
File OpsRead with paginationRead with offset/limitView with regex search
Tool definitions evolve based on usage patterns and user feedback. Always refer to the latest schema for accurate implementation details.

Build docs developers (and LLMs) love