Skip to content
docsv0.1.0

McpException

Base exception for MCP Client errors. All MCP-related exceptions extend this class, allowing for easy catch-all error handling while also enabling granular exception handling when needed.

McpException::__construct()

public function __construct(string $message, ?string $serverName = null, int $code = 0, ?Throwable $previous = null):

Parameters

Parameters of __construct()
NameTypeDescription
$messagestringException message
$serverName(string | null)Name of the MCP server (for context in error messages)
$codeintException code
$previous(\Throwable | null)Previous exception for chaining

McpException::getServerName()

public function getServerName(): ?string

Get the server name associated with this exception.