McpTool class abstract

A runtime MCP tool exposed by a Zuraffa app.

Subclass (or anonymously implement) this contract for each app feature you want callable by an AI agent:

class FetchUrlTool implements McpTool {
  @override
  String get name => 'fetch';
  @override
  String get description => 'Fetch the URL and return its body.';
  @override
  Map<String, dynamic> get inputSchema => {
    'type': 'object',
    'properties': {'url': {'type': 'string', 'description': 'HTTP(S) URL'}},
    'required': ['url'],
  };
  @override
  Future<McpToolResult> call(Map<String, dynamic> args) async {
    final url = args['url'] as String;
    final client = HttpClient();
    final req = await client.getUrl(Uri.parse(url));
    final res = await req.close();
    final body = await res.transform(utf8.decoder).join();
    return McpToolResult.ok(body);
  }
}

Then register the tool with McpServerPlugin:

final engine = ZuraffaEngine()
  ..register(McpServerPlugin(tools: [FetchUrlTool()]));
await engine.bootstrap();
Implementers

Constructors

McpTool()

Properties

description → String
Human/AI-facing description. Should explain what the tool does, what its arguments mean, and what it returns.
no setter
hashCode → int
The hash code for this object.
no setterinherited
inputSchema → Map<String, dynamic>
JSON Schema (draft-07 subset) describing the call arguments. The runtime server forwards this verbatim to the MCP client in the tools/list response.
no setter
name → String
Stable, unique tool name (snake_case). Used by the MCP client to invoke this tool via tools/call.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

call(Map<String, dynamic> arguments) → Future<McpToolResult>
Invokes the tool with the named arguments from a tools/call request. Implementations should validate inputs defensively (the MCP client is untrusted) and return an McpToolResult — never throw across the JSON-RPC boundary.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited