|
dolibarr 25.0.0-alpha
|
Abstract base class for all MCP (Model Context Protocol) tools. More...


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. | |
| getRequiredRights (string $toolName) | |
| Rights the caller must hold to run a tool of this class. | |
| writeConfirmationPreview (string $toolName, array $args) | |
| Preview of what a call would write, or NO_WRITE for a read tool. | |
Public Attributes | |
| const | RIGHTS_UNDECLARED = 'undeclared' |
| Default of getRequiredRights(): the class never declared anything, deny. | |
| const | NO_WRITE = '' |
| Returned by writeConfirmationPreview() when the tool writes nothing. | |
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.
| McpTool::__construct | ( | $db, | |
| $user, | |||
| $conf ) |
|
abstract |
Execute a specific tool.
This method must be implemented by child classes to contain the logic for executing the tools defined in getDefinitions.
| string | $toolName | The name of the tool to execute. |
| array<string,mixed> | $args Associative array of arguments for the tool. |
Reimplemented in ToolApiBridge, ToolCategories, ToolCoffeeMaker, ToolConversation, ToolCrudObjects, ToolEmailCleaner, ToolInvoices, ToolNavigation, ToolProducts, ToolReports, and ToolThirdParty.
| McpTool::getCategories | ( | ) |
Return categories this tool belongs to.
Used by the intent parser to filter available tools.
Reimplemented in ToolApiBridge, ToolCategories, ToolCoffeeMaker, ToolConversation, ToolCrudObjects, ToolEmailCleaner, ToolInvoices, ToolNavigation, ToolProducts, ToolReports, and ToolThirdParty.
Definition at line 98 of file mcptool.class.php.
|
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.
Reimplemented in ToolApiBridge, ToolCategories, ToolCoffeeMaker, ToolConversation, ToolCrudObjects, ToolEmailCleaner, ToolInvoices, ToolNavigation, ToolProducts, ToolReports, and ToolThirdParty.
Referenced by McpHandler\registerTool().
| McpTool::getRequiredRights | ( | string | $toolName | ) |
Rights the caller must hold to run a tool of this class.
Returns a list of [module, permission, sub-permission] triples; all of them must hold. Three answers are meaningful:
Tools that do not override this are denied: a caller authenticates as a real user since #40425, so a missing declaration must fail closed.
| string | $toolName | Tool being executed, for classes exposing several. |
Reimplemented in ToolApiBridge, ToolCategories, ToolCoffeeMaker, ToolConversation, ToolCrudObjects, ToolInvoices, ToolNavigation, ToolProducts, ToolReports, and ToolThirdParty.
Definition at line 137 of file mcptool.class.php.
References RIGHTS_UNDECLARED.
| 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.
Reimplemented in ToolConversation.
Definition at line 117 of file mcptool.class.php.
| McpTool::writeConfirmationPreview | ( | string | $toolName, |
| array | $args ) |
Preview of what a call would write, or NO_WRITE for a read tool.
A tool returning a preview does not execute on the first call: the handler answers with that text and a confirmation state, and runs the tool only when the caller comes back with it. The text is what a human is asked to approve, so it names the records and amounts involved rather than dumping arguments.
| string | $toolName | Tool that would run. |
| array<string,mixed> | $args Arguments it would run with. |
Reimplemented in ToolCategories, ToolCrudObjects, ToolInvoices, ToolProducts, and ToolThirdParty.
Definition at line 153 of file mcptool.class.php.
References NO_WRITE.