|
dolibarr 24.0.0-beta
|
Public Member Functions | |
| __construct ($db, $conf, $user) | |
| Constructor. | |
| handleRequest (array $request) | |
| JSON-RPC 2.0 Router. | |
Private Member Functions | |
| handleInitialize (array $params) | |
| Handles the 'initialize' request. | |
| handleToolsList () | |
| Handles the 'tools/list' request by delegating to McpHandler. | |
| handleToolCall (array $params) | |
| Handles the 'tools/call' request by delegating to McpHandler. | |
| handleResourcesList () | |
| Handles the 'resources/list' request. | |
| handleResourceRead (array $params) | |
| Handles the 'resources/read' request. | |
| handlePromptsList () | |
| Handles the 'prompts/list' request. | |
| handlePromptGet (array $params) | |
| Handles the 'prompts/get' request. | |
| successResponse ($result) | |
| Creates a successful JSON-RPC response. | |
| errorResponse (int $code, string $message, $data=null) | |
| Creates an error JSON-RPC response. | |
MCPServer Class.
This class acts as a thin protocol layer for the Model Context Protocol. It handles JSON-RPC 2.0 requests and delegates all tool-related operations (discovery, loading, execution) to McpHandler engine.
Instantiates McpHandler with CTX_MCP_SERVER so that the public allow-list (AI_MCP_SERVER_ALLOWED_TOOLS) is applied — tools disabled by the admin are invisible in tools/list responses and blocked at tools/call execution.
Definition at line 41 of file mcp_protocol.class.php.
| MCPServer::__construct | ( | $db, | |
| $conf, | |||
| $user ) |
|
private |
Creates an error JSON-RPC response.
| int | $code | The error code. |
| string | $message | The error message. |
| mixed | $data | Optional error data. |
Definition at line 390 of file mcp_protocol.class.php.
Referenced by handleRequest().
|
private |
Handles the 'initialize' request.
| array<string,mixed> | $params Initialization parameters from the client. |
Definition at line 149 of file mcp_protocol.class.php.
Referenced by handleRequest().
|
private |
Handles the 'prompts/get' request.
| array{name? | string, arguments?: array<string, mixed>} $params Parameters containing the prompt name and arguments. |
| Exception | If the prompt name is not found. |
Definition at line 310 of file mcp_protocol.class.php.
References $prod.
Referenced by handleRequest().
|
private |
Handles the 'prompts/list' request.
Definition at line 290 of file mcp_protocol.class.php.
Referenced by handleRequest().
| MCPServer::handleRequest | ( | array | $request | ) |
JSON-RPC 2.0 Router.
Routes incoming requests to the appropriate handler method.
| array{jsonrpc? | string, method?: string, params?: array<mixed>, id?: string|int|null} $request The decoded JSON-RPC request array. |
| Exception | On processing errors. |
Definition at line 89 of file mcp_protocol.class.php.
References dol_syslog(), errorResponse(), handleInitialize(), handlePromptGet(), handlePromptsList(), handleResourceRead(), handleResourcesList(), handleToolCall(), handleToolsList(), and successResponse().
|
private |
Handles the 'resources/read' request.
| array{uri? | string} $params Parameters containing the URI of the resource to read. |
| Exception | If the resource URI is not found. |
Definition at line 255 of file mcp_protocol.class.php.
Referenced by handleRequest().
|
private |
Handles the 'resources/list' request.
Definition at line 230 of file mcp_protocol.class.php.
Referenced by handleRequest().
|
private |
Handles the 'tools/call' request by delegating to McpHandler.
Execution is blocked for any tool not in AI_MCP_SERVER_ALLOWED_TOOLS, even if the client sends the request directly without consulting tools/list.
| array{name? | string, arguments?: array<string, mixed>} $params Parameters containing the tool name and arguments. |
| Exception | If the tool is blocked, not found or execution fails. |
Definition at line 192 of file mcp_protocol.class.php.
Referenced by handleRequest().
|
private |
Handles the 'tools/list' request by delegating to McpHandler.
Only tools permitted by AI_MCP_SERVER_ALLOWED_TOOLS are returned.
Definition at line 173 of file mcp_protocol.class.php.
Referenced by handleRequest().
|
private |
Creates a successful JSON-RPC response.
| mixed | $result | The result data to include in the response. |
Definition at line 369 of file mcp_protocol.class.php.
Referenced by handleRequest().