MCPLogStrategy constructor
MCPLogStrategy({})
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 instanceenableRealTimeStreaming- Enable real-time log streamingenableHealthMonitoring- Enable health monitoringdefaultContext- 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'),
];
}