Creating Your First Dynamic Tool

This guide will walk you through the process of creating and registering your first dynamic tool.

1. Set Up Your Project

Make sure you have followed the execution playbook and have the MCP server and a Flutter app running.

2. Create the Tool

In your Flutter app, create a new file called lib/my_tools.dart and add the following code:

import 'package:mcp_toolkit/mcp_toolkit.dart';

void registerMyTools() {
  final helloTool = AgentCallEntry.tool(
    namespace: 'app',
    name: 'hello',
    description: 'A simple tool that says hello.',
    inputSchema: const {
      'type': 'object',
      'additionalProperties': false,
      'properties': {},
    },
    handler: (_) async => AgentResult.success(
      message: 'Hello from a dynamic tool!',
    ),
  );

  addMcpTool(helloTool);
}

3. Register the Tool

In your lib/main.dart file, import my_tools.dart and call registerMyTools() in your main function:

import 'package:flutter/material.dart';
import 'package:mcp_toolkit/mcp_toolkit.dart';
import 'my_tools.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  MCPToolkitBinding.instance.initialize();
  registerMyTools();
  runApp(const MyApp());
}

4. Hot Reload and Use the Tool

Save your changes and hot reload the app. Now, you can ask your AI assistant to run the hello tool. It should respond with "Hello from a dynamic tool!".

Server-side registry (intentcall)

On the MCP server, dynamic tools are stored as RegisteredAgentIntent entries in DynamicRegistry (not raw dart_mcp.Tool handlers). MCP publish still uses the tool schema for listing; invocation routes through AgentRegistry.invoke and VM extension forwarding.