ai_sdk_mcp 2.0.0
ai_sdk_mcp: ^2.0.0 copied to clipboard
MCP (Model Context Protocol) client for AI SDK Dart. Connect to MCP servers via Streamable HTTP or stdio, discover tools, and use them with any LLM provider.
2.0.0 #
- Hardened Streamable HTTP reconnection, session cleanup, cancellation notifications, response trust boundaries, and concurrent shutdown.
- Removed stdio lifecycle races and prevented cleanup from suppressing unexpected MCP client errors.
- Stdio JSON frames are capped at 1 MiB and terminate safely on overflow.
1.2.0 #
Breaking #
- Removed the legacy HTTP transport exports
SseClientTransportandHttpClientTransport. UseStreamableHttpClientTransportfor remote MCP servers. - The HTTP client now negotiates and enforces MCP protocol
2025-06-18. Deprecated HTTP+SSE servers that only speak2024-11-05are no longer a supported target.
Transport behavior #
StreamableHttpClientTransportspeaks the Streamable HTTP transport against a single MCP endpoint.- Each client message is sent as an HTTP
POST, and the server may answer with either JSON or SSE for that request. - After initialize succeeds, the client sends
notifications/initialized, reusesMCP-Protocol-Versionon later HTTP requests, and starts the optionalGETSSE listener for server-pushed notifications. - If the server returns
Mcp-Session-Id, the transport reuses it on laterPOST/GET/DELETErequests, reconnects the optional listener withLast-Event-IDafter disconnects, and sendsDELETEonclose(). - Request timeouts send a best-effort
notifications/cancellednotification before the call fails locally. - Custom headers and an injected
http.Clientare supported. Injected clients remain caller-owned; the transport closes only the client it creates.
Web / native #
- Flutter-web compatible. The package no longer imports
dart:ioat the top level.StdioMCPTransport(which spawns a process) now lives behind a conditional import: the realdart:ioimplementation is used on native platforms, and a stub that throwsUnsupportedErroris used on web. MCPTransportexposes anotificationsstream for server-initiated messages.notifications/resources/updatedcontinue to drivesubscribeResource()listeners automatically.
Migration #
Replace remote transport construction like this:
final transport = StreamableHttpClientTransport(
url: Uri.parse('https://mcp.example.com/mcp'),
headers: {'Authorization': 'Bearer <token>'},
);
Notes:
- Point the transport at the MCP endpoint itself, not a legacy
/sseendpoint. - Keep required credential headers in
headers, but avoid embedding long-lived secrets inside distributed browser or mobile clients. - If you need a shared
http.Client, inject it and close it yourself after the MCP client shuts down.
1.1.0 #
- Bumped
ai_sdk_dartconstraint to^1.1.0. - No MCP client behaviour changes; version aligned with the rest of the monorepo.
1.0.0+1 #
- Improved pubspec descriptions for better pub.dev discoverability.
- Added
example/example.mdwith usage examples and links to runnable apps.
1.0.0 #
First stable release. Depends on ai_sdk_dart 1.0.0.
MCPClient— manages a session with any MCP server via pluggable transport.SseClientTransport— HTTP SSE transport for remote MCP servers; supports custom headers and separate POST URL.StdioMCPTransport— stdio transport that spawns a local process and communicates via stdin/stdout.initialize()— MCP protocol 2024-11-05 handshake with idempotency guard.tools()— discovers available tools and returns aToolSetcompatible withgenerateText/streamText.callTool()— invokes a named tool with structured arguments; throwsMCPExceptionon server-side errors.MCPException— typed exception withmessagefield.
0.2.0 #
- Initial release.
MCPClient— manages a connection to an MCP server via any transport.SseClientTransport— HTTP SSE transport for remote MCP servers.StdioMCPTransport— stdio transport for local MCP server processes.tools()— discovers available tools and returns a typedToolSet.callTool()— invokes a named tool with structured arguments.- MCP protocol 2024-11-05 initialize handshake.
MCPExceptionfor server-side errors.