What is a Tool?
A tool is a Python class that:- Lives in
server/tools/<widget>_tool.py
- Extends
BaseWidget
- Defines inputs with Pydantic
- Implements widget logic in
execute()
Core Concepts
BaseWidget
BaseWidget
is the abstract base class that all FastApps widgets must inherit from. It handles all the MCP (Model Context Protocol) wiring and widget lifecycle management automatically.
Required Class Attributes
Attribute | Type | Description | Example |
---|---|---|---|
identifier | str | Unique widget identifier. Must match the widget folder name in widgets/ . Used as the resource URI identifier | "greeting" for widgets/greeting/ |
title | str | Human-readable tool name displayed in ChatGPT interface. Shown when the model considers calling this tool | "Show Greeting Widget" |
input_schema | Type[BaseModel] | Pydantic model defining the tool’s input parameters. ChatGPT uses this JSON schema to understand when and how to call your tool | GreetingInput |
invoking | str | Short, localized status message shown to users while the tool is being executed. Maps to openai/toolInvocation/invoking | "Preparing your greeting…" |
invoked | str | Short, localized status message shown to users after the tool completes. Maps to openai/toolInvocation/invoked | "Greeting ready!" |
Optional Class Attributes
Attribute | Type | Description | Example |
---|---|---|---|
description | str | Optional tool description. Helps the model understand when to use this tool | "Display a personalized greeting widget" |
widget_accessible | bool | Whether the widget can initiate tool calls from its React component | True for interactive widgets |
Basic Tool Structure
Common Patterns
Simple Data Display
User Input Collection
Conditional Logic
Input Validation
Use Pydantic models to define and validate inputs:Error Handling
Handle errors gracefully and provide meaningful feedback:Next Steps
- Advanced Patterns - Learn advanced tool patterns
- API Integration - Connect to external APIs
- Back to Server Overview