mcp_client library
Kernel sub-barrel for outbound MCP client usage.
mcp_client is exposed through a dedicated entry point (rather than
the main brain_kernel.dart barrel) because its model classes
— Content / TextContent / ImageContent / CallToolResult /
transport configs — collide pervasively with mcp_server's
same-named classes. Rolling them into the main barrel forces every
domain consumer to disambiguate. Splitting the surfaces keeps the
main barrel clean for the typical builder usage (server-side MCP +
bundle + LLM) while still letting tools that genuinely need
outbound clients (inspector probes, cross-server wiring) reach the
types through the kernel.
Usage:
import 'package:brain_kernel/mcp_client.dart';
final result = await McpClient.createAndConnect(
config: const McpClientConfig(...),
);
if (result.content.first is TextContent) { ... }
Domain code that imports both brain_kernel.dart (for the
server / bundle types) and this file should use a prefix on one of
them to silence the expected collisions on Content / etc.
Classes
- AudioContent
- Audio content (spec 2025-03-26+).
- AuthenticatedEventSource
- Authenticated EventSource implementation
- AuthServerMetadata
- Authorization server metadata (RFC8414)
- CachedResource
- Cached resource item for performance optimization
- CallToolRequest
- Call tool request
- CallToolResult
-
Tool call result. Spec 2025-06-18 added
structuredContent(paired withTool.outputSchema). - CancelRequestNotification
- Cancel request notification
- Client
- Main MCP Client class that handles all client-side protocol operations
- ClientCapabilities
- Client capabilities configuration
- ClientInfo
- Client information (2025-03-26 compliant)
- ClientTransport
- Abstract base class for client transport implementations
- CompletionRequest
- Completion request
- CompletionResult
- Completion result
- CompressedEventSource
- Compressed EventSource implementation
- Connected
- The connection is established and ready
- Connecting
- The connection is in the process of connecting
- ConnectionError
- The connection has failed with an error
- ConnectionState
- Represents the various states of an MCP connection
- Content
- Base class for all MCP content types (2025-03-26 compliant)
- CreateMessageRequest
- Create message request for sampling
- CreateMessageResult
- Create message result from sampling
- Disconnected
- The connection is disconnected
- Disconnecting
- The connection is in the process of disconnecting
-
Failure<
T, E extends Object> - Represents a failed result
- GetPromptRequest
- Get prompt request
- GetPromptResult
- Get prompt result
- HeartbeatConfig
- Heartbeat configuration
- HeartbeatEventSource
- Heartbeat-enabled EventSource implementation
- HeartbeatStats
- Heartbeat statistics
- HttpOAuthClient
- HTTP-based OAuth 2.1 client implementation
- ImageContent
- Image content representation
- InitializeRequest
- Initialize request
- InitializeResult
- Initialize result
- JsonRpcMessage
- JSON-RPC message
- Level
- Levels to control logging output. Logging can be enabled to include all levels above certain Level. Levels are ordered using an integer value Level.value. The predefined Level constants below are sorted as follows (in descending order): Level.SHOUT, Level.SEVERE, Level.WARNING, Level.INFO, Level.CONFIG, Level.FINE, Level.FINER, Level.FINEST, and Level.ALL.
- ListPromptsResult
- List prompts result
- ListResourcesResult
- List resources result
- ListToolsResult
- List tools result
- Logger
- Use a Logger to log debug messages.
- LogMessageNotification
- Log message notification
- LogRecord
- A log entry representation used to propagate information from Logger to individual handlers.
- McpClient
- Modern MCP Client factory with enhanced error handling and configuration
- McpClientConfig
- Configuration for creating MCP clients
- McpProtocol
- MCP protocol versions and constants
- Message
- Message model for prompt system
- ModelHint
- Model hint for sampling
- ModelPreferences
- Model preferences for sampling
- OAuthClient
- OAuth client interface
- OAuthConfig
- OAuth 2.1 authentication configuration
- OAuthError
- OAuth error response
- OAuthToken
- OAuth 2.1 token response
- OAuthTokenManager
- OAuth token manager with automatic refresh
- PendingOperation
- Pending operation for cancellation support
- ProgressNotification
- Progress notification
- ProgressUpdate
- Progress update for long-running operations
- Prompt
- Prompt definition
- PromptArgument
- Prompt argument definition
- PromptsListChangedNotification
- Prompts list changed notification
- ProtocolCapabilities
- Protocol capabilities
- ReadResourceRequest
- Read resource request
- ReadResourceResult
- Resource read result
- Resource
- Resource definition
- ResourceContent
- Resource content representation
- ResourceContentInfo
- Resource content
- ResourceLinkContent
- Resource link content (spec 2025-06-18+).
- ResourcesListChangedNotification
- Resources list changed notification
- ResourceTemplate
- Resource template definition
- ResourceUpdatedNotification
- Resource updated notification
-
Result<
T, E extends Object> - A sealed class representing the result of an operation that can succeed or fail
- Results
- Utility functions for working with Results
- Root
- Root definition for filesystem access
- Semaphore
- Semaphore for controlling concurrent requests
- ServerCapabilities
- Server capabilities
- ServerHealth
- Server health information
- ServerInfo
- Server information (2025-03-26 compliant)
- SseAuthClientTransport
- SSE Transport with Bearer Token Authentication
- SseClientTransport
- Transport implementation using Server-Sent Events (SSE) over HTTP
- SseCompressedClientTransport
- SSE Transport with automatic compression support
- SseHeartbeatClientTransport
- SSE Transport with heartbeat monitoring
- SseTransportConfig
- StdioClientTransport
- Transport implementation using standard input/output streams
- StdioTransportConfig
- StreamableHttpClientTransport
- Streamable HTTP client transport for MCP
- StreamableHttpTransportConfig
-
Success<
T, E extends Object> - Represents a successful result
- TextContent
- Text content representation
- TokenLifecycleEvent
- Token lifecycle event.
- Tool
-
Tool definition. Spec 2025-06-18+ added
outputSchema,_meta, and thetitledisplay name (separate from programmaticname). Spec 2025-11-25+ addedicons. - ToolCallTracking
- Class to hold result of a tracked tool call
- ToolMetadata
- Lightweight tool metadata (name + description only) Used for token-efficient LLM context in deferred loading mode
- ToolRegistry
- Cache layer for tool definitions Provides metadata extraction and full schema lookup LLM-agnostic: can be used without mcp_llm
- ToolsListChangedNotification
- Tools list changed notification
- TransportConfig
- Configuration for transport connections
Enums
- CompressionType
- Compression types supported
- ConnectionHealth
- Connection health status
- DisconnectReason
- Reason for disconnection
- MCPContentType
- McpLogLevel
- Log levels for MCP protocol
- MessageRole
- Base content type enum for MCP
- OAuthGrantType
- OAuth 2.1 grant types supported by MCP
- TokenEventType
- Token lifecycle event types.
Extensions
- ClientToolMetadataExtension on Client
- Extension on Client for easy metadata access in deferred loading mode
-
FutureResultExtensions
on Future<
Result< T, E> > -
Extension methods for
Future<Result> - LoggerExtensions on Logger
Constants
- defaultLevel → const Level
- The default Level.
Properties
- hierarchicalLoggingEnabled ↔ bool
-
Whether to allow fine-grain logging and configuration of loggers in a
hierarchy.
getter/setter pair
- recordStackTraceAtLevel ↔ Level
-
Automatically record stack traces for any message of this level or above.
getter/setter pair
Exceptions / Errors
- McpError
- Error class for MCP-related errors