mcp_host library
Kernel sub-barrel for the reference MCP host adapters.
Hosts that want a mcp_server + mcp_client backed surface import
this barrel in addition to package:brain_kernel/brain_kernel.dart.
The main barrel exposes only the KernelServerHost /
KernelClientHost abstracts; this barrel surfaces the reference
impls (ServerBootstrap aka McpServerKernelHost,
McpClientKernelHost) plus the raw mcp_server / mcp_client
types so hosts can reach out to wire-shape APIs (custom prompts,
resource subscriptions, OAuth, etc).
Usage:
import 'package:brain_kernel/brain_kernel.dart';
import 'package:brain_kernel/mcp_host.dart';
final app = await KernelApp.boot(
workspaceId: 'studio',
kvStorage: kv,
serverHostFactory: ServerBootstrap.factory, // MCP server-backed
clientHost: McpClientKernelHost(), // outbound calls
);
Hosts that never expose a server transport omit serverHostFactory
(kernel falls back to in-process). Hosts that never make outbound
calls omit clientHost.
Classes
- ApiKeyValidator
- Simple API key validator
- AudioContent
- Audio content (spec 2025-03-26+).
- AuthContext
- Authorization context for MCP requests
- AuthMiddleware
- Authentication middleware for HTTP requests
- AuthResult
- Authentication result
- CachedResource
- Cached resource item for performance optimization
- CallToolResult
- Tool call result.
- CancellationToken
- Cancellation token for async operations
- Client
- Main MCP Client class that handles all client-side protocol operations
- ClientSession
- Client session information
- CompletionsCapability
-
Completions capability — server advertises support for argument
autocompletion via the
completion/completerequest (spec). - Content
- Base class for all MCP content types (2025-03-26 compliant)
- CreateMessageRequest
- Create message request for sampling
- CreateMessageResult
- Create message result from sampling
- DeprecationInfo
- Deprecation information
- ErrorCode
- Error codes for standardized error handling
- EventMessage
- Event message with optional ID for SSE
-
Failure<
T, E extends Object> - Represents a failed result
- GetPromptResult
- Get prompt result
- ImageContent
- Image content representation
- 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.
- Logger
- Use a Logger to log debug messages.
- LoggingCapability
- Logging capability
- LogRecord
- A log entry representation used to propagate information from Logger to individual handlers.
- McpClientKernelHost
- McpErrorCodes
- MCP Error codes as defined in the specification
- McpMethodAuth
- MCP method authorization configuration
- McpMethods
- Standard MCP methods that must be implemented
- McpProtocol
- MCP Protocol Version constants and definitions
- McpServer
- Modern MCP Server factory with enhanced configuration and error handling
- McpServerConfig
- Configuration for creating MCP servers
- Message
- Message model for prompt system
- ModelHint
- Model hint for sampling
- ModelPreferences
- Model preferences for sampling
- OAuthTokenValidator
- OAuth 2.1 token validator
- PendingOperation
- Pending operation for cancellation support
- ProgressCapability
- Progress capability
- ProgressNotification
- Progress notification data (2025-03-26)
- Prompt
- Prompt definition
- PromptArgument
- Prompt argument definition
- PromptMessage
- Prompt message (2025-03-26)
- PromptsCapability
- Prompts capability
- ReadResourceResult
- Resource read result
- Resource
- Resource definition
- ResourceContent
- Resource content representation
- ResourceContentInfo
- Resource content info (used in ReadResourceResult)
- ResourceLinkContent
- Resource link content (spec 2025-06-18+) — a tool result that points to a server resource by URI without inlining the content.
- ResourcesCapability
- Resources capability
- ResourceTemplate
- Resource template definition
- ResourceUsage
- Resource usage indicators
-
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
- RootsCapability
- Roots capability
- SamplingCapability
- Sampling capability
- Server
- Main MCP Server class that handles all server-side protocol operations
- ServerBootstrap
- ServerCapabilities
- Server capabilities configuration for MCP 2025-03-26 protocol
- ServerHealth
- Server health information
- ServerInterface
- Interface for server to expose key functionality for testing
- ServerTransport
- Abstract base class for server transport implementations
- SseClientTransport
- Transport implementation using Server-Sent Events (SSE) over HTTP
- SseServerTransport
- Transport implementation using Server-Sent Events (SSE) over HTTP
- SseStreamInfo
- SSE stream information for request-specific streams
- SseTransportConfig
- StdioClientTransport
- Transport implementation using standard input/output streams
- StdioServerTransport
- Transport implementation using standard input/output streams
- StdioTransportConfig
- StreamableHttpClientTransport
- Streamable HTTP client transport for MCP
- StreamableHttpServerConfig
- Configuration for StreamableHTTP server transport
- StreamableHttpServerTransport
- MCP 2025-03-26 StreamableHTTP Server Transport Implementation Supports both JSON responses and SSE streaming according to MCP standard
- StreamableHttpTransportConfig
-
Success<
T, E extends Object> - Represents a successful result
- TextContent
- Text content representation
- TokenValidator
- Token validation interface
- Tool
- Tool definition (2025-03-26 compliant)
- ToolAnnotationBuilder
- Tool annotation builder for creating standard annotations
- ToolAnnotationKeys
- Standard tool annotation keys defined in MCP 2025-03-26
- ToolAnnotationPresets
- Common tool annotation presets
- ToolAnnotationUtils
- Utility functions for working with tool annotations
- ToolsCapability
- Tools capability
- TransportConfig
- Configuration for transport connections
Enums
- MCPContentType
- McpLogLevel
- Log levels for MCP protocol
- MessageRole
- Base content type enum for MCP
- PromptMessageRole
- Prompt message roles
- ToolPriority
- Tool priority levels
Extensions
-
FutureResultExtensions
on Future<
Result< T, E> > -
Extension methods for
Future<Result> - LoggerExtensions on Logger
- OAuthServerMethods on Server
Constants
- defaultLevel → const Level
- The default Level.
- getStreamKey → const String
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
Typedefs
-
CompletionHandler
= Future<
Map< Function(Map<String, dynamic> >String, dynamic> ref, Map<String, dynamic> argument, Map<String, dynamic> ? context) -
Type definition for completion handler functions (spec
completion/complete). - IsCancelledCheck = bool Function()
- Callback type for checking if operation is cancelled
- MCPServer = McpServer
- ProgressCallback = void Function(double progress, String message)
- Callback type for tool execution progress updates
-
PromptHandler
= Future Function(Map<
String, dynamic> arguments) - Type definition for prompt handler functions
-
ResourceHandler
= Future Function(String uri, Map<
String, dynamic> params) - Type definition for resource handler functions
- SseServerConfig = SseTransportConfig
-
ToolHandler
= Future Function(Map<
String, dynamic> arguments) - Type definition for tool handler functions with cancellation and progress reporting
Exceptions / Errors
- CancelledException
- Exception thrown when an operation is cancelled
- McpError
- Error class for MCP-related errors