Tool Development
Build tools for SpoonOS agents using BaseTool and FastMCP.
Tool Types
| Type |
Use Case |
BaseTool |
Local Python tools |
MCPTool |
External MCP servers |
FastMCP |
Build MCP servers |
Quick Start
from spoon_ai.tools.base import BaseTool
from pydantic import Field
class MyTool(BaseTool):
name: str = "my_tool"
description: str = "Tool description"
parameters: dict = Field(default={
"type": "object",
"properties": {
"param": {"type": "string"}
},
"required": ["param"]
})
async def execute(self, param: str) -> str:
return f"Result: {param}"
Scripts
References
ToolManager Methods
| Method |
Description |
add_tool(tool) |
Add single tool |
remove_tool(name) |
Remove by name |
execute(name, input) |
Execute tool |
to_params() |
Get OpenAI specs |
Best Practices
- Use async for all I/O operations
- Return ToolResult/ToolFailure
- Validate inputs before execution
- Implement proper error handling
- Use environment variables for secrets