MCP PHP SDK

Builder

FinalYes
Tags
phpstan-import-type

Handler from ElementReference

author

Kyrian Obikwelu koshnawaza@gmail.com

Table of Contents

Properties

$container  : ContainerInterface|null
$discoverer  : DiscovererInterface|null
$discoveryBasePath  : string|null
$discoveryCache  : CacheInterface|null
$discoveryExcludeDirs  : array<string|int, mixed>|array<string|int, string>
$discoveryScanDirs  : array<string|int, string>
$eventDispatcher  : EventDispatcherInterface|null
$instructions  : string|null
$loaders  : array<string|int, LoaderInterface>
$logger  : LoggerInterface|null
$notificationHandlers  : array<int, NotificationHandlerInterface>
$paginationLimit  : int
$prompts  : array<string|int, Icon[], meta: ?array}>
$protocolVersion  : ProtocolVersion|null
$registry  : RegistryInterface
$requestHandlers  : array<int, RequestHandlerInterface<string|int, mixed>>
$resources  : array<string|int, Icon[], meta: ?array}>
$resourceTemplates  : array<string|int, Annotations, meta: ?array}>
$schemaGenerator  : SchemaGeneratorInterface|null
$serverCapabilities  : ServerCapabilities|null
$serverInfo  : Implementation|null
$sessionFactory  : SessionFactoryInterface|null
$sessionStore  : SessionStoreInterface|null
$sessionTtl  : int
$subscriptionManager  : SubscriptionManagerInterface|null
$tools  : array<string|int, Icon[], meta: ?array, outputSchema: ?array}>

Methods

addLoader()  : self
Register a single custom loader.
addLoaders()  : self
addNotificationHandler()  : self
Register a single custom notification handler.
addNotificationHandlers()  : self
Register multiple custom notification handlers.
addPrompt()  : self
Manually registers a prompt handler.
addRequestHandler()  : self
Register a single custom method handler.
addRequestHandlers()  : self
Register multiple custom method handlers.
addResource()  : self
Manually registers a resource handler.
addResourceTemplate()  : self
Manually registers a resource template handler.
addTool()  : self
Manually registers a tool handler.
build()  : Server
Builds the fully configured Server instance.
setCapabilities()  : self
Explicitly set server capabilities. If set, this overrides automatic detection.
setContainer()  : self
Provides a PSR-11 DI container, primarily for resolving user-defined handler classes.
setDiscoverer()  : self
setDiscovery()  : self
setEventDispatcher()  : self
setInstructions()  : self
Configures the instructions describing how to use the server and its features.
setLogger()  : self
Provides a PSR-3 logger instance. Defaults to NullLogger.
setPaginationLimit()  : self
Configures the server's pagination limit.
setProtocolVersion()  : self
setRegistry()  : self
setResourceSubscriptionManager()  : self
setSchemaGenerator()  : self
setServerInfo()  : self
Sets the server's identity. Required.
setSession()  : self
createDiscoverer()  : DiscovererInterface

Properties

$container

private ContainerInterface|null $container = null

$discoverer

private DiscovererInterface|null $discoverer = null

$discoveryBasePath

private string|null $discoveryBasePath = null

$discoveryCache

private CacheInterface|null $discoveryCache = null

$discoveryExcludeDirs

private array<string|int, mixed>|array<string|int, string> $discoveryExcludeDirs = []

$discoveryScanDirs

private array<string|int, string> $discoveryScanDirs = []

$eventDispatcher

private EventDispatcherInterface|null $eventDispatcher = null

$instructions

private string|null $instructions = null

$logger

private LoggerInterface|null $logger = null

$paginationLimit

private int $paginationLimit = 50

$prompts

private array<string|int, Icon[], meta: ?array}> $prompts = []

$resources

private array<string|int, Icon[], meta: ?array}> $resources = []

$resourceTemplates

private array<string|int, Annotations, meta: ?array}> $resourceTemplates = []

$sessionTtl

private int $sessionTtl = 3600

$tools

private array<string|int, Icon[], meta: ?array, outputSchema: ?array}> $tools = []

Methods

addPrompt()

Manually registers a prompt handler.

public addPrompt(Handler $handler[, string|null $name = null ][, string|null $description = null ][, array<string|int, Icon>|null $icons = null ][, array<string, mixed>|null $meta = null ]) : self
Parameters
$handler : Handler
$name : string|null = null
$description : string|null = null
$icons : array<string|int, Icon>|null = null
$meta : array<string, mixed>|null = null
Return values
self

addRequestHandlers()

Register multiple custom method handlers.

public addRequestHandlers(iterable<string|int, RequestHandlerInterface<string|int, mixed>> $handlers) : self
Parameters
$handlers : iterable<string|int, RequestHandlerInterface<string|int, mixed>>
Return values
self

addResource()

Manually registers a resource handler.

public addResource(Handler $handler, string $uri[, string|null $name = null ][, string|null $description = null ][, string|null $mimeType = null ][, int|null $size = null ][, Annotations|null $annotations = null ][, array<string|int, Icon>|null $icons = null ][, array<string, mixed>|null $meta = null ]) : self
Parameters
$handler : Handler
$uri : string
$name : string|null = null
$description : string|null = null
$mimeType : string|null = null
$size : int|null = null
$annotations : Annotations|null = null
$icons : array<string|int, Icon>|null = null
$meta : array<string, mixed>|null = null
Return values
self

addResourceTemplate()

Manually registers a resource template handler.

public addResourceTemplate(Handler $handler, string $uriTemplate[, string|null $name = null ][, string|null $description = null ][, string|null $mimeType = null ][, Annotations|null $annotations = null ][, array<string, mixed>|null $meta = null ]) : self
Parameters
$handler : Handler
$uriTemplate : string
$name : string|null = null
$description : string|null = null
$mimeType : string|null = null
$annotations : Annotations|null = null
$meta : array<string, mixed>|null = null
Return values
self

addTool()

Manually registers a tool handler.

public addTool(Handler $handler[, string|null $name = null ][, string|null $description = null ][, ToolAnnotations|null $annotations = null ][, array<string, mixed>|null $inputSchema = null ][, array<string|int, Icon>|null $icons = null ][, array<string, mixed>|null $meta = null ][, array<string, mixed>|null $outputSchema = null ]) : self
Parameters
$handler : Handler
$name : string|null = null
$description : string|null = null
$annotations : ToolAnnotations|null = null
$inputSchema : array<string, mixed>|null = null
$icons : array<string|int, Icon>|null = null
$meta : array<string, mixed>|null = null
$outputSchema : array<string, mixed>|null = null
Return values
self

build()

Builds the fully configured Server instance.

public build() : Server
Return values
Server

setCapabilities()

Explicitly set server capabilities. If set, this overrides automatic detection.

public setCapabilities(ServerCapabilities $serverCapabilities) : self
Parameters
$serverCapabilities : ServerCapabilities
Return values
self

setContainer()

Provides a PSR-11 DI container, primarily for resolving user-defined handler classes.

public setContainer(ContainerInterface $container) : self

Defaults to a basic internal container.

Parameters
$container : ContainerInterface
Return values
self

setDiscoverer()

public setDiscoverer(DiscovererInterface $discoverer) : self
Parameters
$discoverer : DiscovererInterface
Return values
self

setDiscovery()

public setDiscovery(string $basePath[, array<string|int, string> $scanDirs = ['.', 'src'] ][, array<string|int, string> $excludeDirs = [] ][, CacheInterface|null $cache = null ]) : self
Parameters
$basePath : string
$scanDirs : array<string|int, string> = ['.', 'src']
$excludeDirs : array<string|int, string> = []
$cache : CacheInterface|null = null
Return values
self

setEventDispatcher()

public setEventDispatcher(EventDispatcherInterface $eventDispatcher) : self
Parameters
$eventDispatcher : EventDispatcherInterface
Return values
self

setInstructions()

Configures the instructions describing how to use the server and its features.

public setInstructions(string|null $instructions) : self

This can be used by clients to improve the LLM's understanding of available tools, resources, etc. It can be thought of like a "hint" to the model. For example, this information MAY be added to the system prompt.

Parameters
$instructions : string|null
Return values
self

setLogger()

Provides a PSR-3 logger instance. Defaults to NullLogger.

public setLogger(LoggerInterface $logger) : self
Parameters
$logger : LoggerInterface
Return values
self

setPaginationLimit()

Configures the server's pagination limit.

public setPaginationLimit(int $paginationLimit) : self
Parameters
$paginationLimit : int
Return values
self

setServerInfo()

Sets the server's identity. Required.

public setServerInfo(string $name, string $version[, string|null $description = null ][, array<string|int, Icon>|null $icons = null ][, string|null $websiteUrl = null ]) : self
Parameters
$name : string
$version : string
$description : string|null = null
$icons : array<string|int, Icon>|null = null
$websiteUrl : string|null = null
Return values
self

createDiscoverer()

private createDiscoverer(LoggerInterface $logger) : DiscovererInterface
Parameters
$logger : LoggerInterface
Return values
DiscovererInterface

        
On this page

Search results