dolibarr 24.0.0-beta
conversation.class.php
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
30{
37 public function getDefinitions(): array
38 {
39 return [
40 [
41 "name" => "ask_for_clarification",
42 "description" => "Asks the user for more information needed to complete a Dolibarr ERP-related task. The client-side JavaScript will append the user's response at the end of the original query to maintain context. Only use this when the question is clearly about Dolibarr ERP.",
43
44 "inputSchema" => [
45 "type" => "object",
46 "properties" => [
47 "question" => [
48 "type" => "string",
49 "description" => "The specific question to ask the user about Dolibarr ERP."
50 ]
51 ],
52 "required" => ["question"]
53 ]
54 ],
55 [
56 "name" => "respond_to_user",
57 "description" => "Sends a one-way informational message to the user about Dolibarr ERP objects and functions ONLY. This tool is strictly restricted to displaying information or errors related to Dolibarr ERP. Do NOT use this tool for general knowledge questions, personal advice, or topics unrelated to Dolibarr ERP.",
58 "inputSchema" => [
59 "type" => "object",
60 "properties" => [
61 "message" => [
62 "type" => "string",
63 "description" => "The informational message to display to the user."
64 ]
65 ],
66 "required" => ["message"]
67 ]
68 ],
69 [
70 "name" => "ask_for_confirmation",
71 "description" => "Asks the user to confirm a destructive or critical action before proceeding. The client-side JavaScript will store the original intent and re-execute it if the user confirms.",
72 "inputSchema" => [
73 "type" => "object",
74 "properties" => [
75 "action" => [
76 "type" => "string",
77 "description" => "A short, verb-based description of the action (e.g., 'delete invoice')."
78 ],
79 "details" => [
80 "type" => "string",
81 "description" => "A clear, human-readable summary of what will be affected."
82 ]
83 ],
84 "required" => ["action", "details"]
85 ]
86 ],
87 [
88 "name" => "reject_general_question",
89 "description" => "Use this tool when the user asks a question that is not related to Dolibarr ERP objects and functions. This tool should not be used for any general knowledge questions, personal advice, or topics outside the scope of Dolibarr ERP.",
90 "inputSchema" => [
91 "type" => "object",
92 "properties" => [
93 "message" => [
94 "type" => "string",
95 "description" => "A polite message explaining that you can only answer questions about Dolibarr ERP."
96 ]
97 ],
98 "required" => ["message"]
99 ]
100 ]
101 ];
102 }
103
110 public function getCategories(): array
111 {
112 return ['global'];
113 }
114
128 public function isSystem()
129 {
130 return true;
131 }
132
143 public function execute(string $name, array $args): ?array
144 {
145 // These tools don't require specific permissions as they are for UI control.
146 // The main application layer should handle any permission checks if needed.
147
148 switch ($name) {
149 case 'ask_for_clarification':
150 case 'respond_to_user':
151 case 'ask_for_confirmation':
152 case 'reject_general_question':
153
154 return [
155 "tool" => $name,
156 "arguments" => $args
157 ];
158
159 default:
160 return null;
161 }
162 }
163}
Abstract base class for all MCP (Model Context Protocol) tools.
getDefinitions()
Defines the conversational tools available to the AI.
execute(string $name, array $args)
Executes a conversational tool.
isSystem()
Conversation tools are system-level infrastructure.
getCategories()
Return categories this tool belongs to.