dolibarr 25.0.0-alpha
ToolCrudObjects Class Reference

Tool class for CRUD operations on Dolibarr objects TODO Remove all tools in this file. More...

Inheritance diagram for ToolCrudObjects:
Collaboration diagram for ToolCrudObjects:

Public Member Functions

 __construct (DoliDB $db, $user=null, $conf=null)
 Constructor.
 
 getDefinitions ()
 Returns an array of tool definitions, including name, description, and input schema.
 
 getCategories ()
 Return categories this tool belongs to.
 
 execute (string $name, array $args)
 Executes the requested tool function based on its name.
 
- Public Member Functions inherited from McpTool
 __construct ($db, $user, $conf)
 Constructor.
 
 isSystem ()
 Return true if this is a system/infrastructure tool that must always remain visible and executable regardless of the admin allow-list.
 

Private Member Functions

 addLineItem (array $args)
 Entry point for the 'add_line_item' tool.
 
 findProduct ($identifier)
 Find a product by various identifiers (ID, Ref, Barcode, Label).
 
 deleteObject (array $args)
 Delete a document object.
 
 checkPermission (string $type)
 Check if the current user has permission for the given object type.
 
 instantiate (string $type)
 Factory Helper to instantiate Dolibarr objects.
 

Detailed Description

Tool class for CRUD operations on Dolibarr objects TODO Remove all tools in this file.

Must be into the objectname.class.php to follow the same structure than APIs.

Definition at line 36 of file crud_objects.class.php.

Constructor & Destructor Documentation

◆ __construct()

ToolCrudObjects::__construct ( DoliDB $db,
$user = null,
$conf = null )

Constructor.

Aligned with McpHandler's instantiation contract: new $className($db, $user, $conf). Accepting $user via DI allows this tool to work in HTTP MCP context where no PHP web session exists. Some sibling tool classes (ToolThirdParty, ToolCategories, ToolProducts) already use this signature; this aligns ToolCrudObjects with them.

Parameters
DoliDB$dbDatabase handler
User | null$userService user provided by McpHandler (from AI_MCP_USER_ID)
Conf | null$confDolibarr config (optional)

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

References $db, conf(), and user.

Member Function Documentation

◆ addLineItem()

ToolCrudObjects::addLineItem ( array $args)
private

Entry point for the 'add_line_item' tool.

Adds line to an already existing object. Instantiates the document and calls the line processing helper.

Parameters
array{object_type:string,parent_id:int,product_id?:int,description?:string,quantity?:float|int,unit_price?:float|int,vat_rate?:float|int}$args Tool arguments for adding a line item
Returns
array{success:bool,line_id?:int,error?:string}

Definition at line 708 of file crud_objects.class.php.

References string.

Referenced by execute().

◆ checkPermission()

ToolCrudObjects::checkPermission ( string $type)
private

Check if the current user has permission for the given object type.

Parameters
string$typeObject type key.
Returns
array{error: string}|null Null if allowed, error array if denied.

Definition at line 894 of file crud_objects.class.php.

References user.

◆ deleteObject()

ToolCrudObjects::deleteObject ( array $args)
private

Delete a document object.

Parameters
array{object_typestring, id: int|string} $args Arguments containing type and ID.
Returns
array{success: bool}|array{error: string} Result array.

Definition at line 849 of file crud_objects.class.php.

References $id, and string.

Referenced by execute().

◆ execute()

ToolCrudObjects::execute ( string $name,
array $args )

Executes the requested tool function based on its name.

Parameters
string$nameThe name of the tool to execute.
array<string,mixed>$args The arguments for the tool (key-value pairs).
Returns
mixed The result of the tool execution (usually an array) or an error array.

Reimplemented from McpTool.

Definition at line 335 of file crud_objects.class.php.

References $conf, $mysoc, addLineItem(), deleteObject(), and user.

◆ findProduct()

ToolCrudObjects::findProduct ( $identifier)
private

Find a product by various identifiers (ID, Ref, Barcode, Label).

Parameters
string | int$identifierThe search term (ID, ref, barcode, etc.).
Returns
Product|array{error: string, matches?: list<string>} Returns the Product object on success, or an error array.

Definition at line 757 of file crud_objects.class.php.

References getEntity().

◆ getCategories()

ToolCrudObjects::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 from McpTool.

Definition at line 323 of file crud_objects.class.php.

◆ getDefinitions()

ToolCrudObjects::getDefinitions ( )

Returns an array of tool definitions, including name, description, and input schema.

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

Reimplemented from McpTool.

Definition at line 152 of file crud_objects.class.php.

◆ instantiate()

ToolCrudObjects::instantiate ( string $type)
private

Factory Helper to instantiate Dolibarr objects.

Parameters
string$typeObject type key (e.g., 'proposal', 'invoice').
Returns
CommonObject New instance of the specific Dolibarr class.
Exceptions
ExceptionIf the type is unknown or class not found.

Definition at line 914 of file crud_objects.class.php.

References string.


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