mcp_dart library

Support for Model Controller Protocol (MCP) SDK for Dart.

This package provides a Dart implementation of the Model Controller Protocol (MCP), which is designed to facilitate communication between clients and servers in a structured and extensible way.

The library exports key modules and types for building MCP-based applications, including server implementations, type definitions, and utilities.

Classes

AbortController
Controls an AbortSignal, allowing the initiator of an operation to signal abortion.
AbortSignal
Represents a signal that can be used to notify downstream consumers that an operation should be aborted.
ArgumentCompletionInfo
Information about the argument being completed.
AudioContent
BaseResultData
Base class for specific MCP result types.
BasicAbortController
BlobResourceContents
Resource contents represented as binary data (Base64 encoded).
CallToolRequestParams
Parameters for the tools/call request.
CallToolResult
Result data for a successful tools/call request.
CancelledNotificationParams
Parameters for the notifications/cancelled notification.
Client
An MCP client implementation built on top of a pluggable Transport.
ClientCapabilities
Capabilities a client may support.
ClientCapabilitiesRoots
Describes capabilities related to root resources (e.g., workspace folders).
ClientOptions
Options for configuring the MCP Client.
CompletableDef
CompletableField
CompleteRequestParams
Parameters for the completion/complete request.
CompleteResult
Result data for a successful completion/complete request.
CompletionResultData
Data structure containing completion results.
Content
Base class for content parts within prompts or tool results.
CreateMessageRequestParams
Parameters for the sampling/createMessage request.
CreateMessageResult
Result data for a successful sampling/createMessage request.
EmbeddedResource
Content embedding a resource.
EmptyResult
A response that indicates success but carries no specific data.
EventStore
Interface for resumability support via event storage
GetPromptRequestParams
Parameters for the prompts/get request.
GetPromptResult
Result data for a successful prompts/get request.
ImageContent
Image content.
Implementation
Describes the name and version of an MCP implementation (client or server).
InitializeRequestParams
Parameters for the initialize request.
InitializeResult
Result data for a successful initialize request.
IOStreamTransport
Transport implementation that uses standard I/O for communication.
JsonRpcCallToolRequest
Request sent from client to invoke a tool provided by the server.
JsonRpcCancelledNotification
Notification sent by either side to indicate cancellation of a request.
JsonRpcCompleteRequest
Request sent from client to ask server for completion options for an argument.
JsonRpcCreateMessageRequest
Request sent from server to client to sample an LLM.
JsonRpcError
Represents a response indicating an error occurred during a request.
JsonRpcErrorData
Represents the error object in a JSON-RPC error response.
JsonRpcGetPromptRequest
Request sent from client to get a specific prompt, potentially with template arguments.
JsonRpcInitializedNotification
Notification sent from the client to the server after initialization is finished.
JsonRpcInitializeRequest
Request sent from client to server upon connection to begin initialization.
JsonRpcListPromptsRequest
Request sent from client to list available prompts and templates.
JsonRpcListResourcesRequest
Request sent from client to list available resources.
JsonRpcListResourceTemplatesRequest
Request sent from client to list available resource templates.
JsonRpcListRootsRequest
Request sent from server to client to get the list of root URIs.
JsonRpcListToolsRequest
Request sent from client to list available tools.
JsonRpcLoggingMessageNotification
Notification of a log message passed from server to client.
JsonRpcMessage
Base class for all JSON-RPC messages (requests, notifications, responses, errors).
JsonRpcNotification
Base class for JSON-RPC notifications which do not expect a response.
JsonRpcPingRequest
A ping request, sent by either side to check liveness. Expects an empty result.
JsonRpcProgressNotification
Out-of-band notification informing the receiver of progress on a request.
JsonRpcPromptListChangedNotification
Notification from server indicating the list of available prompts has changed.
JsonRpcReadResourceRequest
Request sent from client to read a specific resource.
JsonRpcRequest
Base class for JSON-RPC requests that expect a response.
JsonRpcResourceListChangedNotification
Notification from server indicating the list of available resources has changed.
JsonRpcResourceUpdatedNotification
Notification from server indicating a subscribed resource has changed.
JsonRpcResponse
Represents a successful (non-error) response to a request.
JsonRpcRootsListChangedNotification
Notification from client indicating the list of roots has changed.
JsonRpcSetLevelRequest
Request sent from client to enable or adjust logging level from the server.
JsonRpcSubscribeRequest
Request sent from client to subscribe to updates for a resource.
JsonRpcToolListChangedNotification
Notification from server indicating the list of available tools has changed.
JsonRpcUnsubscribeRequest
Request sent from client to cancel a resource subscription.
ListPromptsRequestParams
Parameters for the prompts/list request. Includes pagination.
ListPromptsResult
Result data for a successful prompts/list request.
ListResourcesRequestParams
Parameters for the resources/list request. Includes pagination.
ListResourcesResult
Result data for a successful resources/list request.
ListResourceTemplatesRequestParams
Parameters for the resources/templates/list request. Includes pagination.
ListResourceTemplatesResult
Result data for a successful resources/templates/list request.
ListRootsResult
Result data for a successful roots/list request.
ListToolsRequestParams
Parameters for the tools/list request. Includes pagination.
ListToolsResult
Result data for a successful tools/list request.
LoggingMessageNotificationParams
Parameters for the notifications/message (or logging/message) notification.
McpServer
High-level Model Context Protocol (MCP) server API.
ModelHint
Hints for model selection during sampling.
ModelPreferences
Server's preferences for model selection requested during sampling.
OAuthClientProvider
Represents an OAuth client provider for authentication
OAuthTokens
Represents OAuth tokens
Progress
Represents progress information for a long-running request.
ProgressNotificationParams
Parameters for the notifications/progress notification.
Prompt
A prompt or prompt template offered by the server.
PromptArgument
Describes an argument accepted by a prompt template.
PromptArgumentDefinition
PromptMessage
Describes a message within a prompt structure.
PromptReference
Reference to a prompt or prompt template name.
Protocol
Implements MCP protocol framing on top of a pluggable transport, including features like request/response linking, notifications, and progress.
ProtocolOptions
Additional initialization options for the protocol handler.
ReadResourceRequestParams
Parameters for the resources/read request.
ReadResourceResult
Result data for a successful resources/read request.
Reference
Sealed class representing a reference for autocompletion targets.
RequestHandlerExtra
Extra data given to request handlers when processing an incoming request.
RequestOptions
Options that can be given per request.
Resource
A known resource offered by the server.
ResourceContents
Sealed class representing the contents of a specific resource or sub-resource.
ResourceReference
Reference to a resource or resource template URI.
ResourceTemplate
A template description for resources available on the server.
ResourceTemplateRegistration
ResourceUpdatedNotificationParams
Parameters for the notifications/resources/updated notification.
Root
Represents a root directory or file the server can operate on.
SamplingContent
Represents content parts within sampling messages.
SamplingImageContent
Image content for sampling messages.
SamplingMessage
Describes a message issued to or received from an LLM API during sampling.
SamplingTextContent
Text content for sampling messages.
Server
An MCP server implementation built on top of a pluggable Transport.
ServerCapabilities
Capabilities a server may support.
ServerCapabilitiesPrompts
Describes capabilities related to prompts.
ServerCapabilitiesResources
Describes capabilities related to resources.
ServerCapabilitiesTools
Describes capabilities related to tools.
ServerOptions
Options for configuring the MCP Server.
SetLevelRequestParams
Parameters for the logging/setLevel request.
SseServerManager
Manages Server-Sent Events (SSE) connections and routes HTTP requests.
SseServerTransport
Server transport for SSE: sends messages over a persistent SSE connection (HttpResponse) and receives messages from separate HTTP POST requests handled by handlePostMessage.
StartSseOptions
Options for starting or authenticating an SSE connection
StdioClientTransport
Client transport for stdio: connects to a server by spawning a process and communicating with it over stdin/stdout pipes.
StdioServerParameters
Configuration parameters for launching the stdio server process.
StdioServerTransport
Server transport for stdio: communicates with a MCP client by reading from the current process's standard input (io.stdin) and writing to standard output (io.stdout).
StreamableHttpClientTransport
Client transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification. It will connect to a server using HTTP POST for sending messages and HTTP GET with Server-Sent Events for receiving messages.
StreamableHttpClientTransportOptions
Configuration options for the StreamableHttpClientTransport.
StreamableHttpReconnectionOptions
Configuration options for reconnection behavior of the StreamableHttpClientTransport.
StreamableHTTPServerTransport
Server transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification. It supports both SSE streaming and direct HTTP responses.
StreamableHTTPServerTransportOptions
Configuration options for StreamableHTTPServerTransport
SubscribeRequestParams
Parameters for the resources/subscribe request.
TextContent
Text content.
TextResourceContents
Resource contents represented as text.
Tool
Definition for a tool offered by the server.
ToolAnnotations
Additional properties describing a Tool to clients.
ToolInputSchema
Describes the input schema for a tool, based on JSON Schema.
ToolOutputSchema
Describes the output schema for a tool, based on JSON Schema.
Transport
Describes the minimal contract for a MCP transport that a client or server can communicate over.
UnknownContent
Represents unknown or passthrough content types.
UnknownResourceContents
Represents unknown or passthrough resource content types.
UnsubscribeRequestParams
Parameters for the resources/unsubscribe request.

Enums

ErrorCode
Standard JSON-RPC error codes.
IncludeContext
Context inclusion options for sampling requests.
LoggingLevel
Severity levels for log messages (syslog levels).
PromptMessageRole
Role associated with a prompt message (user or assistant).
SamplingMessageRole
Role in a sampling message exchange.
StopReason
Reasons why LLM sampling might stop.

Constants

defaultRequestTimeout → const Duration
The default request timeout duration.
jsonRpcVersion → const String
JSON-RPC protocol version string.
latestProtocolVersion → const String
The latest version of the Model Context Protocol supported.
supportedProtocolVersions → const List<String>
List of supported Model Context Protocol versions.

Functions

auth(OAuthClientProvider provider, {required Uri serverUrl, String? authorizationCode}) Future<AuthResult>
Performs authentication with the provided OAuth client
generateUUID() String
Generates a RFC4122 compliant UUID (version 4).
mergeCapabilities<T extends Map<String, dynamic>>(T base, T additional) → T
Merges two capability maps (potentially nested).

Typedefs

AuthResult = String
Result of an authentication attempt
CompleteCallback = Future<List<String>> Function(String value)
CompleteResourceTemplateCallback = FutureOr<List<String>> Function(String currentValue)
Cursor = String
An opaque token used to represent a cursor for pagination.
DynamicStopReason = dynamic
Type alias allowing StopReason or a custom String reason.
EventId = String
ID for events in SSE streams
ListResourcesCallback = FutureOr<ListResourcesResult> Function(RequestHandlerExtra extra)
ProgressCallback = void Function(Progress progress)
Callback for progress notifications.
ProgressToken = dynamic
A progress token, used to associate progress notifications with the original request.
PromptCallback = FutureOr<GetPromptResult> Function(Map<String, dynamic>? args, RequestHandlerExtra? extra)
ReadResourceCallback = FutureOr<ReadResourceResult> Function(Uri uri, RequestHandlerExtra extra)
ReadResourceTemplateCallback = FutureOr<ReadResourceResult> Function(Uri uri, TemplateVariables variables, RequestHandlerExtra extra)
RequestId = dynamic
A uniquely identifying ID for a request in JSON-RPC.
ResourceMetadata = ({String? description, String? mimeType})
StreamId = String
ID for SSE streams
ToolCallback = FutureOr<CallToolResult> Function({Map<String, dynamic>? args, RequestHandlerExtra? extra})

Exceptions / Errors

AbortError
Error thrown when an operation is aborted via an AbortSignal.
McpError
Custom error class for MCP specific errors.
StreamableHttpError
Error thrown for Streamable HTTP issues
UnauthorizedError
Represents an unauthorized error