MCPLogStrategy class

MCP Log Strategy for Strategic Logger

⚠️ SECURITY WARNING: This strategy starts an HTTP server that exposes logs. NOT recommended for production mobile/web apps without proper authentication.

This strategy integrates with the Model Context Protocol (MCP) server to provide AI agents with structured logging capabilities.

Security Considerations:

  • HTTP server exposes logs without authentication by default
  • Should only be used in development or with proper security measures
  • Not recommended for Flutter mobile apps in production
  • Consider using only in local development environments

Features:

  • Structured logging for AI consumption
  • Real-time log streaming
  • Query capabilities for log analysis
  • Health monitoring through logs

Example (Development only):

// Only use in development!
MCPLogStrategy(
  enableInMobile: false, // Disabled by default for security
  apiKey: 'your-secret-key', // Required for production
)
Inheritance

Constructors

MCPLogStrategy({MCPServer? mcpServer, bool enableInMobile = false, String? apiKey, bool enableRealTimeStreaming = true, bool enableHealthMonitoring = true, Map<String, dynamic>? defaultContext})
Constructs an MCPLogStrategy.

Properties

hashCode int
The hash code for this object.
no setterinherited
loggerLogLevel LogLevel
The log level set by the logger using this strategy. Used to determine if a message should be logged.
getter/setter pairinherited
logLevel LogLevel
The minimum log level that this strategy handles for logging.
getter/setter pairinherited
mcpServer MCPServer
MCP Server instance for testing
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
supportedEvents List<LogEvent>?
A list of specific LogEvent types that this strategy supports. If null, all events are considered supported.
getter/setter pairinherited

Methods

buildContext(Map<String, dynamic>? additionalContext, StackTrace? stackTrace) Map<String, dynamic>
Build context for testing
dispose() → void
error(LogEntry entry) Future<void>
Logs an error.
override
fatal(LogEntry entry) Future<void>
Logs a fatal error.
override
formatMessage(dynamic message) String
Format message for testing
generateLogId() String
Generate log ID for testing
getHealthStatus() Future<Map<String, dynamic>>
Gets health status from the MCP server
info(LogEntry entry) Future<void>
Logs an info message or event.
override
log(LogEntry entry) Future<void>
Logs a message or event.
override
logError(dynamic error, StackTrace? stackTrace, LogEvent? event, Map<String, dynamic>? context) Future<void>
Legacy method for logging errors (for backward compatibility).
inherited
logMessage(dynamic message, LogEvent? event, Map<String, dynamic>? context) Future<void>
Legacy method for logging messages (for backward compatibility).
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
queryLogs({LogLevel? level, DateTime? since, DateTime? until, String? message, Map<String, String>? context, String? sortBy, int? limit}) Future<List<MCPLogEntry>>
Queries logs from the MCP server
shouldLog({LogEvent? event}) bool
Determines whether a log operation should proceed based on the event and log level.
inherited
startServer() Future<void>
Starts the MCP server if not already running
stopServer() Future<void>
Stops the MCP server
toString() String
Provides a string representation of the strategy including its type and log level.
override

Operators

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