mcp_server_dart
A developer-friendly MCP (Model Context Protocol) framework for Dart with annotations and code generation. Build MCP servers as easily as annotating methods with @MCPTool, @MCPResource, or @MCPPrompt - similar to how json_serializable or freezed works.
claude mcp add --transport stdio zfinix-mcp_server_dart docker run -i zfinix/mcp_server_dart:latest \ --env MCP_ENV="description or placeholder"
How to use
The mcp_server_dart package provides a Dart-based MCP (Model Context Protocol) framework that lets you declare MCP tools, resources, and prompts using simple annotations. Generated code handles registration and wiring, enabling a clean, type-safe API surface for LLMs and clients. The server supports multiple transports, including standard input/output (stdio) for CLI usage and HTTP-based transports with Server-Sent Events (SSE) for real-time streaming, all built on the Relic HTTP framework. Use the annotated methods in your server class to expose tools, resources, and prompts that clients can call through MCP endpoints. The example demonstrates how to annotate methods with @MCPTool, @MCPResource, and @MCPPrompt, then generate boilerplate with build_runner and run the server via the provided start or serve methods. The included health and status endpoints help you monitor health, uptime, and active MCP streams.
To use the tools, declare a class that extends MCPServer, annotate methods accordingly, and call registerGeneratedHandlers() after construction. Build generation produces an extension that wires endpoints for you. Run the server and choose a transport: standard IO for CLI integration or an HTTP server on a port (e.g., 8080) for production deployments. Clients can interact with the generated MCP endpoints using JSON-RPC-like payloads, obtaining JSON responses with strong type safety and automatic input schema generation from method signatures.
How to install
Prerequisites:\n- Dart SDK 3.9+ installed on your machine.\n- A Dart project initialized (pubspec.yaml).\n- Build runner available for code generation.\n\nStep-by-step installation:\n1) Create a new Dart project (or use an existing one):\n\nbash\ndart create my_mcp_server\ncd my_mcp_server\n\n\n2) Add dependencies to pubspec.yaml:\n\nyaml\ndependencies:\n mcp_server_dart: ^1.1.2\n relic: ^0.5.0\n logging: ^1.3.0\ndev_dependencies:\n build_runner: ^2.4.13\n\n\n3) Import and implement your MCP server using the README guidance (generate code as shown):\n\ndart\nimport 'package:mcp_server_dart/mcp_server_dart.dart';\n\npart 'my_server.mcp.dart'; // Generated file\n\nclass MyMCPServer extends MCPServer {\n MyMCPServer() : super(name: 'my-server', version: '1.0.0') {\n registerGeneratedHandlers();\n }\n // Add @MCPTool, @MCPResource, @MCPPrompt methods here...\n}\n\n\n4) Generate the code:\n\nbash\ndart run build_runner build\n\nThis will generate the my_server.mcp.dart file with automatic registration hooks.\n\n5) Run the server: you can run a Dart-based HTTP server or use stdio (CLI) transport as shown in the Quick Start example. For the CLI approach, instantiate your server and call start(); for HTTP, call serve(port: 8080).
Additional notes
Tips and known considerations:\n- Ensure you have a Dart project configured with build_runner to generate the MCP boilerplate.\n- The framework supports multiple transports: stdio (CLI), HTTP (Relic-based), and SSE streaming per MCP 2025-06-18 spec.\n- Health checks are exposed at /health and status at /status when using the HTTP transport.\n- Use the provided annotations to generate input schemas automatically from method signatures.\n- If you enable CORS in your HTTP server, configure allowed origins to fit your deployment environment.\n- For production deployments, consider using a reverse proxy and enabling graceful shutdown.\n- The SSE implementation enables real-time MCP streaming of results to clients.\n- If you encounter issues with code generation, run dart clean and re-run dart run build_runner build to regenerate the extension.\n- Logging can be configured via the standard Dart logging package; enable verbose logs during development and reduce in production.
Related MCP Servers
mcp-language
mcp-language-server gives MCP enabled clients access semantic tools like get definition, references, rename, and diagnostics.
mcp_flutter
MCP server and MCP Toolkit for Flutter and Dart VM - supports dynamic tooling
robloxstudio
Create agentic AI workflows in ROBLOX Studio
kodit
đ©âđ» MCP server to index external repositories
gtm
An MCP server for Google Tag Manager. Connect it to your LLM, authenticate once, and start managing GTM through natural language.
cbn_mcp
A Model Context Protocol (MCP) server for accessing Central Bank of Nigeria (CBN) data and circulars. Connect this server to Cursor, Claude Desktop, or any MCP-compatible application to access CBN regulatory information directly in your AI conversations. đ