Tool class

Annotation that describes an MCP tool.

Apply this annotation to methods that should be exposed as tools in the generated MCP server. Each tool becomes callable by MCP clients.

The name parameter allows specifying a custom tool name. If not provided, the method name is used. This is useful for avoiding naming collisions when multiple classes have methods with the same name, or for creating more descriptive tool names.

The description provides a human-readable explanation of what the tool does. If not provided, the generator will use the method's dartdoc comment.

The icons parameter allows specifying icon URLs for UI clients that display available tools.

The annotations parameter provides behavioral hints to MCP clients, such as whether the tool is read-only, destructive, or idempotent.

Example:

@Tool(
  name: 'user_create',
  description: 'Creates a new user in the system',
  icons: ['https://example.com/user-icon.png'],
  annotations: ToolAnnotations(
    destructiveHint: false,
    idempotentHint: false,
    openWorldHint: false,
  ),
)
Future<User> createUser({required String name, required String email}) async {
  // Implementation
}
Annotations
  • @immutable

Constructors

Tool({String? name, String? description, List<String>? icons, ToolAnnotations? annotations, bool codeMode = true, bool codeModeVisible = false})
Creates a Tool annotation.
const

Properties

annotations ToolAnnotations?
Optional behavioral annotations for this tool.
final
codeMode bool
Whether this tool should be available in code mode.
final
codeModeVisible bool
Whether this tool should remain visible in the standard tools/list response when the parent Server annotation has codeMode: true.
final
description String?
Optional text describing what this tool does.
final
hashCode int
The hash code for this object.
no setterinherited
icons List<String>?
Optional list of icon URLs for this tool.
final
name String?
Optional custom name for this tool.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited