MCPLogStrategy constructor

MCPLogStrategy({
  1. MCPServer? mcpServer,
  2. bool enableInMobile = false,
  3. String? apiKey,
  4. bool enableRealTimeStreaming = true,
  5. bool enableHealthMonitoring = true,
  6. Map<String, dynamic>? defaultContext,
})

Constructs an MCPLogStrategy.

⚠️ SECURITY WARNING: This strategy starts an HTTP server.

  • enableInMobile - Set to true to enable in mobile (default: false for security)
  • apiKey - Optional API key for authentication (recommended for production)
  • mcpServer - Custom MCP server instance
  • enableRealTimeStreaming - Enable real-time log streaming
  • enableHealthMonitoring - Enable health monitoring
  • defaultContext - Default context to add to all logs

Implementation

MCPLogStrategy({
  MCPServer? mcpServer,
  bool enableInMobile = false,
  String? apiKey,
  bool enableRealTimeStreaming = true,
  bool enableHealthMonitoring = true,
  Map<String, dynamic>? defaultContext,
}) : _mcpServer = mcpServer ?? MCPServer.instance,
     _enableInMobile = enableInMobile,
     _apiKey = apiKey,
     _enableRealTimeStreaming = enableRealTimeStreaming,
     _enableHealthMonitoring = enableHealthMonitoring,
     _defaultContext = defaultContext ?? {} {
  // Security check: Warn if trying to use in mobile/web without explicit enable
  if (!_enableInMobile && (kIsWeb || Platform.isAndroid || Platform.isIOS)) {
    developer.log(
      '⚠️ MCP Server is disabled by default in mobile/web for security. '
      'Set enableInMobile: true only if you understand the risks. '
      'MCP Server exposes logs via HTTP without authentication by default.',
      name: 'MCPLogStrategy',
    );
    // Don't throw error, just log warning - strategy will work but server won't start
  }

  logLevel = LogLevel.info;
  loggerLogLevel = LogLevel.info;
  supportedEvents = [
    LogEvent(eventName: 'mcp_log', eventMessage: 'MCP structured log entry'),
  ];
}