Skip to content

leehack/mcp_dart

Repository files navigation

MCP (Model Context Protocol) for Dart

Coverage Pub Version likes

The Model Context Protocol (MCP) is a standardized protocol for communication between AI applications and external services. It enables:

  • Tools: Allow AI to execute actions (API calls, computations, etc.)
  • Resources: Provide context and data to AI (files, databases, APIs)
  • Prompts: Pre-built prompt templates with arguments

Understanding MCP: Client, Server, and Host

MCP follows a client-server architecture with three key components:

  • MCP Host: The AI application that provides the user interface and manages connections to multiple MCP servers.

    • Example: Claude Desktop, IDEs like VS Code, custom AI applications
    • Manages server lifecycle, discovers capabilities, and orchestrates interactions
  • MCP Client: The protocol implementation within the host that communicates with servers.

    • Handles protocol negotiation, capability discovery, and request/response flow
    • Typically built into or used by the MCP host
  • MCP Server: Provides capabilities (tools, resources, prompts) that AI can use through the host.

    • Example: Servers for file system access, database queries, or API integrations
    • Runs as a separate process and communicates via standardized transports (stdio, StreamableHTTP)

Typical Flow: User ↔ MCP Host (with Client) ↔ MCP Protocol ↔ Your Server ↔ External Services/Data

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.

Installation

Add to your pubspec.yaml:

dependencies:
  mcp_dart: ^2.1.1

Then install dependencies:

dart pub get

What This SDK Provides

This SDK lets you build both MCP servers and clients in Dart/Flutter.

  • Build MCP Servers - Create servers that expose tools, resources, and prompts to AI hosts
  • Build MCP Clients - Create AI applications that can connect to and use MCP servers
  • Full MCP Protocol Support - Complete MCP specification 2025-11-25 implementation
  • Multiple Transport Options - Stdio, StreamableHTTP, IOStream, or custom transports
  • All Capabilities - Tools, Resources, Prompts, Sampling, Roots, Completions, Elicitation, Tasks
  • Extension Support - Generic extensions negotiation with typed MCP Apps helpers and TypeScript-style registerAppTool / registerAppResource
  • Latest Content/Metadata Types - resource_link, themed icons, and annotations.lastModified
  • OAuth Authentication Hooks - OAuthClientProvider, server authenticators, and OAuth2/PKCE examples
  • Transport Security Controls - DNS rebinding protection and strict Streamable HTTP validation with compatibility toggles
  • Type-Safe - Comprehensive type definitions with null safety
  • Cross-Platform - Works on Linux, Windows, macOS, Web, and Flutter

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.

Choosing between mcp_dart and the Dart team dart_mcp package

The Dart ecosystem now has more than one MCP package. The Dart team-maintained dart_mcp package lives in dart-lang/ai and is a good place to look when you specifically want the Dart team's implementation.

mcp_dart is a community SDK focused on production-oriented MCP servers and clients for Dart and Flutter applications. It is designed for teams that need broad protocol coverage, multiple transports, security controls, and tooling around real deployments.

Package Best fit Notes
dart_mcp Projects that prefer the Dart team-maintained package or want to follow the Dart team's evolving MCP APIs closely. Check the package docs and changelog for its current feature set and stability guarantees.
mcp_dart Production-focused Dart/Flutter MCP servers, clients, and hosts that need broad transport, auth, security, and tooling support today. Includes StreamableHTTP, OAuthClientProvider and server authenticator hooks with OAuth2/PKCE examples, MCP Apps helpers, strict transport security controls, CLI tooling, and compatibility with MCP protocol version 2025-11-25.

Use this comparison as a starting point, not a permanent verdict: both packages can evolve quickly. If you compare them for a production decision, re-check the current pub.dev releases and docs first.

Model Context Protocol Version

The current version of the protocol is 2025-11-25. 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 previous versions including 2025-06-18, 2025-03-26, 2024-11-05, and 2024-10-07.

Documentation

Getting Started

Core Concepts

Advanced Features

Quick Start with CLI

The fastest way to create an MCP server is using the mcp_dart_cli:

# Install the CLI
dart pub global activate mcp_dart_cli

# Create a new project
mcp_dart create my_server

# Navigate and run
cd my_server
mcp_dart serve

Your server is now running! Use mcp_dart inspect to test it:

mcp_dart inspect              # List all capabilities
mcp_dart inspect --tool add --json-args '{"a": 1, "b": 2}'   # Call a tool

CLI Commands

Command Description
create Scaffold a new MCP server project
serve Run your server (stdio or HTTP)
doctor Check project health and connectivity
inspect Test and debug server capabilities

📖 Full CLI Documentation

Connecting to AI Hosts

Configure your server with AI hosts like Claude Desktop:

{
  "mcpServers": {
    "my_server": {
      "command": "mcp_dart",
      "args": ["serve"],
      "cwd": "/path/to/my_server"
    }
  }
}

Tip

For manual server implementation or advanced use cases, see the Server Guide.

Authentication

This library provides OAuth-aware client and server authentication hooks, including OAuthClientProvider for StreamableHTTP clients and server-side authenticator callbacks. For OAuth2/PKCE guides and examples, see the OAuth Authentication documentation.

Platform Support

Platform Stdio StreamableHTTP IOStream Custom
Desktop (CLI/Server)
Web (Browser)
Flutter (Mobile/Desktop)

Custom Transports: You can implement your own transport layer by extending the transport interfaces if you need specific communication patterns not covered by the built-in options.

More Examples

For additional examples including authentication, HTTP clients, and advanced features:

Community & Support

Credits

This library is inspired by the following projects:

About

Dart implementation of MCP SDK

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

 
 
 

Contributors