osmandemiroz/mcp-dart-example
If you are the rightful owner of mcp-dart-example and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The Dart MCP Server is a powerful tool that enhances the interaction between AI coding assistants and the Dart/Flutter ecosystem, streamlining development workflows.
Supercharge Your Dart & Flutter Development Experience with the Dart MCP Server
A comprehensive Flutter example demonstrating the power of the Dart MCP Server for AI-enhanced development workflows
This project recreates and expands upon the examples from the official Medium article by the Flutter team, showcasing how the Dart MCP (Model Context Protocol) Server transforms the way AI assistants interact with your Flutter development environment.
๐ What is the Dart MCP Server?
The Dart MCP Server is a powerful bridge between AI coding assistants and the Dart/Flutter ecosystem. It provides a standardized way for AI models to:
- ๐ Analyze and fix errors in your project's code
- ๐ง Introspect and interact with your running application
- ๐ฆ Search pub.dev for the best packages for your use case
- ๐ Manage package dependencies in your pubspec.yaml
- ๐งช Run tests and analyze the results
- ๐ฅ Trigger hot reloads programmatically
- ๐ณ Inspect widget trees for debugging
๐ฏ Interactive Demo Features
This Flutter app provides hands-on demonstrations of MCP capabilities:
1. ๐ Real-time Chart Visualization
Demonstrates: Package Search & Dependency Management
// Example: AI assistant finds and adds charting package
// Prompt: "Find a suitable package to add a line chart that maps button presses over time"
// MCP Server Response:
// 1. Uses pub_dev_search tool to find popular charting libraries
// 2. Suggests syncfusion_flutter_charts (high rating, good documentation)
// 3. Uses pubspec_manager tool to add dependency
// 4. Generates implementation code
The app includes a live chart showing button press data over time, powered by the syncfusion_flutter_charts
package that would be discovered and added via MCP.
2. โ ๏ธ Layout Error Detection & Fixing
Demonstrates: Runtime Error Detection & Widget Inspection
// Example: AI assistant detects and fixes RenderFlex overflow
// Prompt: "Check for and fix static and runtime analysis issues. Check for and fix any layout issues."
// MCP Server Tools Used:
// 1. error_inspector: Gets current runtime errors
// 2. widget_inspector: Analyzes widget tree structure
// 3. Applies fix (e.g., wrapping Row with Expanded or using Wrap)
Click the "Simulate Error" button to see how MCP would detect layout issues, then "Fix Layout" to see the resolution.
3. ๐ฅ Hot Reload Integration
Demonstrates: Development Workflow Enhancement
The app showcases programmatic hot reload capabilities that MCP enables for AI assistants.
4. ๐ ๏ธ MCP Tools Reference
Visual guide to all available MCP server tools with descriptions
๐ Requirements
- Dart SDK: 3.0.0+ (3.9.0+ recommended for full MCP functionality)
- Flutter: 3.0.0+ (3.35.0+ recommended for full MCP functionality)
- MCP-compatible AI tool (see supported tools below)
๐ Quick Start
1. Clone and Setup
git clone <repository-url>
cd mcp-dart-example
flutter pub get
2. Run the Demo App
flutter run -d chrome --web-port=8080
# Or for mobile:
flutter run
3. Install Dart MCP Server
# Install the Dart MCP Server globally
dart pub global activate dart_mcp_server
# Verify installation
dart_mcp_server --help
๐ค Supported AI Development Tools
This example works seamlessly with MCP-enabled AI assistants:
GitHub Copilot in VS Code
- Install the MCP extension for VS Code
- Configure the Dart MCP Server in your settings
- Use natural language prompts to interact with your Flutter project
Cursor
- Enable MCP support in Cursor settings
- Add Dart MCP Server configuration
- Start using AI-powered Flutter development
Gemini CLI
# Install Gemini CLI with MCP support
npm install -g @google/gemini-cli
# Configure with Dart MCP Server
gemini config set mcp.servers.dart ./dart_mcp_server
Gemini Code Assist in VS Code
Follow the official setup guide and add MCP configuration.
Firebase Studio
The Firebase team's experimental Firebase MCP Server works alongside the Dart MCP Server for full-stack development.
๐ฌ Example AI Assistant Prompts
Try these prompts with your MCP-enabled AI assistant:
๐ Error Detection and Fixing
"Check for and fix static and runtime analysis issues. Check for and fix any layout issues."
What happens:
- AI uses
error_inspector
to scan for runtime errors - Uses
widget_inspector
to analyze layout structure - Identifies RenderFlex overflow or other issues
- Automatically applies fixes (e.g., adding Flexible widgets, using Wrap instead of Row)
- Verifies the fix resolved the issue
๐ฆ Package Discovery and Integration
"Find a suitable package to add a line chart that maps the number of button presses over time."
What happens:
- AI uses
pub_dev_search
to find charting packages - Evaluates options based on popularity, maintenance, and features
- Suggests best option (e.g.,
syncfusion_flutter_charts
) - Uses
pubspec_manager
to add dependency - Runs
flutter pub get
- Generates implementation code with proper imports and usage
๐จ UI Enhancement
"Add a beautiful loading animation when searching for packages."
What happens:
- AI analyzes current UI structure
- Suggests appropriate loading widget
- Implements state management for loading states
- Adds smooth animations and transitions
๐งช Testing and Quality
"Add comprehensive tests for the counter functionality and chart updates."
What happens:
- AI analyzes existing code structure
- Creates widget tests for UI components
- Adds unit tests for business logic
- Uses
flutter test
to verify all tests pass
๐ ๏ธ MCP Server Tools Reference
Tool | Purpose | Example Usage |
---|---|---|
pub_dev_search | Find packages on pub.dev | Search for "chart", "animation", "http client" |
pubspec_manager | Manage dependencies | Add/remove packages, update versions |
error_inspector | Get runtime errors | Detect layout overflows, null pointer exceptions |
widget_inspector | Analyze widget tree | Debug layout issues, performance problems |
hot_reload | Trigger hot reload | Apply changes without full restart |
test_runner | Execute tests | Run unit tests, widget tests, integration tests |
analyzer | Static code analysis | Find linting issues, unused imports |
๐ฌ The Dart MCP Server in Action
Scenario 1: Fixing a Runtime Layout Error
The Problem: You build a beautiful UI, run the app, and see the infamous yellow-and-black stripes of a RenderFlex overflow error.
Traditional Approach:
- Manually debug the widget tree
- Identify the problematic Row/Column
- Try different solutions (Flexible, Expanded, Wrap)
- Test and iterate
With MCP Server:
Prompt: "Check for and fix static and runtime analysis issues. Check for and fix any layout issues."
What the AI does:
- ๐ Uses
error_inspector
to see the current runtime errors - ๐ณ Uses
widget_inspector
to understand the layout causing overflow - ๐ง Applies appropriate fix (e.g., wrapping with Flexible or using Wrap)
- โ Verifies the fix resolved the error
Scenario 2: Adding New Functionality with Package Search
The Problem: You need to add a chart to your app but don't know which package to use.
Traditional Approach:
- Search pub.dev manually
- Compare different packages
- Read documentation
- Add to pubspec.yaml
- Run pub get
- Write implementation code
With MCP Server:
Prompt: "Find a suitable package to add a line chart that maps the number of button presses over time."
What the AI does:
- ๐ฆ Uses
pub_dev_search
to find popular charting libraries - ๐ค Evaluates options based on ratings, maintenance, and features
- ๐ก Suggests
syncfusion_flutter_charts
(or similar) - โ Uses
pubspec_manager
to add the package - ๐ Runs
pub get
- ๐ป Generates complete implementation code
- ๐ Self-corrects any syntax errors
๐ง Configuration Examples
VS Code Settings (settings.json)
{
"mcp.servers": {
"dart": {
"command": "dart_mcp_server",
"args": ["--project-root", "${workspaceFolder}"]
}
}
}
Cursor Configuration
{
"mcp": {
"servers": {
"dart-mcp": {
"command": "dart_mcp_server",
"args": ["--project-root", "."]
}
}
}
}
๐ง What's Coming Next?
The Dart MCP Server is rapidly evolving. Upcoming features include:
- ๐ Enhanced widget inspection with performance metrics
- ๐งช Advanced testing capabilities with automatic test generation
- ๐ Code quality metrics and suggestions
- ๐ Integration with Firebase services via Firebase MCP Server
- ๐จ UI/UX analysis and improvement suggestions
๐ Learn More
- ๐ Official Dart MCP Server Documentation
- ๐ Model Context Protocol Specification
- ๐ฅ Firebase MCP Server
- ๐ Original Medium Article
- ๐ป Dart MCP Server GitHub Repository
๐ค Contributing
This example project welcomes contributions! Whether you want to:
- ๐ Fix bugs or improve existing demos
- โจ Add new MCP capability demonstrations
- ๐ Improve documentation
- ๐งช Add more comprehensive tests
Please feel free to open issues and pull requests.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
Ready to supercharge your Flutter development with AI? ๐
Start by running this demo app, then set up the Dart MCP Server with your favorite AI development tool. Experience firsthand how AI assistants can transform your development workflow from reactive debugging to proactive, intelligent development assistance.