MCP for Dart
A Dart SDK for building MCP servers and clients.
MCP(Model Context Protocol) for Dart
Model Context Protocol (MCP) is an open protocol designed to enable seamless integration between LLM applications and external data sources and tools.
This library aims to provide a simple and intuitive way to implement MCP servers and clients in Dart, while adhering to the MCP protocol spec. The goal is to make this SDK as similar as possible to the official SDKs available in other languages, ensuring a consistent developer experience across platforms.
Requirements
- Dart SDK version ^3.0.0 or higher
Ensure you have the correct Dart SDK version installed. See https://dart.dev/get-dart for installation instructions.
Features
- Stdio support (Server and Client)
- StreamableHTTP support (Server and Client)
- SSE support (Server only) - Deprecated
- Stream Transport using dart streams (Server and Client in shared process)
- Tools
- Resources
- Prompts
- Sampling
- Roots
Model Context Protocol Version
The current version of the protocol is 2025-03-26. This library is designed to be compatible with this version, and any future updates will be made to ensure continued compatibility.
It's also backward compatible with the previous version 2024-11-05 and 2024-10-07.
Getting started
Below code is the simplest way to start the MCP server.
import 'package:mcp_dart/mcp_dart.dart';
void main() async {
McpServer server = McpServer(
Implementation(name: "mcp-example-server", version: "1.0.0"),
options: ServerOptions(
capabilities: ServerCapabilities(
resources: ServerCapabilitiesResources(),
tools: ServerCapabilitiesTools(),
),
),
);
server.tool(
"calculate",
description: 'Perform basic arithmetic operations',
inputSchemaProperties: {
'operation': {
'type': 'string',
'enum': ['add', 'subtract', 'multiply', 'divide'],
},
'a': {'type': 'number'},
'b': {'type': 'number'},
},
callback: ({args, extra}) async {
final operation = args!['operation'];
final a = args['a'];
final b = args['b'];
return CallToolResult(
content: [
TextContent(
text: switch (operation) {
'add' => 'Result: ${a + b}',
'subtract' => 'Result: ${a - b}',
'multiply' => 'Result: ${a * b}',
'divide' => 'Result: ${a / b}',
_ => throw Exception('Invalid operation'),
},
),
],
);
},
);
server.connect(StdioServerTransport());
}
Usage
Once you compile your MCP server, you can compile the client using the below code.
dart compile exe example/server_stdio.dart -o ./server_stdio
Or just run it with JIT.
dart run example/server_stdio.dart
To configure it with the client (ex, Claude Desktop), you can use the below code.
{
"mcpServers": {
"calculator_jit": {
"command": "path/to/dart",
"args": [
"/path/to/server_stdio.dart"
]
},
"calculator_aot": {
"command": "path/to/compiled/server_stdio",
},
}
}
More examples
https://github.com/leehack/mcp_dart/tree/main/example
Credits
This library is inspired by the following projects:
Related Servers
Scout Monitoring MCP
sponsorPut performance and error data directly in the hands of your AI assistant.
Alpha Vantage MCP Server
sponsorAccess financial market data: realtime & historical stock, ETF, options, forex, crypto, commodities, fundamentals, technical indicators, & more
GemForge (Gemini Tools)
Integrates Google's Gemini for advanced codebase analysis, web search, and processing of text, PDFs, and images.
Windows Command Line MCP Server
Enables AI models to interact with the Windows command-line safely and efficiently.
SeedDream 3.0 FAL
Generate images using Bytedance's SeedDream 3.0 model via the FAL AI platform. Requires a FAL AI API key.
FastAPI MCP Server
A MCP server implementation using the FastAPI framework, configurable via environment variables.
Remote MCP Server (Authless)
An example of a remote MCP server deployable on Cloudflare Workers without authentication.
Command Executor
Execute pre-approved shell commands securely on a server.
OpenRouter MCP Client for Cursor
An MCP client for Cursor that uses OpenRouter.ai to access multiple AI models. Requires an OpenRouter API key.
Snak
An agent engine for creating powerful and secure AI Agents powered by Starknet.
MCP Crash Course
A simple demonstration of the MCP Python SDK.
MCP Shell
Execute secure shell commands from AI assistants and other MCP clients, with configurable security settings.