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
| Property | Purpose |
|---|---|
name | Unique tool identifier |
schema | JSON Schema definition for LLM |
execute | Actual execution logic |
shouldConfirmExecute | Optional: 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
- Single responsibility: One tool does one thing
- Clear descriptions: Help LLM understand when to use
- Error handling: Return structured errors
- 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 →