mcp_dart 包是 Model Context Protocol (MCP) SDK 的 Dart 实现,可在 Flutter 应用中无缝集成上下文感知的 AI 模型。它通过定义管理模型上下文、提示和响应的标准协议,促进客户端与大语言模型(LLM)之间的结构化通信。专为开发 AI 驱动的应用程序的开发者设计,支持在 Android、iOS、Web、macOS、Windows 和 Linux 上跨平台部署。该包简化了动态上下文数据的处理,提升了提示的准确性,并降低了生成工作流中的延迟。
适合场景
集成AI聊天界面
增强LLM提示管理
构建上下文感知的助手
启用实时AI响应
支持多模型工作流
主要特点
跨平台兼容性
标准化上下文协议
高效的提示处理
实时上下文同步
轻量化且模块化设计
适合对象
使用 LLM 的 Flutter 开发人员
AI 应用构建器
全栈开发人员集成人工智能
需要跨平台保持一致AI行为的团队
需要结构化AI上下文的项目
使用建议
需要了解MCP标准
依赖于兼容的LLM后端
可能需要为自定义模型集成进行额外设置
最适合具有明确AI上下文需求的项目
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
MCP (Model Context Protocol) for Dart
mcp_dart is a dual-era Dart and Flutter SDK for MCP clients, servers, and AI
hosts. It implements the complete core client/server wire surface of the locked
MCP 2026-07-28 specification, retains the MCP 2025-11-25 feature set, and
negotiates supported earlier initialization-based specifications.
Here, core means the normative wire requirements assigned to client and server
roles by the pinned final specification. It excludes optional MCP
extensions, host UI behavior, an authorization-server implementation, JSON
Schema external-reference resolution, and custom JSON Schema vocabularies.
[!IMPORTANT]
This release is mcp_dart 2.4.2. The separately versioned stable CLI remains
mcp_dart_cli 0.2.1, which requires mcp_dart ^2.4.2.
Current source passes every scored requirement in the official alpha.11 MCP
2025-11-25 and 2026-07-28 client and server sets, including all 25
required 2026 authorization scenarios, plus bidirectional published
TypeScript SDK 2.0.0 and Python SDK 2.1.1 interoperability.
SDK Tier 1 target
The project is pursuing
MCP SDK Tier 1. Tier 1
is not yet claimed or assigned. The technical baseline is green; the remaining
official audit, repository-governance, and SDK Working Group steps are tracked
in the roadmap and
48-feature coverage inventory.
Use the latest stable package for production projects:
dart pub add mcp_dart
Pin the stable SDK release
Pin the stable 2.4 line explicitly when reproducible dependency resolution is
important:
dependencies:mcp_dart:^2.4.2
The snippets below use the current stable SDK line. Package versions
remain separate from protocol profiles: McpProtocol.stable names the SDK's
default compatibility policy.
The SDK and CLI are versioned independently. The stable CLI's ^2.4.2
constraint accepts SDK versions from 2.4.2 up to, but not including, 3.0.0.
For direct SDK integration, start with the
getting-started guide.
The CLI below is optional and provides scaffolding, inspection, and conformance
commands.
What the SDK provides
MCP servers, clients, and host integrations with null-safe Dart APIs.
Core tools, resources, prompts, completion, elicitation, subscriptions,
logging, roots, and sampling APIs with behavior selected for the negotiated
protocol era. MCP 2026-07-28 logging is retained for compatibility but is
deprecated upstream.
Stdio, Streamable HTTP, IO stream, and custom transports.
OAuth client discovery/PKCE hooks, server authentication callbacks, DNS
rebinding protection, and strict Streamable HTTP validation.
An experimental Tasks extension implementation, MCP Apps metadata helpers,
and generic extension negotiation. Extensions are separate from core
protocol coverage; Tasks is not an official extension or part of the SDK's
core conformance claim.
Automated MCP 2025-11-25 and MCP 2026-07-28 conformance, bidirectional
published TypeScript SDK 2.0.0 interoperability, bidirectional Python SDK
2.1.1 interoperability, real-browser transport tests, a real Flutter Web
service integration in Chrome, deterministic widget tests, and an
independent pinned JSON Schema Test Suite gate.
mcp_dart 2.4.2 bounds incoming stdio and IO stream messages to 10 MiB by
default, with configurable limits for larger messages. See the
transport guide before upgrading integrations that
exchange larger frames.
Hardened Streamable HTTP access and JSON-RPC error diagnostics, plus the
deprecated, opt-in legacy HTTP+SSE client with
same-origin routing and bidirectional interoperability against official
TypeScript SDK 1.30.0 and Python SDK 2.1.1 peers.
MCP has three roles: a host owns the user experience, a client connects that
host to one server, and a server exposes tools, resources, and prompts. A host
can manage multiple clients and servers.
Protocol profiles
Profile
Protocol behavior
McpProtocol.stable
Default dual-era profile: prefer MCP 2026-07-28, then fall back to initialization-based MCP specifications; body-only discovery probes are bounded to 5 seconds
McpProtocol.legacy
Initialization-era profile: negotiate the MCP 2025-11-25, MCP 2025-06-18, MCP 2025-03-26, MCP 2024-11-05, or MCP 2024-10-07 specification
McpProtocol.require2026
Require MCP 2026-07-28 and reject legacy initialization
Use stableProtocolVersion or defaultProtocolVersion for MCP 2026-07-28.
previewProtocolVersion remains as a deprecated alias for applications built
against a 2.3 prerelease.
latestInitializationProtocolVersion remains 2025-11-25 when the default
profile falls back to the legacy lifecycle. For compatibility,
latestProtocolVersion and supportedProtocolVersions retain their mcp_dart
2.2 initialization-era values; use allSupportedProtocolVersions for the
dual-era list.
Select a profile only when you need to constrain negotiation:
dart pub global activate mcp_dart_cli 0.2.1
mcp_dart create my_server
cd my_server
mcp_dart inspect
The 0.2.1 CLI creates a project with mcp_dart: ^2.4.2. The inspector
launches the generated stdio server itself. After leaving the interactive
inspector, you can run a single tool directly:
Standalone integration examples may declare newer Dart SDK requirements; check
each example README before running it.
Authentication
StreamableHttpClientTransport supports OAuthClientProvider and optional
authorization-code discovery. Servers can use authenticator or
authenticationHandler and publish protected-resource metadata.
The checked-in OAuth examples store tokens in plaintext files for local
learning. Production applications must use platform secure storage or an
encrypted credential service. See the OAuth examples
and Streamable HTTP authentication.
Do not expose example HTTP servers directly to untrusted networks. Production
deployments should use TLS, authenticate requests, and configure the documented
Host and Origin protections.
Platform support
Target
Stdio
Streamable HTTP
Legacy HTTP+SSE
IO/custom stream
Dart VM / desktop server
Yes
Client and server
Client and server
Yes
Browser / Flutter Web
No process spawning
Client
Client
Yes
Flutter mobile
Only app-managed native helpers
Remote client
Remote client
Yes
Flutter desktop
Local helper processes
Client and server
Client and server
Yes
Legacy HTTP+SSE is deprecated under MCP SEP-2596 and is retained only for
explicit compatibility. Use Streamable HTTP for new remote integrations.
The Dart team maintains dart_mcp in
dart-lang/ai.
Choose it when you prefer the Dart team's APIs. Choose mcp_dart when you need
this SDK's transport, security, compatibility, extension, and inspection
surface. Re-check both packages' current releases before a production decision.