Skip to content

Tool Interface Design

Translation in Progress

This page is being translated. Content below is a placeholder.

gemini-cli Tool Interface

typescript
interface ServerTool {
  name: string
  schema: FunctionDeclaration
  execute(params: unknown, signal?: AbortSignal): Promise<ToolResult>
  shouldConfirmExecute?(params: unknown): Promise<ConfirmDetails | false>
}

Interface Breakdown

PropertyPurpose
nameUnique tool identifier
schemaJSON Schema definition for LLM
executeActual execution logic
shouldConfirmExecuteOptional: check if user confirmation needed

Example Implementation

typescript
const readFileTool: ServerTool = {
  name: 'read_file',

  schema: {
    name: 'read_file',
    description: 'Read file contents',
    parameters: {
      type: 'object',
      properties: {
        path: { type: 'string' }
      },
      required: ['path']
    }
  },

  async execute({ path }) {
    const content = await fs.readFile(path, 'utf-8')
    return { content }
  },

  // No confirmation needed for read operations
  async shouldConfirmExecute() {
    return false
  }
}

Design Principles

  1. Single responsibility: One tool does one thing
  2. Clear descriptions: Help LLM understand when to use
  3. Error handling: Return structured errors
  4. Abort support: Allow cancellation of long-running operations

Summary

  • ServerTool interface unifies all tools
  • Schema tells LLM how to call the tool
  • Execute contains actual implementation

Next

See built-in tool implementations: Built-in Tools →

Learn AI Agent development through real source code