Labsco
leehack logo

MCP for Dart

โ˜… 110

from leehack

A Dart SDK for building MCP servers and clients.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeQuick setup

MCP (Model Context Protocol) for Dart

mcp_dart is a Dart and Flutter SDK for building Model Context Protocol (MCP) servers, clients, and AI host integrations. Use it to expose Dart tools over stdio or Streamable HTTP, connect Flutter apps to MCP servers, and validate real deployments with the companion CLI.

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

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, Resource.size, Root._meta, and annotations.lastModified
  • โœ… OAuth Authentication Hooks - OAuthClientProvider, MCP OAuth discovery helpers, 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.

PackageBest fitNotes
dart_mcpProjects 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_dartProduction-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

Recipes and Compatibility

Advanced Features

Authentication

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

Platform Support

PlatformStdioStreamableHTTPIOStreamCustom
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: