41require
'../../main.inc.php';
51require_once DOL_DOCUMENT_ROOT .
'/core/lib/admin.lib.php';
52require_once DOL_DOCUMENT_ROOT .
'/core/class/html.form.class.php';
53require_once DOL_DOCUMENT_ROOT .
'/ai/lib/ai.lib.php';
54require_once DOL_DOCUMENT_ROOT .
'/ai/class/mcp.class.php';
55require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
57$langs->loadLangs(array(
'admin',
'other',
'main'));
68$action =
GETPOST(
'action',
'aZ09');
69$toolcontext =
GETPOST(
'toolcontext',
'alpha');
70$toolname =
GETPOST(
'toolname',
'alpha');
71$mode =
GETPOST(
'mode',
'alpha');
72$backtopage =
GETPOST(
'backtopage',
'alpha');
86 $tool = $handler->toolsByName[$name] ??
null;
87 if (is_object($tool) && method_exists($tool,
'writeConfirmationPreview') && $tool->writeConfirmationPreview($name, array()) !==
McpTool::NO_WRITE) {
91 return (
bool) preg_match(
'/^(create|update|delete|add|remove|change|write|edit|validate|pay|send)/i', $name);
94$mcpHandler =
new McpHandler($db, $user,
$conf, McpHandler::CTX_ASSISTANT);
95$mcpHandler->loadTools();
97$unfilteredSchema = $mcpHandler->getToolsSchemaUnfiltered();
100$allDiscoveredTools = array();
101$groupedNormalTools = array();
102$groupedSystemTools = array();
104if (!empty($unfilteredSchema) && is_array($unfilteredSchema)) {
105 foreach ($unfilteredSchema as $def) {
106 $name = $def[
'name'];
107 $isSystem = !empty($def[
'is_system']);
108 $classNameKey = !empty($def[
'class_name']) ? (string) $def[
'class_name'] :
'DefaultTools';
111 $allDiscoveredTools[] = $name;
112 $groupedNormalTools[$classNameKey][] = $def;
114 $groupedSystemTools[$classNameKey][] = $def;
131if ($action ==
'addrights' || $action ==
'delrights') {
132 if (
GETPOST(
'token',
'alpha') !== $_SESSION[
'token']) {
136 if (!empty($toolcontext) && !empty($toolname)) {
137 if ($toolcontext ===
'ast') {
138 if ($action ==
'addrights') {
139 if (!in_array($toolname, $astAllowed,
true)) {
140 $astAllowed[] = $toolname;
143 $astAllowed = array_values(array_diff($astAllowed, array($toolname)));
145 $val = empty($astAllowed) ?
'NONE' : implode(
',', $astAllowed);
149 if ($toolcontext ===
'mcp') {
150 if ($action ==
'addrights') {
151 if (!in_array($toolname, $mcpAllowed,
true)) {
152 $mcpAllowed[] = $toolname;
155 $mcpAllowed = array_values(array_diff($mcpAllowed, array($toolname)));
157 $val = empty($mcpAllowed) ?
'NONE' : implode(
',', $mcpAllowed);
164 header(
'Location: ' . $_SERVER[
'PHP_SELF'] . ($page_y > 0 ?
'?page_y=' . $page_y :
''));
168if ($action ==
'apply_preset' && !empty($toolcontext) && !empty($mode)) {
169 if (
GETPOST(
'token',
'alpha') !== $_SESSION[
'token']) {
173 $resultSet = array();
175 if ($mode ===
'all') {
176 $resultSet = $allDiscoveredTools;
177 } elseif ($mode ===
'none') {
178 $resultSet = array();
179 } elseif ($mode ===
'readonly') {
180 foreach ($allDiscoveredTools as $tName) {
182 $resultSet[] = $tName;
187 $val = empty($resultSet) ?
'NONE' : implode(
',', $resultSet);
188 $constTarget = ($toolcontext ===
'mcp') ?
'AI_MCP_SERVER_ALLOWED_TOOLS' :
'AI_ASSISTANT_ALLOWED_TOOLS';
191 header(
'Location: ' . $_SERVER[
'PHP_SELF']);
202llxHeader(
'', $langs->trans($title),
'',
'', 0, 0, array(
'/ai/js/ai.js'), array(),
'',
'mod-ai page-admin');
204$linkback =
'<a href="' . ($backtopage ? $backtopage : DOL_URL_ROOT .
'/admin/modules.php?restore_lastsearch_values=1') .
'">' . img_picto($langs->trans(
"BackToModuleList"),
'back',
'class="pictofixedwidth"') .
'<span class="hideonsmartphone">' . $langs->trans(
"BackToModuleList") .
'</span></a>';
211print
'<!-- Tools quick setup -->';
212print
'<div class="info">' . $langs->trans(
"ToolAccessControlHelp") .
'<br>' . $langs->trans(
"ToolAccessControlHelp2") .
'</div>';
214print
'<div class="marginleftonly" style="display:flex; flex-wrap:wrap; gap:40px; margin-top:15px; padding-top:15px;">';
218print
'<strong>' . $langs->trans(
'PresetsForChatAssistant') .
'</strong><br>';
219print
'<a class="button" href="' .
dolBuildUrl($_SERVER[
'PHP_SELF'], array(
'action' =>
'apply_preset',
'toolcontext' =>
'ast',
'mode' =>
'none'),
true) .
'" style="margin:4px 2px;">' . $langs->trans(
'None') .
'</a>';
220print
'<a class="button" href="' .
dolBuildUrl($_SERVER[
'PHP_SELF'], array(
'action' =>
'apply_preset',
'toolcontext' =>
'ast',
'mode' =>
'readonly'),
true) .
'" style="margin:4px 2px;">' . $langs->trans(
'ViewOnly') .
'</a>';
221print
'<a class="button" href="' .
dolBuildUrl($_SERVER[
'PHP_SELF'], array(
'action' =>
'apply_preset',
'toolcontext' =>
'ast',
'mode' =>
'all'),
true) .
'" style="margin:4px 2px;">' . $langs->trans(
'AllTools') .
'</a>';
226print
'<strong>' . $langs->trans(
'PresetsForMcpServer') .
'</strong><br>';
227print
'<a class="button" href="' .
dolBuildUrl($_SERVER[
'PHP_SELF'], array(
'action' =>
'apply_preset',
'toolcontext' =>
'mcp',
'mode' =>
'none'),
true) .
'" style="margin:4px 2px;">' . $langs->trans(
'None') .
'</a>';
228print
'<a class="button" href="' .
dolBuildUrl($_SERVER[
'PHP_SELF'], array(
'action' =>
'apply_preset',
'toolcontext' =>
'mcp',
'mode' =>
'readonly'),
true) .
'" style="margin:4px 2px;">' . $langs->trans(
'ViewOnly') .
'</a>';
229print
'<a class="button" href="' .
dolBuildUrl($_SERVER[
'PHP_SELF'], array(
'action' =>
'apply_preset',
'toolcontext' =>
'mcp',
'mode' =>
'all'),
true) .
'" style="margin:4px 2px;">' . $langs->trans(
'AllTools') .
'</a>';
237print
'<div class="div-table-responsive-no-min">';
238print
'<table class="noborder centpercent" id="toolsTable">';
239print
'<tr class="liste_titre">';
240print
'<td class="tdoverflowmax250" style="min-width: 130px;">' . $langs->trans(
'Tool') .
'</td>';
241print
'<td class="hideonsmartphone">' . $langs->trans(
'ToolDescription') .
'</td>';
242print
'<td class="center" style="min-width: 60px;">' . $langs->trans(
'ToolActionType') .
'</td>';
243print
'<td class="center nowraponall">' . $langs->trans(
'ChatAssistant') .
'</td>';
244print
'<td class="center nowraponall">' . $langs->trans(
'McpServer') .
'</td>';
247if (empty($groupedNormalTools) && empty($groupedSystemTools)) {
248 print
'<tr class="oddeven"><td colspan="5" class="opacitymedium">' . $langs->trans(
'NoMcpToolsDiscovered') .
'</td></tr>';
251 $finalGroupsList = array_merge($groupedNormalTools, $groupedSystemTools);
253 foreach ($finalGroupsList as $categoryName => $definitions) {
256 print
'<tr class="trgroup trforbreaknobg" data-group="group-' . $groupId .
'">';
257 print
'<td colspan="5" class="mcp-trigger-collapse" style="cursor:pointer;">';
262 foreach ($definitions as $def) {
263 $name = $def[
'name'];
264 $desc = !empty($def[
'description']) ? $def[
'description'] :
'-';
265 $isSystem = !empty($def[
'is_system']);
267 $isAstOn = $isSystem ? true : in_array($name, $astAllowed,
true);
268 $isMcpOn = $isSystem ? true : in_array($name, $mcpAllowed,
true);
272 $typeBadge =
'<span class="badge badge-status2" style="display: inline-block;">' . $langs->trans(
'Modify') .
'</span>';
275 $typeBadge =
'<span class="badge badge-status4" style="display: inline-block;">' . $langs->trans(
'ViewOnly') .
'</span>';
278 print
'<tr class="oddeven group-' . $groupId .
'" data-tool-name="' .
dol_escape_htmltag($name) .
'" data-tool-type="' . $type .
'">';
281 print
'<td style="padding-left:20px; min-width: 130px; word-break: break-all;" class="tdoverflowmax250">';
284 print
'<br><span class="badgeneutral">' . $langs->trans(
'System') .
'</span>';
289 print
'<td class="small opacitymedium hideonsmartphone">' .
dol_escape_htmltag($desc) .
'</td>';
292 print
'<td class="center">' . $typeBadge .
'</td>';
295 $lockCssClass = $isSystem ?
' opacitymedium disabled' :
'';
298 print
'<td class="center nowraponall">';
300 print img_picto($langs->trans(
'Active'),
'switch_on',
'', 0, 0, 0,
'',
'opacitymedium');
302 $actAst = $isAstOn ?
'delrights' :
'addrights';
303 $pictoAst = $isAstOn ?
'switch_on'.($type ==
'write' ?
'_warning' :
'') :
'switch_off';
306 'toolcontext' =>
'ast',
310 print
'<a class="ctx-ast-link reposition' . $lockCssClass . (($isAstOn && !$astEnabled) ?
' opacitymedium' :
'') .
'" href="' . $urlAst .
'">';
311 print img_picto($langs->trans($isAstOn ?
'Remove' :
'Add'), $pictoAst,
'', 0, 0, 0,
'', !$isAstOn ?
'font-status6' : ($type ==
'write' ?
'font-status2' :
'font-status4'));
317 print
'<td class="center nowraponall">';
319 print img_picto($langs->trans(
'Active'),
'switch_on',
'', 0, 0, 0,
'',
'opacitymedium');
321 $actMcp = $isMcpOn ?
'delrights' :
'addrights';
322 $pictoMcp = $isMcpOn ?
'switch_on'.($type ==
'write' ?
'_warning' :
'') :
'switch_off';
325 'toolcontext' =>
'mcp',
329 print
'<a class="ctx-mcp-link reposition' . $lockCssClass . (($isMcpOn && !$mcpEnabled) ?
' opacitymedium' :
'') .
'" href="' . $urlMcp .
'">';
330 print img_picto($langs->trans($isMcpOn ?
'Remove' :
'Add'), $pictoMcp,
'', 0, 0, 0,
'', !$isMcpOn ?
'font-status6' : ($type ==
'write' ?
'font-status2' :
'font-status4'));
335 print
'</tr>' .
"\n";
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
aiAdminPrepareHead()
Prepare admin pages header.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to handle MCP (Model Context Protocol).
static resolveAllowList($raw, $allDiscoveredTools)
Resolves a raw allow-list constant value into an explicit PHP array of tool names.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.