Custom Tools
Translation in Progress
This page is being translated. Content below is a placeholder.
Creating a Custom Tool
Follow the ServerTool interface:
typescript
const myTool: ServerTool = {
name: 'my_tool',
schema: {
name: 'my_tool',
description: 'What this tool does',
parameters: {
type: 'object',
properties: {
// Define parameters
}
}
},
async execute(params) {
// Implementation
return { result: 'something' }
}
}Example: Git Status Tool
typescript
const gitStatusTool: ServerTool = {
name: 'git_status',
schema: {
name: 'git_status',
description: 'Get the current git status',
parameters: {
type: 'object',
properties: {}
}
},
async execute() {
const { stdout } = await execAsync('git status --porcelain')
const files = stdout.split('\\n').filter(Boolean)
return {
modified: files.filter(f => f.startsWith(' M')),
added: files.filter(f => f.startsWith('A ')),
untracked: files.filter(f => f.startsWith('??'))
}
}
}Best Practices
- Clear descriptions: Help LLM know when to use
- Structured output: Return objects, not raw strings
- Error handling: Always catch and return errors
- Limit output size: Truncate large results
Summary
- Implement ServerTool interface
- Provide clear schema description
- Handle errors gracefully
- Return structured data
Next
Understand the Agent loop: Loop Structure →