Mcp class
Annotation to mark a class, library, or method for MCP exposure.
Use this annotation to configure how the MCP server will be generated for the annotated element. The generator uses these settings to create the appropriate server transport and behavior.
The transport parameter determines whether the server uses stdio (for CLI integration) or HTTP (for network access).
The generateJson parameter controls whether the generator should also produce a JSON metadata file alongside the Dart code.
The port parameter specifies the port number for HTTP transport. Only used when transport is McpTransport.http. Defaults to 3000.
The address parameter specifies the bind address for HTTP transport. Only used when transport is McpTransport.http. Defaults to 'localhost'. Use '0.0.0.0' to listen on all interfaces.
The toolPrefix parameter adds a prefix to all tool names in this scope. Useful for organizing tools by domain or avoiding naming collisions when aggregating tools from multiple files.
Example:
@Mcp(transport: McpTransport.stdio)
@Tool(description: 'Create users')
Future<bool> createUsers(List<User> users) async { ... }
Example with HTTP transport:
@Mcp(transport: McpTransport.http, port: 8080, address: '0.0.0.0')
@Tool(description: 'Create users')
Future<bool> createUsers(List<User> users) async { ... }
Example with tool prefix:
@Mcp(transport: McpTransport.stdio, toolPrefix: 'user_service_')
class UserService {
@Tool(description: 'Create user')
Future<User> createUser() async { ... } // Tool name: user_service_createUser
}
Example with auto class prefix:
@Mcp(transport: McpTransport.stdio, autoClassPrefix: true)
class UserService {
@Tool(description: 'Create user')
Future<User> createUser() async { ... } // Tool name: UserService_createUser
}
Constructors
Properties
- address → String
-
The bind address for HTTP transport.
final
- autoClassPrefix → bool
-
Whether to automatically prefix tool names with their class name.
final
- generateJson → bool
-
Whether to generate a JSON metadata file in addition to Dart code.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- port → int
-
The port number for HTTP transport.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- toolPrefix → String?
-
Optional prefix for all tool names in this scope.
final
- transport → McpTransport
-
The transport protocol used by the generated MCP server.
final
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