McpEvents class

Public entry point for the mcpe2e system.

Exposes system operations as a simple API without requiring the caller to know about the Registry, Simulator, or Executor internally.

Typical usage in the app:

// 1. Register widgets before mounting them
McpEvents.instance.registerWidget(const McpMetadataKey(
  id: 'auth.login_button',
  widgetType: McpWidgetType.button,
  description: 'Main login button',
  screen: 'LoginScreen',
));

// 2. Use the key in the widget
ElevatedButton(
  key: McpEvents.instance.getGlobalKey('auth.login_button'),
  onPressed: _handleLogin,
  child: const Text('Sign in'),
)

// 3. Start the server (in main() or in a debug initState)
if (kDebugMode) await McpEventServer.start();

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

executeEvent({required String widgetKey, required McpEventType eventType, McpEventParams? params}) Future<bool>
Executes the eventType on the widget identified by widgetKey.
getAllWidgetIds() List<String>
Lists the IDs of all registered widgets.
getAllWidgets() List<McpMetadataKey>
Lists the metadata of all registered widgets.
getContext(String id) BuildContext?
Returns the BuildContext of the widget if it is mounted.
getGlobalKey(String id) GlobalKey<State<StatefulWidget>>?
Returns the GlobalKey to assign to the widget in the tree.
getWidgetMetadata(String id) McpMetadataKey?
Returns the registered metadata for a widget.
isRegistered(String id) bool
Returns true if the widget with id is registered.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerWidget(McpMetadataKey key) → void
Registers a testable widget and creates its internal GlobalKey.
toJson({String? screen, String? route}) Map<String, dynamic>
Generates the context JSON consumed by the external MCP server.
toString() String
A string representation of this object.
inherited
unregisterWidget(String id) → void
Removes a widget from the registry.

Operators

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

Static Properties

instance McpEvents
final