This doc is written mostly for AI.
This project enables AI-powered development tools to interact with Flutter applications through a Dart-based MCP server with dynamic tools registration capabilities:
┌─────────────────────────────┐ ┌──────────────────┐ ┌─────────────────────────────┐
│ │ │ │ │ │
│ Flutter App │<--->│ Dart VM │<--->│ MCP Server Dart │
│ + mcp_toolkit │ │ Service │ │ + Dynamic Registry │
│ + Dynamic Tool Registration│ │ (Port 8181) │ │ │
│ │ │ │ │ │
└─────────────────────────────┘ └──────────────────┘ └─────────────────────────────┘
This unified architecture supports:
- Basic VM operations: Memory inspection, debugging, isolate management
- Flutter-specific operations: Widget inspection, layout analysis, error reporting, screenshots
- Dynamic tool registration: Runtime tool discovery and custom functionality
-
Direct VM Service Communication:
- Memory inspection
- Basic debugging operations
- Isolate management
- General VM state queries
-
Flutter-Specific Operations:
- Widget tree inspection
- Layout debugging
- State management analysis
- Performance profiling
- UI element interaction
-
Dynamic Tools Registration 🆕:
- Custom debugging tools
- App-specific functionality
- Runtime tool discovery
- Event-driven tool updates
Location: Your Flutter App Purpose: Debug target application Requirements:
- Must run in debug mode
mcp_toolkitpackage integrated, providing service extensions- Port 8181 available for VM Service
Location: mcp_toolkit/mcp_toolkit/ (as a Dart package integrated into the Flutter Application)
Purpose: Exposes Flutter-specific functionalities to external tools (like AI assistants via the MCP/Forwarding server) through custom Dart VM Service extensions.
Key Features:
- Registers custom Dart VM Service extensions (e.g.,
ext.mcp.toolkit.app_errors,ext.mcp.toolkit.view_screenshots). - Captures and reports Flutter application errors.
- Provides screenshot capabilities of the application's UI.
- Enables retrieval of application view details.
- Facilitates interaction with the Flutter application at a higher level than raw VM service calls.
- 🆕 Dynamic Tool Registration: Allows runtime registration of custom tools and resources.
Location: mcp_server_dart/
Purpose: Protocol translation, request handling, and dynamic registry management
Key Features:
- JSON-RPC to VM Service Protocol translation
- Request routing and validation
- Error handling and logging
- Connection management
- Dynamic Registry: Manages runtime-registered tools and resources
- Event-Driven Discovery: Real-time tool detection via DTD events
Location: AI Tool (e.g., Cline, Claude, Cursor) Purpose: Developer interaction and analysis Features:
- Code analysis and suggestions
- Widget tree visualization
- Debug information display
- Performance recommendations
- Dynamic Tool Discovery: Access to runtime-registered tools
-
Request Initiation:
AI Assistant -> MCP JSON-RPC Request -> MCP Server Dart -
Protocol Translation & Interaction:
MCP Server Dart -> Dart VM Service (invoking mcp_toolkit extensions on Flutter App) -
Response Flow:
mcp_toolkit in Flutter App -> Dart VM Service -> MCP Server Dart -> AI Assistant
-
Tool Registration:
Flutter App -> MCPToolkitBinding.addEntries() -> DTD Event -> MCP Server Dart -
Discovery:
AI Assistant -> listClientToolsAndResources -> MCP Server Dart -> Dynamic Registry -
Execution:
AI Assistant -> runClientTool -> MCP Server Dart -> Dynamic Registry -> Flutter App
- JSON-RPC 2.0 based
- Standardized message format
- Type-safe interactions
- Extensible command system
- Dynamic tool support
- Flutter's native debugging protocol
- Real-time state access
- Widget tree manipulation
- Performance metrics collection
- Event-driven tool discovery
- Runtime registration/unregistration
- Type-safe tool definitions
- Hot reload support
-
Debug Mode Only:
- All operations require debug mode
- No production access
- Controlled environment execution
-
Port Security:
- Default ports: 8181 (VM), 8182 (MCP)
- Local-only connections
- Port validation and verification
-
Data Safety:
- No sensitive data exposure
- Sanitized error messages
- Controlled access scope
-
Dynamic Registration Security 🆕:
- Debug mode enforcement
- Local-only tool registration
- Sandboxed execution environment
-
Connection Management:
- Connection pooling
- Automatic reconnection
- Resource cleanup
-
Data Efficiency:
- Response caching
- Batch operations
- Optimized protocol translation
-
Error Handling:
- Graceful degradation
- Detailed error reporting
- Recovery mechanisms
-
Dynamic Registry Performance:
- Event-driven updates (no polling)
- Efficient tool lookup
- Minimal overhead registration
// Add new commands via dynamic registration
final customTool = MCPCallEntry.tool(
handler: (request) {
// Your custom logic
return MCPCallResult(message: 'Success');
},
definition: MCPToolDefinition(
name: 'custom_command',
description: 'Your custom functionality',
inputSchema: {...},
),
);
await MCPToolkitBinding.instance.addEntries(entries: {customTool});Dynamic Tool Registration:
// Example: Register custom debugging tool
final debugTool = MCPCallEntry.tool(
handler: (request) => MCPCallResult(
message: 'Debug info',
parameters: {'state': getCurrentState()},
),
definition: MCPToolDefinition(
name: 'get_debug_state',
description: 'Get current debug state',
inputSchema: {'type': 'object', 'properties': {}},
),
);
await MCPToolkitBinding.instance.addEntries(entries: {debugTool});- DynamicRegistry: Core registry managing tool/resource lifecycle
- RegistryDiscoveryService: DTD event-driven discovery service
- DynamicRegistryTools: MCP tools for registry interaction
- MCPToolkitBinding: Client-side registration interface
Flutter App Tool Registration -> DTD Event -> Discovery Service -> Registry Update -> MCP Tool Availability
- Registration: Flutter app calls
addEntries() - Discovery: DTD event triggers server-side discovery
- Availability: Tool becomes available via MCP protocol
- Execution: AI assistant can call tool via
runClientTool - Cleanup: Hot reload or app restart clears registry
-
Connection Issues:
- Verify debug mode is active
- Check port availability
- Confirm extension installation
-
Protocol Errors:
- Validate message format
- Check method availability
- Verify parameter types
-
Performance Problems:
- Monitor message volume
- Check response times
- Analyze resource usage
-
Dynamic Registration Issues:
- Ensure
mcp_toolkitis properly initialized - Check DTD event streaming
- Verify tool schema compliance
- Use
listClientToolsAndResourcesfor debugging
- Ensure
