dolibarr 24.0.0-beta
McpTool Class Reference

Abstract base class for all MCP (Model Context Protocol) tools. More...

Inheritance diagram for McpTool:

Public Member Functions

 __construct ($db, $user, $conf)
 Constructor.
 
 getDefinitions ()
 Return the list of tools provided by this class.
 
 execute (string $toolName, array $args)
 Execute a specific tool.
 
 getCategories ()
 Return categories this tool belongs to.
 
 isSystem ()
 Return true if this is a system/infrastructure tool that must always remain visible and executable regardless of the admin allow-list.
 

Detailed Description

Abstract base class for all MCP (Model Context Protocol) tools.

All AI tools must extend this class. It provides a standard interface for defining tool capabilities and executing them, along with common utility methods for interacting with Dolibarr.

Definition at line 32 of file mcptool.class.php.

Constructor & Destructor Documentation

◆ __construct()

McpTool::__construct ( $db,
$user,
$conf )

Constructor.

Parameters
DoliDB$dbDatabase handler object
User$userUser object
Conf$confConfiguration object

Definition at line 50 of file mcptool.class.php.

References conf(), and user.

Member Function Documentation

◆ execute()

McpTool::execute ( string $toolName,
array $args )
abstract

Execute a specific tool.

This method must be implemented by child classes to contain the logic for executing the tools defined in getDefinitions.

Parameters
string$toolNameThe name of the tool to execute.
array<string,mixed>$args Associative array of arguments for the tool.
Returns
mixed The result of the tool execution.

Reimplemented in ToolCategories, ToolConversation, ToolCrudObjects, ToolInvoices, ToolNavigation, ToolProducts, ToolReports, and ToolThirdParty.

◆ getCategories()

McpTool::getCategories ( )

Return categories this tool belongs to.

Used by the intent parser to filter available tools.

Returns
array<string> List of categories (e.g., ['billing', 'commercial'])

Reimplemented in ToolCategories, ToolConversation, ToolCrudObjects, ToolInvoices, ToolNavigation, ToolProducts, ToolReports, and ToolThirdParty.

Definition at line 86 of file mcptool.class.php.

◆ getDefinitions()

McpTool::getDefinitions ( )
abstract

Return the list of tools provided by this class.

This method must be implemented by child classes to define their capabilities. It should return an array of tool definitions, typically in a JSON schema format.

Returns
list<array<string, mixed>> Array of tool definitions.

Reimplemented in ToolCategories, ToolConversation, ToolCrudObjects, ToolInvoices, ToolNavigation, ToolProducts, ToolReports, and ToolThirdParty.

Referenced by McpHandler\registerTool().

◆ isSystem()

McpTool::isSystem ( )

Return true if this is a system/infrastructure tool that must always remain visible and executable regardless of the admin allow-list.

The default is false. Override and return true in any tool class that provides core assistant communication functions (clarification, confirmation, responses, etc.).

McpHandler calls this method at runtime — no tool names are hardcoded anywhere. Adding a new system tool class in the future requires only overriding this method in that class; no changes to McpHandler are needed.

Returns
bool

Reimplemented in ToolConversation.

Definition at line 105 of file mcptool.class.php.


The documentation for this class was generated from the following file: