How leehack/mcp_dart works
Project type and purpose
• This is a Dart SDK library implementing the Model Context Protocol (MCP) for both clients and servers. It’s not a single full‐stack application, but rather a protocol SDK with pluggable transports (stdio, HTTP, SSE, streams) and example binaries showing usage.
File structure
• Top-level:
• lib/: the published SDK.
• example/: standalone demo clients and servers.
• test/: unit and integration tests.
• .github/, CI workflows, lint and build configs.
• Inside lib/src:
• shared/: core protocol definitions (messages, transports, UUID, URI template).
• client/: client-side API and transports (stdio, streamable_https).
• server/: server-side API, tool registration, transports (stdio, SSE, streamable_https).
• Examples show how to wire up a McpServer or McpClient with specific transports and host processes.
README insights
• This SDK aligns with a published spec.
• Supports multiple transports symmetrically (client + server) except SSE (server only, deprecated).
• Shows typical startup code: server.tool(...) + server.connect(transport).
a. Main components:
• MCP Client Library
• MCP Server Library
• Transport Layer (std I/O, Streamable HTTPS, SSE, In‐process stream)
• Protocol Core (shared message definitions, module loader)
• Tooling Framework (server.tool callbacks, resource & tool capabilities)
• Example Applications (CLI binaries for demo)
• External LLM Host or Consumer (e.g., Claude Desktop)
b. Relationships & Data Flow:
• Client Library → serializes MCP requests → Transport Layer → delivers JSON to Server Layer
• Server Library → deserializes MCP requests → Core Protocol Handler → dispatches to registered tools/resources → generates MCP responses → back through transport to client
• Example binaries instantiate Client or Server + select transport
• External LLM Host communicates with client executables via stdin/stdout or HTTP
c. Architectural patterns & principles:
• Layered modular design: transport, client/server API, shared protocol
• Dependency inversion: transports implement abstract interfaces in shared module
• Plugin pattern: server.tool(...) registers new tool handlers
• Single responsibility: each transport and module handles one concern
d. Key technologies & libraries:
• Dart SDK ≥3.0
• Built-in dart:io streams for stdio transport
• HTTP server/client for streamable HTTPS
• EventSource or SSE server manager
• JSON encoding/decoding