A Dart package for making MCP servers and clients.
Note: This package is still experimental and is likely to evolve quickly.
To implement a server, import package:dart_mcp/server.dart and extend the MCPServer class. You must provide the server a communication channel to send and receive messages with.
For each specific MCP capability or utility your server supports, there is a corresponding mixin that you can use (ToolsSupport, ResourcesSupport, etc).
Each mixin has doc comments explaining how to use it - some may require you to provide implementations of methods, while others may just expose new methods that you can call.
See the server example for some example code.
All client capabilities are exposed as methods on the MCPServer class.
Before attempting to call these methods, you must first wait for the MCPServer.initialized future and then check the capabilities of the client by reading the MCPServer.clientCapabilities.
Alternatively, if your server requires certain capabilities from the client for all operations, you may override the MCPServer.initialize function and return an error, which may result in a better UX for the users of the client.
To implement a client, import package:dart_mcp/client.dart and extend the MCPClient class, or directly call its constructor with a ClientImplementation if you aren't implementing any “capabilities”.
For each specific MCP capability your client supports, there is a corresponding mixin that you can use (RootsSupport, SamplingSupport, etc). Each mixin has doc comments explaining how to use it - some may require you to provide implementations of methods, while others may just expose new methods that you can call.
You can connect this client with STDIO servers using the MCPClient.connectStdioServer method, or you can call MCPClient.connectServer with any other communication channel.
The returned ServerConnection should be used for all interactions with the server, starting with a call to ServerConnection.initialize, followed up with a call to ServerConnection.notifyInitialized (if initialization was successful). If a version could not be negotiated or a server does not support required features, the server connection should be closed (by calling ServerConnection.shutdown).
See initialization lifecycle for information about the client/server initialization protocol.
All server capabilities and utilities are exposed as methods or streams on the ServerConnection class.
Before attempting to call methods on the server however, you should first verify the capabilities of the server by reading them from the InitializeResult returned from ServerConnection.initialize.
If support for a given protocol version is dropped, that will be released as a breaking change in this package.
However, we will strive to maintain backwards compatibility where possible.
This table describes the state of implementation for the base protocol utilities.
Both the MCPServer and MCPClient support these.
| Utility | Support | Notes |
|---|---|---|
| Ping | :heavy_check_mark: | |
| Cancellation | :x: | https://github.com/dart-lang/ai/issues/37 |
| Progress | :heavy_check_mark: |
This table describes the supported transport mechanisms.
At its core this package is just built on streams, so any transport mechanism can be used, but some are directly supported out of the box.
| Transport | Support | Notes |
|---|---|---|
| Stdio | :heavy_check_mark: | |
| Streamable HTTP | :x: | Unsupported at this time, may come in the future. |
Both the client and server support processing batch requests, but do not support creating batch requests at this time.
Authorization is not supported at this time. This package is primarily targeted at local MCP server usage for now.
This table describes the state of implementation for the server capabilities.
Note: Servers can also invoke all client capabilities, see Invoking Client Capabilities.
| Capability | Support | Notes |
|---|---|---|
| Prompts | :heavy_check_mark: | |
| Resources | :heavy_check_mark: | |
| Tools | :heavy_check_mark: |
This table describes the state of implementation for the server utilities.
| Utility | Support | Notes |
|---|---|---|
| Completion | :heavy_check_mark: | |
| Logging | :heavy_check_mark: | |
| Pagination | :construction: | https://github.com/dart-lang/ai/issues/28 |
This table describes the state of implementation for the client capabilities.
Note: Clients can also invoke all server capabilities and server utilities, see Invoking Server Capabilities and Utilities.
| Capability | Support | Notes |
|---|---|---|
| Roots | :heavy_check_mark: | |
| Sampling | :heavy_check_mark: |