dolibarr 25.0.0-alpha
mcptool.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2026 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2026 Nick Fragoulis
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
32abstract class McpTool
33{
34 const RIGHTS_ENFORCED_DOWNSTREAM = 'downstream';
35
39 const RIGHTS_UNDECLARED = 'undeclared';
40
44 const NO_WRITE = '';
45
47 protected $db;
48
50 protected $user;
51
53 protected $conf;
54
62 public function __construct($db, $user, $conf)
63 {
64 $this->db = $db;
65 $this->user = $user;
66 $this->conf = $conf;
67 }
68
77 abstract public function getDefinitions(): array;
78
90 abstract public function execute(string $toolName, array $args);
91
98 public function getCategories(): array
99 {
100 return ['global']; // Default
101 }
102
117 public function isSystem()
118 {
119 return false;
120 }
121
137 public function getRequiredRights(string $toolName)
138 {
140 }
153 public function writeConfirmationPreview(string $toolName, array $args)
154 {
155 return self::NO_WRITE;
156 }
157}
Abstract base class for all MCP (Model Context Protocol) tools.
execute(string $toolName, array $args)
Execute a specific tool.
writeConfirmationPreview(string $toolName, array $args)
Preview of what a call would write, or NO_WRITE for a read tool.
getDefinitions()
Return the list of tools provided by this class.
__construct($db, $user, $conf)
Constructor.
const RIGHTS_UNDECLARED
Default of getRequiredRights(): the class never declared anything, deny.
isSystem()
Return true if this is a system/infrastructure tool that must always remain visible and executable re...
getRequiredRights(string $toolName)
Rights the caller must hold to run a tool of this class.
const NO_WRITE
Returned by writeConfirmationPreview() when the tool writes nothing.
getCategories()
Return categories this tool belongs to.
conf($dolibarr_main_document_root, $realpathconf=null)
Load conf file (file must exists)
Definition inc.php:431
$conf db user
Active Directory does not allow anonymous connections.
Definition repair.php:141