|
dolibarr 25.0.0-alpha
|

Public Member Functions | |
| __construct ($db, $conf, $user) | |
| Constructor. | |
| getHttpStatus () | |
| HTTP status code the transport must use for the last handled request. | |
| validateTransportHeaders (array $headers, array $request) | |
| Validate the spec 2026-07-28 transport headers against the request body. | |
| handleRequest (array $request) | |
| JSON-RPC 2.0 Router. | |
Private Member Functions | |
| handleInitialize (array $params) | |
| Handles the 'initialize' request. | |
| serverCapabilities () | |
| Capabilities shared by initialize and server/discover. | |
| handleDiscover () | |
| Handles the 'server/discover' request (spec 2026-07-28, mandatory). | |
| 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 42 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 537 of file mcp_protocol.class.php.
Referenced by handleRequest(), and validateTransportHeaders().
| MCPServer::getHttpStatus | ( | ) |
HTTP status code the transport must use for the last handled request.
Definition at line 98 of file mcp_protocol.class.php.
|
private |
Handles the 'server/discover' request (spec 2026-07-28, mandatory).
All fields below are required by the DiscoverResult schema; resultType is injected by successResponse() like on every other result.
Definition at line 285 of file mcp_protocol.class.php.
References serverCapabilities().
Referenced by handleRequest().
|
private |
Handles the 'initialize' request.
| array<string,mixed> | $params Initialization parameters from the client. |
Definition at line 245 of file mcp_protocol.class.php.
References serverCapabilities().
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 450 of file mcp_protocol.class.php.
References $prod.
Referenced by handleRequest().
|
private |
Handles the 'prompts/list' request.
Definition at line 430 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 165 of file mcp_protocol.class.php.
References dol_syslog(), errorResponse(), handleDiscover(), 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 395 of file mcp_protocol.class.php.
Referenced by handleRequest().
|
private |
Handles the 'resources/list' request.
Definition at line 370 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 324 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 305 of file mcp_protocol.class.php.
Referenced by handleRequest().
|
private |
Capabilities shared by initialize and server/discover.
The 'logging' capability was dropped (deprecated in spec 2026-07-28 and this server never emitted notifications/message).
Definition at line 269 of file mcp_protocol.class.php.
Referenced by handleDiscover(), and handleInitialize().
|
private |
Creates a successful JSON-RPC response.
| mixed | $result | The result data to include in the response. |
Definition at line 509 of file mcp_protocol.class.php.
Referenced by handleRequest().
| MCPServer::validateTransportHeaders | ( | array | $headers, |
| array | $request ) |
Validate the spec 2026-07-28 transport headers against the request body.
Enforcement is presence-based for backward compatibility: a 2025-11-25 client sending no Mcp-* headers is untouched, but any header that IS present must agree with the body (HeaderMismatchError -32020, HTTP 400) and any protocol version named must be one we support (UnsupportedProtocolVersionError -32022, HTTP 400). This is also the enforcement point the Rate Limiting roadmap item keys on: proxies can throttle per-tool on Mcp-Method/Mcp-Name without parsing bodies, because we guarantee here that the headers never lie about the body.
| array<string,string> | $headers HTTP request headers (any case) |
| array<string,mixed> | $request Decoded JSON-RPC request body |
Definition at line 119 of file mcp_protocol.class.php.
References errorResponse().