abstract class Server mixin PendingTestResponse

Traits

Constants

CAPABILITY_TOOLS

CAPABILITY_RESOURCES

CAPABILITY_PROMPTS

CAPABILITY_COMPLETIONS

CACHEABLE_METHODS

Properties

static protected array<string, null|list<object>|object> $attributeCache from  ReadsAttributes
protected string $name
protected string $version
protected string $instructions
protected array<int, string> $supportedProtocolVersion
protected Extension> $extensions
protected array<string, array<string, bool>|stdClass|string> $capabilities
protected array<int|Tool>|Tool>|Tool>|Tool> $tools
protected Resource>|Resource> $resources
protected Prompt>|Prompt> $prompts
int $maxPaginationLength
int $defaultPaginationLength
protected Method>> $methods

Methods

mixed
resolveAttribute(string $attributeClass)

Resolve the nearest matching attribute in the class hierarchy.

array
resolveAttributes(string $attributeClass)

Resolve all matching attributes in the class hierarchy.

static void
flushState()

Flush all static state.

array
resolvedIcons()

Resolve icons from attributes and the primitive's icons method.

from  HasIcons
resolveResource(string|null $uri, ServerContext $context)

Resolve a resource by URI or URI template.

__construct(Transport $transport)

Create a server for the given transport.

void
addCapability(string $key, bool $value = true)

Add or modify a server capability.

void
addMethod(string $method, string $handler)

Register a custom JSON-RPC method handler.

void
start()

Boot the server and register its incoming message handler.

void
boot()

Bootstrap the server.

void
handle(string $rawMessage)

Handle an incoming JSON-RPC message.

void
sendException(Throwable $exception, ServerContext $context, int|string|null $requestId)

Send a terminal failure from eager or streamed request handling.

createContext()

Create the context for one incoming message.

array
icons()

Return the server's icons.

void
validateProtocolMeta(JsonRpcRequest $request, ServerContext $context)

Validate the protocol metadata on a modern request.

void
handleMessage(JsonRpcRequest $request, ServerContext $context)

Invoke the method and deliver its eager or streamed response.

streamResponses(iterable $response, JsonRpcRequest $request, ServerContext $context)

Produce responses through the existing send extension point.

void
send(JsonRpcResponse $response, ServerContext $context, JsonRpcRequest|null $request = null)

Add result metadata and send the response through the transport.

array
cacheHints()

Return method-specific cache hints.

array
resolveCacheHints(JsonRpcRequest $request, ServerContext $context)

Resolve the cache hints for a successful result.

Cacheable|null
resourceCacheable(JsonRpcRequest $request, ServerContext $context)

Resolve cache hints from the resource selected for this message.

iterable|JsonRpcResponse
runMethodHandle(JsonRpcRequest $request, ServerContext $context)

Invoke a method under its request context.

array
resolvedCapabilities()

Resolve the advertised server capabilities and extensions.

void
detectUiCapability()

Enable the UI extension when an App resource is registered.

__callStatic(string $name, array $arguments)

Start a server test invocation.

Details

in ReadsAttributes at line 24
protected mixed resolveAttribute(string $attributeClass)

Resolve the nearest matching attribute in the class hierarchy.

Parameters

string $attributeClass

Return Value

mixed

in ReadsAttributes at line 56
protected array resolveAttributes(string $attributeClass)

Resolve all matching attributes in the class hierarchy.

Parameters

string $attributeClass

Return Value

array

in ReadsAttributes at line 82
static void flushState()

Flush all static state.

Return Value

void

in HasIcons at line 19
array resolvedIcons()

Resolve icons from attributes and the primitive's icons method.

Return Value

array

in ResolvesResources at line 17
protected Resource resolveResource(string|null $uri, ServerContext $context)

Resolve a resource by URI or URI template.

Parameters

string|null $uri
ServerContext $context

Return Value

Resource

at line 155
__construct(Transport $transport)

Create a server for the given transport.

Parameters

Transport $transport

at line 166
void addCapability(string $key, bool $value = true)

Add or modify a server capability.

Using dot notation like "feature.enabled" will create a nested capability array. Passing a single key like "anotherFeature" will register an empty object capability.

Parameters

string $key
bool $value

Return Value

void

at line 191
void addMethod(string $method, string $handler)

Register a custom JSON-RPC method handler.

Parameters

string $method
string $handler

Return Value

void

at line 199
void start()

Boot the server and register its incoming message handler.

Return Value

void

at line 210
protected void boot()

Bootstrap the server.

Return Value

void

at line 217
void handle(string $rawMessage)

Handle an incoming JSON-RPC message.

Parameters

string $rawMessage

Return Value

void

at line 268
protected void sendException(Throwable $exception, ServerContext $context, int|string|null $requestId)

Send a terminal failure from eager or streamed request handling.

Parameters

Throwable $exception
ServerContext $context
int|string|null $requestId

Return Value

void

at line 307
ServerContext createContext()

Create the context for one incoming message.

Return Value

ServerContext

at line 335
protected array icons()

Return the server's icons.

Return Value

array

at line 345
protected void validateProtocolMeta(JsonRpcRequest $request, ServerContext $context)

Validate the protocol metadata on a modern request.

Parameters

JsonRpcRequest $request
ServerContext $context

Return Value

void

Exceptions

JsonRpcException

at line 384
protected void handleMessage(JsonRpcRequest $request, ServerContext $context)

Invoke the method and deliver its eager or streamed response.

Parameters

JsonRpcRequest $request
ServerContext $context

Return Value

void

Exceptions

JsonRpcException

at line 415
protected Generator streamResponses(iterable $response, JsonRpcRequest $request, ServerContext $context)

Produce responses through the existing send extension point.

Parameters

iterable $response
JsonRpcRequest $request
ServerContext $context

Return Value

Generator

at line 431
protected void send(JsonRpcResponse $response, ServerContext $context, JsonRpcRequest|null $request = null)

Add result metadata and send the response through the transport.

Parameters

JsonRpcResponse $response
ServerContext $context
JsonRpcRequest|null $request

Return Value

void

at line 452
protected array cacheHints()

Return method-specific cache hints.

Return Value

array

at line 462
protected array resolveCacheHints(JsonRpcRequest $request, ServerContext $context)

Resolve the cache hints for a successful result.

Parameters

JsonRpcRequest $request
ServerContext $context

Return Value

array

at line 483
protected Cacheable|null resourceCacheable(JsonRpcRequest $request, ServerContext $context)

Resolve cache hints from the resource selected for this message.

Parameters

JsonRpcRequest $request
ServerContext $context

Return Value

Cacheable|null

at line 507
protected iterable|JsonRpcResponse runMethodHandle(JsonRpcRequest $request, ServerContext $context)

Invoke a method under its request context.

Parameters

JsonRpcRequest $request
ServerContext $context

Return Value

iterable|JsonRpcResponse

Exceptions

JsonRpcException

at line 524
protected array resolvedCapabilities()

Resolve the advertised server capabilities and extensions.

Return Value

array

at line 539
protected void detectUiCapability()

Enable the UI extension when an App resource is registered.

Return Value

void

at line 551
static PendingTestResponse|TestResponse|TestListResponse __callStatic(string $name, array $arguments)

Start a server test invocation.

Parameters

string $name
array $arguments

Return Value

PendingTestResponse|TestResponse|TestListResponse