MCP PHP SDK

Error implements MessageInterface

A response to a request that indicates an error occurred.

Tags
author

Kyrian Obikwelu koshnawaza@gmail.com

Table of Contents

Interfaces

MessageInterface
Refers to any valid JSON-RPC object that can be decoded off the wire, or encoded to be sent.

Constants

HEADER_MISMATCH  : mixed = -32020
Values in the HTTP headers contradict the request body, or a required header is missing or malformed. Answered with `400 Bad Request`.
INTERNAL_ERROR  : mixed = -32603
INVALID_PARAMS  : mixed = -32602
INVALID_REQUEST  : mixed = -32600
METHOD_NOT_FOUND  : mixed = -32601
MISSING_REQUIRED_CLIENT_CAPABILITY  : mixed = -32021
Handling the request needs a client capability the client never declared.
PARSE_ERROR  : mixed = -32700
RESOURCE_NOT_FOUND  : mixed = -32002
SERVER_ERROR  : mixed = -32000
UNSUPPORTED_PROTOCOL_VERSION  : mixed = -32022
The request's protocol version is unknown to this server, or is a version it has chosen not to implement. Answered with `400 Bad Request`.

Properties

$code  : int
$data  : mixed
$id  : string|int|null
$message  : string

Methods

__construct()  : mixed
forHeaderMismatch()  : self
forInternalError()  : self
forInvalidParams()  : self
forInvalidRequest()  : self
forMethodNotFound()  : self
forMissingRequiredClientCapability()  : self
forParseError()  : self
forResourceNotFound()  : self
forServerError()  : self
forUnsupportedProtocolVersion()  : self
The client is expected to pick a mutually supported version out of $supported and retry, so the list travels with the error rather than only in the message.
fromArray()  : self
getId()  : string|int|null
jsonSerialize()  : array{jsonrpc: string, id?: string|int, error: array{code: int, message: string, data?: mixed}}

Constants

HEADER_MISMATCH

Values in the HTTP headers contradict the request body, or a required header is missing or malformed. Answered with `400 Bad Request`.

public mixed HEADER_MISMATCH = -32020

INTERNAL_ERROR

public mixed INTERNAL_ERROR = -32603

INVALID_PARAMS

public mixed INVALID_PARAMS = -32602

INVALID_REQUEST

public mixed INVALID_REQUEST = -32600

METHOD_NOT_FOUND

public mixed METHOD_NOT_FOUND = -32601

MISSING_REQUIRED_CLIENT_CAPABILITY

Handling the request needs a client capability the client never declared.

public mixed MISSING_REQUIRED_CLIENT_CAPABILITY = -32021

Answered with 400 Bad Request.

PARSE_ERROR

public mixed PARSE_ERROR = -32700

RESOURCE_NOT_FOUND

public mixed RESOURCE_NOT_FOUND = -32002

SERVER_ERROR

public mixed SERVER_ERROR = -32000

UNSUPPORTED_PROTOCOL_VERSION

The request's protocol version is unknown to this server, or is a version it has chosen not to implement. Answered with `400 Bad Request`.

public mixed UNSUPPORTED_PROTOCOL_VERSION = -32022

Properties

$code read-only

public int $code

$data read-only

public mixed $data = null

$id read-only

public string|int|null $id

$message read-only

public string $message

Methods

__construct()

public __construct(string|int|null $id, int $code, string $message[, mixed|null $data = null ]) : mixed
Parameters
$id : string|int|null

The id of the request this answers. null only when it could not be read — a malformed body, or a notification that was refused — in which case the member is omitted rather than sent as an id nobody issued.

$code : int

the error type that occurred

$message : string

a short description of the error

$data : mixed|null = null

additional information about the error

forHeaderMismatch()

public final static forHeaderMismatch(string $message[, string|int|null $id = null ]) : self
Parameters
$message : string
$id : string|int|null = null
Return values
self

forInternalError()

public final static forInternalError(string $message[, string|int|null $id = null ]) : self
Parameters
$message : string
$id : string|int|null = null
Return values
self

forInvalidParams()

public final static forInvalidParams(string $message[, string|int|null $id = null ][, mixed $data = null ]) : self
Parameters
$message : string
$id : string|int|null = null
$data : mixed = null
Return values
self

forInvalidRequest()

public final static forInvalidRequest(string $message[, string|int|null $id = null ]) : self
Parameters
$message : string
$id : string|int|null = null
Return values
self

forMethodNotFound()

public final static forMethodNotFound(string $message[, string|int|null $id = null ]) : self
Parameters
$message : string
$id : string|int|null = null
Return values
self

forMissingRequiredClientCapability()

public final static forMissingRequiredClientCapability(string $message, ClientCapabilities $requiredCapabilities[, string|int|null $id = null ]) : self
Parameters
$message : string
$requiredCapabilities : ClientCapabilities

the capabilities the server needs to process the request

$id : string|int|null = null
Return values
self

forParseError()

public final static forParseError(string $message[, string|int|null $id = null ]) : self
Parameters
$message : string
$id : string|int|null = null
Return values
self

forResourceNotFound()

public final static forResourceNotFound(string $message[, string|int|null $id = null ]) : self
Parameters
$message : string
$id : string|int|null = null
Return values
self

forServerError()

public final static forServerError(string $message[, string|int|null $id = null ]) : self
Parameters
$message : string
$id : string|int|null = null
Return values
self

forUnsupportedProtocolVersion()

The client is expected to pick a mutually supported version out of $supported and retry, so the list travels with the error rather than only in the message.

public final static forUnsupportedProtocolVersion(string $requested, array<int, ProtocolVersion$supported[, string|int|null $id = null ]) : self
Parameters
$requested : string
$supported : array<int, ProtocolVersion>

versions this server does support

$id : string|int|null = null
Return values
self

fromArray()

public final static fromArray(ErrorData $data) : self
Parameters
$data : ErrorData
Return values
self

getId()

public getId() : string|int|null
Return values
string|int|null

jsonSerialize()

public jsonSerialize() : array{jsonrpc: string, id?: string|int, error: array{code: int, message: string, data?: mixed}}
Return values
array{jsonrpc: string, id?: string|int, error: array{code: int, message: string, data?: mixed}}
On this page

Search results