> For the complete documentation index, see [llms.txt](https://dnotifier.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/example-mcp-agent/dart-flutter.md). Agents can also search and read this documentation through its [MCP server](https://dnotifier.gitbook.io/product-docs/~gitbook/mcp).

# Dart / Flutter

```dart
import 'dart:io';

import 'package:dnotifier/dnotifier.dart';

Future<void> main() async {
  const userId = 'demo-user';
  final notifier = DNotifier(
    appId: Platform.environment['DNOTIFIER_APP_ID']!,
    secret: Platform.environment['DNOTIFIER_SECRET']!,
    transport: 'http',
    userId: userId,
    permissionEnforcement: 'backend',
    onAgentEvent: (event) {
      print('[agent] ${event['type']} ${event['toolId']} ${event['mcpServerId']}');
    },
  );

  await notifier.connect();

  final mermaid = await notifier.mcp.connect(
    id: 'mermaid',
    name: 'Agentic Mermaid',
    transport: 'http',
    endpoint: 'https://agentic-mermaid.dev/mcp',
  );

  final allTools = mermaid.tools();
  print('Discovered: ${allTools.map((t) => t.name).join(', ')}');

  RegisteredTool findTool(String name) =>
      allTools.firstWhere((t) => t.name == name);

  final verify = findTool('mermaid.verify');
  final describe = findTool('mermaid.describe');
  final renderAscii = findTool('mermaid.render_ascii');

  const sample = 'flowchart LR\n  A[Start] --> B[Done]';
  final direct = await verify.execute(
    {'source': sample},
    {
      'executionId': 'manual',
      'agentId': 'manual',
      'toolId': verify.id,
    },
  );
  final directText = direct.toString();
  print(
    'Direct verify: ${directText.substring(0, directText.length > 200 ? 200 : directText.length)}',
  );

  final agent = defineAgent(
    name: 'mermaid-assistant',
    description: 'Validates and explains Mermaid diagrams using MCP tools.',
    instructions:
        'You help with Mermaid diagrams. Use mermaid.verify, mermaid.describe, and mermaid.render_ascii when needed. Keep answers concise.',
    provider: 'open_ai',
    model: 'gpt-4o',
    observability: true,
    tools: [verify, describe, renderAscii],
    permissions: {
      'mermaid.verify': ['execute'],
      'mermaid.describe': ['execute'],
      'mermaid.render_ascii': ['execute'],
    },
  );

  final result = await notifier.runAgent(
    agent,
    input:
        'Create a Mermaid diagram for a 3-tier web architecture and render it in ASCII.',
    userId: userId,
    maxToolRounds: 6,
  );

  print('finishReason: ${result['finishReason']}');
  print('executionId: ${result['executionId']}');
  print('output:\n${result['output']}');
}
```

## Learn more

* [**Tools & MCP — Dart**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/tools-and-mcp/dart-flutter.md)
* [**Local tool agent example**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/example-tool-agent/dart-flutter.md)
