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());
}
