Basic Usage
Signature
Type Safety
The@Tool decorator provides compile-time type checking:
- Input validation: The
execute()parameter type must exactly match theinputSchema. Mismatches produce a descriptive error at compile time. - Output validation: When
outputSchemais provided, theexecute()return type must be assignable to the inferred output type. - Context check: The decorated class must extend
ToolContext. Using@Toolon a plain class produces a compile error. - Invalid options: Typos in decorator options (e.g.,
concurrency: { maxConcurrensst: 5 }) are caught at compile time with specific error messages, without losing autocomplete on other fields.
Configuration Options
Required Properties
| Property | Type | Description |
|---|---|---|
name | string | Unique tool identifier |
inputSchema | ZodShape | Zod object shape for input validation |
Optional Properties
| Property | Type | Description |
|---|---|---|
description | string | Tool description for AI |
outputSchema | ZodType | Output validation schema |
id | string | Stable identifier for tracking |
tags | string[] | Categorization tags |
visibility | 'public' | 'hidden' | 'internal' | Discovery visibility. hidden hides from public lists; internal keeps it for in-process callers only |
rateLimit | RateLimitConfig | Per-tool rate limit (maxRequests, windowMs, partitionBy) |
concurrency | ConcurrencyConfig | Per-tool concurrency cap (maxConcurrent, optional queue config) |
timeout | TimeoutConfig | Per-tool execution timeout (executeMs) |
availableWhen | EntryAvailability | Restrict discovery to specific platforms/runtimes/deployments. See Environment Awareness |
execution | { taskSupport?: 'required' | 'optional' | 'forbidden' } | MCP 2025-11-25 task-execution mode for tools/list items |
authProviders | ToolAuthProviderRef[] | Required auth providers for this tool (string name or { name, required?, scopes?, alias? }) |
annotations | ToolAnnotations | MCP hints (title, readOnlyHint, destructiveHint, idempotentHint, openWorldHint) |
examples | ToolExample[] | Usage examples (description, input, optional output) |
ui | ToolUIConfig | UI widget configuration (template, csp, sanitization options) |
hideFromDiscovery | boolean | Deprecated alias for visibility: 'hidden' |
Output Types
Authorization
Annotations
Examples
UI Configuration
Theui.template field accepts a builder function, an HTML/MDX string, a React component, or a FileSource (for client-side transpilation):
ToolUIConfig shape (CSP, sanitization, helpers, etc.).
Function-Based Alternative
For simpler tools, use thetool() function:
Context Methods
TheToolContext base class provides:
Dependency Injection
Notifications
Elicitation (Interactive Input)
Platform Detection
Authentication
HTTP Requests
Error Handling
Type Inference
FrontMCP provides helper types for extracting input/output types:Full Example
Related
ToolContext
Context class details
ToolRegistry
Tool registry API
Tool Errors
Tool-related errors
@Resource
Define resources