flutter_mcp 1.0.4
SDKflutter
Platformandroidioswindowslinuxmacosweb
Flutter plugin that integrates MCP server, client, and LLM into a unified agent system. Provides background execution, notification, system tray, lifecycle management, secure data storage, and scheduling for cross-platform agent apps.
Flutter MCP Examples
This directory contains example applications demonstrating various Flutter MCP features.
Examples Overview
Basic Examples
-
- Basic server connection
- Simple method execution
- Error handling
-
- Connecting to multiple servers
- Server switching
- Load balancing
-
- Background task scheduling
- Periodic updates
- Platform-specific implementations
Advanced Examples
-
- Creating custom plugins
- Tool implementation
- Resource management
-
- Integration with Provider
- Integration with Riverpod
- Integration with Bloc
-
- WebSocket subscriptions
- Event streaming
- Live data synchronization
Platform-Specific Examples
-
- Android-specific features
- Background services
- Notifications
-
- iOS-specific features
- Background fetch
- Push notifications
-
- System tray integration
- File system access
- Native menus
-
- Web Worker integration
- Service Worker setup
- Browser storage
Running Examples
-
Clone the repository:
git clone https://github.com/your-org/flutter_mcp.git cd flutter_mcp/examples -
Install dependencies:
flutter pub get -
Run an example:
cd simple_connection flutter run
Example Structure
Each example follows a standard structure:
example_name/
├── lib/
│ ├── main.dart
│ ├── config/
│ │ └── mcp_config.dart
│ ├── models/
│ │ └── data_model.dart
│ ├── screens/
│ │ └── home_screen.dart
│ └── services/
│ └── mcp_service.dart
├── test/
│ └── widget_test.dart
├── pubspec.yaml
└── README.md
Common Patterns
Configuration
All examples use a common configuration pattern:
final config = MCPConfig(
servers: {
'example-server': ServerConfig(
uri: 'ws://localhost:3000',
auth: AuthConfig(
type: 'token',
token: 'your-token',
),
),
},
);
Error Handling
Standard error handling pattern used across examples:
try {
final result = await server.execute('method', params);
// Handle success
} on MCPException catch (e) {
// Handle MCP-specific errors
} catch (e) {
// Handle general errors
}
State Management
Examples demonstrate different state management approaches:
// Provider
final mcpProvider = Provider<MCPService>((ref) => MCPService());
// Riverpod
final mcpProvider = Provider<MCPService>((ref) => MCPService());
// Bloc
class MCPBloc extends Bloc<MCPEvent, MCPState> {
// Implementation
}
Testing Examples
Each example includes tests:
cd example_name
flutter test
Contributing
To add a new example:
- Create a new directory under
examples/ - Implement the example following the standard structure
- Add documentation to this README
- Include comprehensive tests
- Submit a pull request
License
See the main project LICENSE file.