dolibarr 25.0.0-alpha
ToolApiBridge Class Reference

Class ToolApiBridge. More...

Inheritance diagram for ToolApiBridge:
Collaboration diagram for ToolApiBridge:

Public Member Functions

 __construct ($db, $user=null, $conf=null)
 Constructor.
 
 getDefinitions ()
 Returns tool definitions derived from the enabled REST API endpoints.
 
 getCategories ()
 Return categories this tool belongs to.
 
 execute (string $name, array $args)
 Execute a bridged tool: authenticate the service user, call the API method in-process with positional arguments, catch RestException.
 
- Public Member Functions inherited from McpTool
 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

 loadApiRuntime ()
 Load the REST API runtime (Restler autoloader + DolibarrApi base classes), mirroring the bootstrap sequence of htdocs/api/index.php, so that the endpoint classes (which extend DolibarrApi and throw RestException) can be loaded and executed outside the Restler HTTP runtime.
 
 buildToolDefinition (array $ep, string $key, string $method, string $toolname, array $meta=[])
 Build one MCP tool definition from an API class method: reflection + docblock give the skeleton, then the hand-written per-method enrichment is merged over it ('description' appended, 'params' overriding parameter docs, shared common docs as last fallback).
 
 docTypeToJson (string $type)
 Convert a docblock type to a JSON Schema type.
 

Detailed Description

Class ToolApiBridge.

Exposes enabled REST API endpoints as MCP tools (read-only POC).

Definition at line 62 of file api_bridge.class.php.

Constructor & Destructor Documentation

◆ __construct()

ToolApiBridge::__construct ( $db,
$user = null,
$conf = null )

Constructor.

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

Reimplemented from McpTool.

Definition at line 251 of file api_bridge.class.php.

References conf(), and user.

Member Function Documentation

◆ buildToolDefinition()

ToolApiBridge::buildToolDefinition ( array $ep,
string $key,
string $method,
string $toolname,
array $meta = [] )
private

Build one MCP tool definition from an API class method: reflection + docblock give the skeleton, then the hand-written per-method enrichment is merged over it ('description' appended, 'params' overriding parameter docs, shared common docs as last fallback).

Parameters
array{module:string,path:string,class:string,label:string}$ep Endpoint entry
string$keyEndpoint key (e.g. 'thirdparties')
string$methodWhitelisted API method name (e.g. 'index', 'get')
string$toolnameGenerated tool name
array{suffix?:string,description?:string,params?:array<string,string>}$meta Hand-written enrichment for this method
Returns
array<string, mixed>|null Tool definition, or null on reflection failure

Definition at line 341 of file api_bridge.class.php.

References docTypeToJson(), and string.

Referenced by getDefinitions().

◆ docTypeToJson()

ToolApiBridge::docTypeToJson ( string $type)
private

Convert a docblock type to a JSON Schema type.

Parameters
string$typeDocblock type (may be a union like int|string)
Returns
string JSON Schema type

Definition at line 426 of file api_bridge.class.php.

Referenced by buildToolDefinition().

◆ execute()

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

Execute a bridged tool: authenticate the service user, call the API method in-process with positional arguments, catch RestException.

Parameters
string$nameThe tool name (e.g. 'api_thirdparties_list').
array<string,mixed>$args The tool arguments (named).
Returns
mixed Result array, or ["error" => ...] on failure.

Reimplemented from McpTool.

Definition at line 459 of file api_bridge.class.php.

References getDefinitions(), getDolGlobalInt(), and loadApiRuntime().

◆ getCategories()

ToolApiBridge::getCategories ( )

Return categories this tool belongs to.

Returns
array<string> List of categories

Reimplemented from McpTool.

Definition at line 446 of file api_bridge.class.php.

◆ getDefinitions()

ToolApiBridge::getDefinitions ( )

Returns tool definitions derived from the enabled REST API endpoints.

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

Reimplemented from McpTool.

Definition at line 282 of file api_bridge.class.php.

References buildToolDefinition(), getDolGlobalInt(), isModEnabled(), and loadApiRuntime().

Referenced by execute().

◆ loadApiRuntime()

ToolApiBridge::loadApiRuntime ( )
private

Load the REST API runtime (Restler autoloader + DolibarrApi base classes), mirroring the bootstrap sequence of htdocs/api/index.php, so that the endpoint classes (which extend DolibarrApi and throw RestException) can be loaded and executed outside the Restler HTTP runtime.

Returns
void

Definition at line 268 of file api_bridge.class.php.

Referenced by execute(), and getDefinitions().


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