Skip to content

ToolFactory

Category: Mcp_client

Source: tool_factory.dart

Wraps MCP tool descriptors as glue_core [Tool] implementations.

The agent loop sees an MCP-sourced tool as a normal [Tool]; the permission gate, render path, session log, and observability all behave the same. The only difference is the namespaced name (<serverId>.<toolName>) and that execute() delegates to [McpClient.callTool].

Classes

McpTool

Wraps a single MCP tool descriptor.

[bareName] is the server-side tool name (sent to tools/call). [name] is the namespaced surface (<serverId>__<bareName>) — that's what shows up in autocomplete, permission prompts, and the agent's tool registry.

Why double-underscore: OpenAI's function-name validator only allows ^[a-zA-Z0-9_-]+$ (no dots). Single _ collides with tool-name snake_case and single - collides with hyphenated server ids (my-mcp-server). __ is rare in both, so the boundary stays unambiguous and the name remains visually parseable.

Constructor

dart
McpTool({
    required this.client,
    required this.serverId,
    required this.bareName,
    required this.descriptor,
  })

Properties

PropertyTypeDescription
clientMcpClient
serverIdString
bareNameString
descriptorMcpToolDescriptor
nameString get
descriptionString get
parametersList<ToolParameter> get
trustToolTrust get
nameString get
descriptionString get
parametersList<ToolParameter> get
trustToolTrust get

Methods

Future<ToolResult> execute(Map<String, dynamic> args)

Functions

`List<McpTool> buildMcpTools({

required McpClient client, required String serverId, required List<McpToolDescriptor> descriptors, Set<String> reservedNames = const {}, })`

Builds glue_core [Tool]s for every descriptor advertised by a server. Skips descriptors whose namespaced name conflicts with [reservedNames] (typically the agent's native tools — natives win to avoid surprise behaviour from a server claiming read_file).

Released under the MIT License.