Commit inicial powerservice

This commit is contained in:
Gabriel
2026-10-19 12:45:45 -06:00
commit ad85486fe2
10158 changed files with 2736804 additions and 0 deletions
@@ -0,0 +1,338 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
<https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Moe Ghoul>, 1 April 1989
Moe Ghoul, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
@@ -0,0 +1,38 @@
{
"name": "wordpress/php-mcp-schema",
"description": "PHP DTOs for the Model Context Protocol (MCP) specification",
"type": "library",
"license": "GPL-2.0-or-later",
"keywords": [
"mcp",
"model-context-protocol",
"dto",
"schema",
"php"
],
"homepage": "https://github.com/WordPress/php-mcp-schema",
"authors": [
{
"name": "WordPress",
"homepage": "https://wordpress.org"
}
],
"require": {
"php": ">=7.4"
},
"require-dev": {
"phpstan/phpstan": "^1.10"
},
"autoload": {
"psr-4": {
"WP\\McpSchema\\": "src/"
}
},
"config": {
"sort-packages": true
},
"scripts": {
"analyse": "phpstan analyse",
"phpstan": "@analyse"
}
}
@@ -0,0 +1,146 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\DTO;
use WP\McpSchema\Client\Elicitation\Union\PrimitiveSchemaDefinitionInterface;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* @since 2025-06-18
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
class BooleanSchema extends AbstractDataTransferObject implements PrimitiveSchemaDefinitionInterface
{
use ValidatesRequiredFields;
public const TYPE = 'boolean';
public const DISCRIMINATOR_FIELD = 'type';
public const DISCRIMINATOR_VALUE = 'boolean';
/**
* @since 2025-06-18
*
* @var 'boolean'
*/
protected string $type;
/**
* @since 2025-06-18
*
* @var string|null
*/
protected ?string $title;
/**
* @since 2025-06-18
*
* @var string|null
*/
protected ?string $description;
/**
* @since 2025-06-18
*
* @var bool|null
*/
protected ?bool $default;
/**
* @param string|null $title @since 2025-06-18
* @param string|null $description @since 2025-06-18
* @param bool|null $default @since 2025-06-18
*/
public function __construct(
?string $title = null,
?string $description = null,
?bool $default = null
) {
$this->type = self::TYPE;
$this->title = $title;
$this->description = $description;
$this->default = $default;
}
/**
* Creates an instance from an array.
*
* @param array{
* type: 'boolean',
* title?: string|null,
* description?: string|null,
* default?: bool|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
return new self(
self::asStringOrNull($data['title'] ?? null),
self::asStringOrNull($data['description'] ?? null),
self::asBoolOrNull($data['default'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['type'] = $this->type;
if ($this->title !== null) {
$result['title'] = $this->title;
}
if ($this->description !== null) {
$result['description'] = $this->description;
}
if ($this->default !== null) {
$result['default'] = $this->default;
}
return $result;
}
/**
* @return 'boolean'
*/
public function getType(): string
{
return $this->type;
}
/**
* @return string|null
*/
public function getTitle(): ?string
{
return $this->title;
}
/**
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* @return bool|null
*/
public function getDefault(): ?bool
{
return $this->default;
}
}
@@ -0,0 +1,106 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\DTO;
use WP\McpSchema\Client\Elicitation\Factory\ElicitRequestParamsFactory;
use WP\McpSchema\Client\Elicitation\Union\ElicitRequestParamsInterface;
use WP\McpSchema\Common\JsonRpc\DTO\JSONRPCRequest;
use WP\McpSchema\Common\Protocol\Union\ServerRequestInterface;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* A request from the server to elicit additional information from the user via the client.
*
* @since 2025-06-18
* @last-updated 2025-11-25 (modified property: params)
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
class ElicitRequest extends JSONRPCRequest implements ServerRequestInterface
{
use ValidatesRequiredFields;
public const METHOD = 'elicitation/create';
public const DISCRIMINATOR_FIELD = 'method';
public const DISCRIMINATOR_VALUE = 'elicitation/create';
/**
* @var \WP\McpSchema\Client\Elicitation\Union\ElicitRequestParamsInterface
*/
protected ElicitRequestParamsInterface $typedParams;
/**
* @param '2.0' $jsonrpc @since 2025-11-25
* @param string|number $id @since 2025-11-25
* @param \WP\McpSchema\Client\Elicitation\Union\ElicitRequestParamsInterface $params @since 2025-06-18
*/
public function __construct(
string $jsonrpc,
$id,
ElicitRequestParamsInterface $params
) {
parent::__construct(self::METHOD, $jsonrpc, $id, null);
$this->typedParams = $params;
}
/**
* Creates an instance from an array.
*
* @param array{
* jsonrpc: '2.0',
* id: string|number,
* method: 'elicitation/create',
* params: array<string, mixed>|\WP\McpSchema\Client\Elicitation\Union\ElicitRequestParamsInterface
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['jsonrpc', 'id', 'params']);
/** @var '2.0' $jsonrpc */
$jsonrpc = self::asString($data['jsonrpc']);
/** @var string|number $id */
$id = self::asStringOrNumber($data['id']);
/** @var \WP\McpSchema\Client\Elicitation\Union\ElicitRequestParamsInterface $params */
$params = is_array($data['params'])
? ElicitRequestParamsFactory::fromArray(self::asArray($data['params']))
: $data['params'];
return new self(
$jsonrpc,
$id,
$params
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
$result['params'] = $this->typedParams->toArray();
return $result;
}
/**
* @return \WP\McpSchema\Client\Elicitation\Union\ElicitRequestParamsInterface
*/
public function getTypedParams(): ElicitRequestParamsInterface
{
return $this->typedParams;
}
}
@@ -0,0 +1,162 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\DTO;
use WP\McpSchema\Client\Elicitation\Union\ElicitRequestParamsInterface;
use WP\McpSchema\Client\Tasks\DTO\TaskMetadata;
use WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta;
use WP\McpSchema\Common\Tasks\DTO\TaskAugmentedRequestParams;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* The parameters for a request to elicit non-sensitive information from the user via a form in the client.
*
* @since 2025-11-25
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
class ElicitRequestFormParams extends TaskAugmentedRequestParams implements ElicitRequestParamsInterface
{
use ValidatesRequiredFields;
public const MODE = 'form';
public const DISCRIMINATOR_FIELD = 'mode';
public const DISCRIMINATOR_VALUE = 'form';
/**
* The elicitation mode.
*
* @since 2025-11-25
*
* @var 'form'|null
*/
protected ?string $mode;
/**
* The message to present to the user describing what information is being requested.
*
* @since 2025-11-25
*
* @var string
*/
protected string $message;
/**
* A restricted subset of JSON Schema.
* Only top-level properties are allowed, without nesting.
*
* @since 2025-11-25
*
* @var \WP\McpSchema\Client\Elicitation\DTO\ElicitRequestFormParamsRequestedSchema
*/
protected ElicitRequestFormParamsRequestedSchema $requestedSchema;
/**
* @param string $message @since 2025-11-25
* @param \WP\McpSchema\Client\Elicitation\DTO\ElicitRequestFormParamsRequestedSchema $requestedSchema @since 2025-11-25
* @param \WP\McpSchema\Client\Tasks\DTO\TaskMetadata|null $task @since 2025-11-25
* @param \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null $_meta @since 2025-11-25
*/
public function __construct(
string $message,
ElicitRequestFormParamsRequestedSchema $requestedSchema,
?TaskMetadata $task = null,
?RequestParamsMeta $_meta = null
) {
parent::__construct($_meta, $task);
$this->mode = self::MODE;
$this->message = $message;
$this->requestedSchema = $requestedSchema;
}
/**
* Creates an instance from an array.
*
* @param array{
* task?: array<string, mixed>|\WP\McpSchema\Client\Tasks\DTO\TaskMetadata|null,
* _meta?: array<string, mixed>|\WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null,
* mode?: 'form'|null,
* message: string,
* requestedSchema: array<string, mixed>|\WP\McpSchema\Client\Elicitation\DTO\ElicitRequestFormParamsRequestedSchema
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['message', 'requestedSchema']);
/** @var \WP\McpSchema\Client\Elicitation\DTO\ElicitRequestFormParamsRequestedSchema $requestedSchema */
$requestedSchema = is_array($data['requestedSchema'])
? ElicitRequestFormParamsRequestedSchema::fromArray(self::asArray($data['requestedSchema']))
: $data['requestedSchema'];
/** @var \WP\McpSchema\Client\Tasks\DTO\TaskMetadata|null $task */
$task = isset($data['task'])
? (is_array($data['task'])
? TaskMetadata::fromArray(self::asArray($data['task']))
: $data['task'])
: null;
/** @var \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null $_meta */
$_meta = isset($data['_meta'])
? (is_array($data['_meta'])
? RequestParamsMeta::fromArray(self::asArray($data['_meta']))
: $data['_meta'])
: null;
return new self(
self::asString($data['message']),
$requestedSchema,
$task,
$_meta
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
if ($this->mode !== null) {
$result['mode'] = $this->mode;
}
$result['message'] = $this->message;
$result['requestedSchema'] = $this->requestedSchema->toArray();
return $result;
}
/**
* @return 'form'|null
*/
public function getMode(): ?string
{
return $this->mode;
}
/**
* @return string
*/
public function getMessage(): string
{
return $this->message;
}
/**
* @return \WP\McpSchema\Client\Elicitation\DTO\ElicitRequestFormParamsRequestedSchema
*/
public function getRequestedSchema(): ElicitRequestFormParamsRequestedSchema
{
return $this->requestedSchema;
}
}
@@ -0,0 +1,114 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* A restricted subset of JSON Schema.
* Only top-level properties are allowed, without nesting.
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
class ElicitRequestFormParamsRequestedSchema extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
public const TYPE = 'object';
/**
* @var string|null
*/
protected ?string $schema;
/**
* @var 'object'
*/
protected string $type;
/**
* @var array<string>|null
*/
protected ?array $required;
/**
* @param string|null $schema
* @param array<string>|null $required
*/
public function __construct(
?string $schema = null,
?array $required = null
) {
$this->type = self::TYPE;
$this->schema = $schema;
$this->required = $required;
}
/**
* Creates an instance from an array.
*
* @param array{
* '$schema'?: string|null,
* type: 'object',
* required?: array<string>|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
return new self(
self::asStringOrNull($data['$schema'] ?? null),
self::asStringArrayOrNull($data['required'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
if ($this->schema !== null) {
$result['$schema'] = $this->schema;
}
$result['type'] = $this->type;
if ($this->required !== null) {
$result['required'] = $this->required;
}
return $result;
}
/**
* @return string|null
*/
public function getSchema(): ?string
{
return $this->schema;
}
/**
* @return 'object'
*/
public function getType(): string
{
return $this->type;
}
/**
* @return array<string>|null
*/
public function getRequired(): ?array
{
return $this->required;
}
}
@@ -0,0 +1,178 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\DTO;
use WP\McpSchema\Client\Elicitation\Union\ElicitRequestParamsInterface;
use WP\McpSchema\Client\Tasks\DTO\TaskMetadata;
use WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta;
use WP\McpSchema\Common\Tasks\DTO\TaskAugmentedRequestParams;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* The parameters for a request to elicit information from the user via a URL in the client.
*
* @since 2025-11-25
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
class ElicitRequestURLParams extends TaskAugmentedRequestParams implements ElicitRequestParamsInterface
{
use ValidatesRequiredFields;
public const MODE = 'url';
public const DISCRIMINATOR_FIELD = 'mode';
public const DISCRIMINATOR_VALUE = 'url';
/**
* The elicitation mode.
*
* @since 2025-11-25
*
* @var 'url'
*/
protected string $mode;
/**
* The message to present to the user explaining why the interaction is needed.
*
* @since 2025-11-25
*
* @var string
*/
protected string $message;
/**
* The ID of the elicitation, which must be unique within the context of the server.
* The client MUST treat this ID as an opaque value.
*
* @since 2025-11-25
*
* @var string
*/
protected string $elicitationId;
/**
* The URL that the user should navigate to.
*
* @since 2025-11-25
*
* @var string
*/
protected string $url;
/**
* @param string $message @since 2025-11-25
* @param string $elicitationId @since 2025-11-25
* @param string $url @since 2025-11-25
* @param \WP\McpSchema\Client\Tasks\DTO\TaskMetadata|null $task @since 2025-11-25
* @param \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null $_meta @since 2025-11-25
*/
public function __construct(
string $message,
string $elicitationId,
string $url,
?TaskMetadata $task = null,
?RequestParamsMeta $_meta = null
) {
parent::__construct($_meta, $task);
$this->mode = self::MODE;
$this->message = $message;
$this->elicitationId = $elicitationId;
$this->url = $url;
}
/**
* Creates an instance from an array.
*
* @param array{
* task?: array<string, mixed>|\WP\McpSchema\Client\Tasks\DTO\TaskMetadata|null,
* _meta?: array<string, mixed>|\WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null,
* mode: 'url',
* message: string,
* elicitationId: string,
* url: string
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['message', 'elicitationId', 'url']);
/** @var \WP\McpSchema\Client\Tasks\DTO\TaskMetadata|null $task */
$task = isset($data['task'])
? (is_array($data['task'])
? TaskMetadata::fromArray(self::asArray($data['task']))
: $data['task'])
: null;
/** @var \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null $_meta */
$_meta = isset($data['_meta'])
? (is_array($data['_meta'])
? RequestParamsMeta::fromArray(self::asArray($data['_meta']))
: $data['_meta'])
: null;
return new self(
self::asString($data['message']),
self::asString($data['elicitationId']),
self::asString($data['url']),
$task,
$_meta
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
$result['mode'] = $this->mode;
$result['message'] = $this->message;
$result['elicitationId'] = $this->elicitationId;
$result['url'] = $this->url;
return $result;
}
/**
* @return 'url'
*/
public function getMode(): string
{
return $this->mode;
}
/**
* @return string
*/
public function getMessage(): string
{
return $this->message;
}
/**
* @return string
*/
public function getElicitationId(): string
{
return $this->elicitationId;
}
/**
* @return string
*/
public function getUrl(): string
{
return $this->url;
}
}
@@ -0,0 +1,129 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\DTO;
use WP\McpSchema\Client\Lifecycle\Union\ClientResultInterface;
use WP\McpSchema\Common\Protocol\DTO\Result;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* The client's response to an elicitation request.
*
* @since 2025-06-18
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
class ElicitResult extends Result implements ClientResultInterface
{
use ValidatesRequiredFields;
/**
* Wire keys this class models. Anything else is kept in $additionalProperties.
*
* @var array<int, string>
*/
private const KNOWN_KEYS = ['_meta', 'action', 'content'];
/**
* The user action in response to the elicitation.
* - "accept": User submitted the form/confirmed the action
* - "decline": User explicitly decline the action
* - "cancel": User dismissed without making an explicit choice
*
* @since 2025-06-18
*
* @var 'accept'|'decline'|'cancel'
*/
protected string $action;
/**
* The submitted form data, only present when action is "accept" and mode was "form".
* Contains values matching the requested schema.
* Omitted for out-of-band mode responses.
*
* @since 2025-06-18
*
* @var array<string, string>|null
*/
protected ?array $content;
/**
* @param 'accept'|'decline'|'cancel' $action @since 2025-06-18
* @param array<string, mixed>|null $_meta @since 2025-06-18
* @param array<string, string>|null $content @since 2025-06-18
* @param array<string, mixed>|null $additionalProperties
*/
public function __construct(
string $action,
?array $_meta = null,
?array $content = null,
?array $additionalProperties = null
) {
parent::__construct($_meta, $additionalProperties);
$this->action = $action;
$this->content = $content;
}
/**
* Creates an instance from an array.
*
* @param array{
* _meta?: array<string, mixed>|null,
* action: 'accept'|'decline'|'cancel',
* content?: array<string, string>|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['action']);
/** @var 'accept'|'decline'|'cancel' $action */
$action = self::asString($data['action']);
return new self(
$action,
self::asArrayOrNull($data['_meta'] ?? null),
self::asStringMapOrNull($data['content'] ?? null),
self::additionalFields($data, self::KNOWN_KEYS)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
$result['action'] = $this->action;
if ($this->content !== null) {
$result['content'] = $this->content;
}
return $result;
}
/**
* @return 'accept'|'decline'|'cancel'
*/
public function getAction(): string
{
return $this->action;
}
/**
* @return array<string, string>|null
*/
public function getContent(): ?array
{
return $this->content;
}
}
@@ -0,0 +1,96 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\DTO;
use WP\McpSchema\Common\JsonRpc\DTO\JSONRPCNotification;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
use WP\McpSchema\Server\Lifecycle\Union\ServerNotificationInterface;
/**
* An optional notification from the server to the client, informing it of a completion of a out-of-band elicitation request.
*
* @since 2025-11-25
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
class ElicitationCompleteNotification extends JSONRPCNotification implements ServerNotificationInterface
{
use ValidatesRequiredFields;
public const METHOD = 'notifications/elicitation/complete';
public const DISCRIMINATOR_FIELD = 'method';
public const DISCRIMINATOR_VALUE = 'notifications/elicitation/complete';
/**
* @var \WP\McpSchema\Client\Elicitation\DTO\ElicitationCompleteNotificationParams
*/
protected ElicitationCompleteNotificationParams $typedParams;
/**
* @param '2.0' $jsonrpc @since 2025-11-25
* @param \WP\McpSchema\Client\Elicitation\DTO\ElicitationCompleteNotificationParams $params @since 2025-11-25
*/
public function __construct(
string $jsonrpc,
ElicitationCompleteNotificationParams $params
) {
parent::__construct(self::METHOD, $jsonrpc, null);
$this->typedParams = $params;
}
/**
* Creates an instance from an array.
*
* @param array{
* jsonrpc: '2.0',
* method: 'notifications/elicitation/complete',
* params: array<string, mixed>|\WP\McpSchema\Client\Elicitation\DTO\ElicitationCompleteNotificationParams
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['jsonrpc', 'params']);
/** @var '2.0' $jsonrpc */
$jsonrpc = self::asString($data['jsonrpc']);
/** @var \WP\McpSchema\Client\Elicitation\DTO\ElicitationCompleteNotificationParams $params */
$params = is_array($data['params'])
? ElicitationCompleteNotificationParams::fromArray(self::asArray($data['params']))
: $data['params'];
return new self(
$jsonrpc,
$params
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
$result['params'] = $this->typedParams->toArray();
return $result;
}
/**
* @return \WP\McpSchema\Client\Elicitation\DTO\ElicitationCompleteNotificationParams
*/
public function getTypedParams(): ElicitationCompleteNotificationParams
{
return $this->typedParams;
}
}
@@ -0,0 +1,74 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
class ElicitationCompleteNotificationParams extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* The ID of the elicitation that completed.
*
* @var string
*/
protected string $elicitationId;
/**
* @param string $elicitationId
*/
public function __construct(
string $elicitationId
) {
$this->elicitationId = $elicitationId;
}
/**
* Creates an instance from an array.
*
* @param array{
* elicitationId: string
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['elicitationId']);
return new self(
self::asString($data['elicitationId'])
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['elicitationId'] = $this->elicitationId;
return $result;
}
/**
* @return string
*/
public function getElicitationId(): string
{
return $this->elicitationId;
}
}
@@ -0,0 +1,198 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\DTO;
use WP\McpSchema\Client\Elicitation\Union\EnumSchemaInterface;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Use TitledSingleSelectEnumSchema instead.
* This interface will be removed in a future version.
*
* @since 2025-11-25
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
class LegacyTitledEnumSchema extends AbstractDataTransferObject implements EnumSchemaInterface
{
use ValidatesRequiredFields;
public const TYPE = 'string';
public const DISCRIMINATOR_FIELD = 'type';
public const DISCRIMINATOR_VALUE = 'string';
/**
* @since 2025-11-25
*
* @var 'string'
*/
protected string $type;
/**
* @since 2025-11-25
*
* @var string|null
*/
protected ?string $title;
/**
* @since 2025-11-25
*
* @var string|null
*/
protected ?string $description;
/**
* @since 2025-11-25
*
* @var array<string>
*/
protected array $enum;
/**
* (Legacy) Display names for enum values.
* Non-standard according to JSON schema 2020-12.
*
* @since 2025-11-25
*
* @var array<string>|null
*/
protected ?array $enumNames;
/**
* @since 2025-11-25
*
* @var string|null
*/
protected ?string $default;
/**
* @param array<string> $enum @since 2025-11-25
* @param string|null $title @since 2025-11-25
* @param string|null $description @since 2025-11-25
* @param array<string>|null $enumNames @since 2025-11-25
* @param string|null $default @since 2025-11-25
*/
public function __construct(
array $enum,
?string $title = null,
?string $description = null,
?array $enumNames = null,
?string $default = null
) {
$this->type = self::TYPE;
$this->enum = $enum;
$this->title = $title;
$this->description = $description;
$this->enumNames = $enumNames;
$this->default = $default;
}
/**
* Creates an instance from an array.
*
* @param array{
* type: 'string',
* title?: string|null,
* description?: string|null,
* enum: array<string>,
* enumNames?: array<string>|null,
* default?: string|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['enum']);
return new self(
self::asStringArray($data['enum']),
self::asStringOrNull($data['title'] ?? null),
self::asStringOrNull($data['description'] ?? null),
self::asStringArrayOrNull($data['enumNames'] ?? null),
self::asStringOrNull($data['default'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['type'] = $this->type;
if ($this->title !== null) {
$result['title'] = $this->title;
}
if ($this->description !== null) {
$result['description'] = $this->description;
}
$result['enum'] = $this->enum;
if ($this->enumNames !== null) {
$result['enumNames'] = $this->enumNames;
}
if ($this->default !== null) {
$result['default'] = $this->default;
}
return $result;
}
/**
* @return 'string'
*/
public function getType(): string
{
return $this->type;
}
/**
* @return string|null
*/
public function getTitle(): ?string
{
return $this->title;
}
/**
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* @return array<string>
*/
public function getEnum(): array
{
return $this->enum;
}
/**
* @return array<string>|null
*/
public function getEnumNames(): ?array
{
return $this->enumNames;
}
/**
* @return string|null
*/
public function getDefault(): ?string
{
return $this->default;
}
}
@@ -0,0 +1,196 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\DTO;
use WP\McpSchema\Client\Elicitation\Union\PrimitiveSchemaDefinitionInterface;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* @since 2025-06-18
* @last-updated 2025-11-25 (added properties: default)
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
class NumberSchema extends AbstractDataTransferObject implements PrimitiveSchemaDefinitionInterface
{
use ValidatesRequiredFields;
/**
* @since 2025-06-18
*
* @var 'number'|'integer'
*/
protected string $type;
/**
* @since 2025-06-18
*
* @var string|null
*/
protected ?string $title;
/**
* @since 2025-06-18
*
* @var string|null
*/
protected ?string $description;
/**
* @since 2025-06-18
*
* @var float|null
*/
protected ?float $minimum;
/**
* @since 2025-06-18
*
* @var float|null
*/
protected ?float $maximum;
/**
* @since 2025-11-25
*
* @var float|null
*/
protected ?float $default;
/**
* @param 'number'|'integer' $type @since 2025-06-18
* @param string|null $title @since 2025-06-18
* @param string|null $description @since 2025-06-18
* @param float|null $minimum @since 2025-06-18
* @param float|null $maximum @since 2025-06-18
* @param float|null $default @since 2025-11-25
*/
public function __construct(
string $type,
?string $title = null,
?string $description = null,
?float $minimum = null,
?float $maximum = null,
?float $default = null
) {
$this->type = $type;
$this->title = $title;
$this->description = $description;
$this->minimum = $minimum;
$this->maximum = $maximum;
$this->default = $default;
}
/**
* Creates an instance from an array.
*
* @param array{
* type: 'number'|'integer',
* title?: string|null,
* description?: string|null,
* minimum?: float|null,
* maximum?: float|null,
* default?: float|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['type']);
/** @var 'number'|'integer' $type */
$type = self::asString($data['type']);
return new self(
$type,
self::asStringOrNull($data['title'] ?? null),
self::asStringOrNull($data['description'] ?? null),
self::asFloatOrNull($data['minimum'] ?? null),
self::asFloatOrNull($data['maximum'] ?? null),
self::asFloatOrNull($data['default'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['type'] = $this->type;
if ($this->title !== null) {
$result['title'] = $this->title;
}
if ($this->description !== null) {
$result['description'] = $this->description;
}
if ($this->minimum !== null) {
$result['minimum'] = $this->minimum;
}
if ($this->maximum !== null) {
$result['maximum'] = $this->maximum;
}
if ($this->default !== null) {
$result['default'] = $this->default;
}
return $result;
}
/**
* @return 'number'|'integer'
*/
public function getType(): string
{
return $this->type;
}
/**
* @return string|null
*/
public function getTitle(): ?string
{
return $this->title;
}
/**
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* @return float|null
*/
public function getMinimum(): ?float
{
return $this->minimum;
}
/**
* @return float|null
*/
public function getMaximum(): ?float
{
return $this->maximum;
}
/**
* @return float|null
*/
public function getDefault(): ?float
{
return $this->default;
}
}
@@ -0,0 +1,221 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\DTO;
use WP\McpSchema\Client\Elicitation\Union\PrimitiveSchemaDefinitionInterface;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* @since 2025-06-18
* @last-updated 2025-11-25 (added properties: default)
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
class StringSchema extends AbstractDataTransferObject implements PrimitiveSchemaDefinitionInterface
{
use ValidatesRequiredFields;
public const TYPE = 'string';
public const DISCRIMINATOR_FIELD = 'type';
public const DISCRIMINATOR_VALUE = 'string';
/**
* @since 2025-06-18
*
* @var 'string'
*/
protected string $type;
/**
* @since 2025-06-18
*
* @var string|null
*/
protected ?string $title;
/**
* @since 2025-06-18
*
* @var string|null
*/
protected ?string $description;
/**
* @since 2025-06-18
*
* @var int|null
*/
protected ?int $minLength;
/**
* @since 2025-06-18
*
* @var int|null
*/
protected ?int $maxLength;
/**
* @since 2025-06-18
*
* @var 'email'|'uri'|'date'|'date-time'|null
*/
protected ?string $format;
/**
* @since 2025-11-25
*
* @var string|null
*/
protected ?string $default;
/**
* @param string|null $title @since 2025-06-18
* @param string|null $description @since 2025-06-18
* @param int|null $minLength @since 2025-06-18
* @param int|null $maxLength @since 2025-06-18
* @param 'email'|'uri'|'date'|'date-time'|null $format @since 2025-06-18
* @param string|null $default @since 2025-11-25
*/
public function __construct(
?string $title = null,
?string $description = null,
?int $minLength = null,
?int $maxLength = null,
?string $format = null,
?string $default = null
) {
$this->type = self::TYPE;
$this->title = $title;
$this->description = $description;
$this->minLength = $minLength;
$this->maxLength = $maxLength;
$this->format = $format;
$this->default = $default;
}
/**
* Creates an instance from an array.
*
* @param array{
* type: 'string',
* title?: string|null,
* description?: string|null,
* minLength?: int|null,
* maxLength?: int|null,
* format?: 'email'|'uri'|'date'|'date-time'|null,
* default?: string|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
/** @var 'email'|'uri'|'date'|'date-time'|null $format */
$format = isset($data['format'])
? self::asStringOrNull($data['format'])
: null;
return new self(
self::asStringOrNull($data['title'] ?? null),
self::asStringOrNull($data['description'] ?? null),
self::asIntOrNull($data['minLength'] ?? null),
self::asIntOrNull($data['maxLength'] ?? null),
$format,
self::asStringOrNull($data['default'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['type'] = $this->type;
if ($this->title !== null) {
$result['title'] = $this->title;
}
if ($this->description !== null) {
$result['description'] = $this->description;
}
if ($this->minLength !== null) {
$result['minLength'] = $this->minLength;
}
if ($this->maxLength !== null) {
$result['maxLength'] = $this->maxLength;
}
if ($this->format !== null) {
$result['format'] = $this->format;
}
if ($this->default !== null) {
$result['default'] = $this->default;
}
return $result;
}
/**
* @return 'string'
*/
public function getType(): string
{
return $this->type;
}
/**
* @return string|null
*/
public function getTitle(): ?string
{
return $this->title;
}
/**
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* @return int|null
*/
public function getMinLength(): ?int
{
return $this->minLength;
}
/**
* @return int|null
*/
public function getMaxLength(): ?int
{
return $this->maxLength;
}
/**
* @return 'email'|'uri'|'date'|'date-time'|null
*/
public function getFormat(): ?string
{
return $this->format;
}
/**
* @return string|null
*/
public function getDefault(): ?string
{
return $this->default;
}
}
@@ -0,0 +1,234 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\DTO;
use WP\McpSchema\Client\Elicitation\Union\MultiSelectEnumSchemaInterface;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Schema for multiple-selection enumeration with display titles for each option.
*
* @since 2025-11-25
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
class TitledMultiSelectEnumSchema extends AbstractDataTransferObject implements MultiSelectEnumSchemaInterface
{
use ValidatesRequiredFields;
public const TYPE = 'array';
public const DISCRIMINATOR_FIELD = 'type';
public const DISCRIMINATOR_VALUE = 'array';
/**
* @since 2025-11-25
*
* @var 'array'
*/
protected string $type;
/**
* Optional title for the enum field.
*
* @since 2025-11-25
*
* @var string|null
*/
protected ?string $title;
/**
* Optional description for the enum field.
*
* @since 2025-11-25
*
* @var string|null
*/
protected ?string $description;
/**
* Minimum number of items to select.
*
* @since 2025-11-25
*
* @var int|null
*/
protected ?int $minItems;
/**
* Maximum number of items to select.
*
* @since 2025-11-25
*
* @var int|null
*/
protected ?int $maxItems;
/**
* Schema for array items with enum options and display labels.
*
* @since 2025-11-25
*
* @var \WP\McpSchema\Client\Elicitation\DTO\TitledMultiSelectEnumSchemaItems
*/
protected TitledMultiSelectEnumSchemaItems $items;
/**
* Optional default value.
*
* @since 2025-11-25
*
* @var array<string>|null
*/
protected ?array $default;
/**
* @param \WP\McpSchema\Client\Elicitation\DTO\TitledMultiSelectEnumSchemaItems $items @since 2025-11-25
* @param string|null $title @since 2025-11-25
* @param string|null $description @since 2025-11-25
* @param int|null $minItems @since 2025-11-25
* @param int|null $maxItems @since 2025-11-25
* @param array<string>|null $default @since 2025-11-25
*/
public function __construct(
TitledMultiSelectEnumSchemaItems $items,
?string $title = null,
?string $description = null,
?int $minItems = null,
?int $maxItems = null,
?array $default = null
) {
$this->type = self::TYPE;
$this->items = $items;
$this->title = $title;
$this->description = $description;
$this->minItems = $minItems;
$this->maxItems = $maxItems;
$this->default = $default;
}
/**
* Creates an instance from an array.
*
* @param array{
* type: 'array',
* title?: string|null,
* description?: string|null,
* minItems?: int|null,
* maxItems?: int|null,
* items: array<string, mixed>|\WP\McpSchema\Client\Elicitation\DTO\TitledMultiSelectEnumSchemaItems,
* default?: array<string>|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['items']);
/** @var \WP\McpSchema\Client\Elicitation\DTO\TitledMultiSelectEnumSchemaItems $items */
$items = is_array($data['items'])
? TitledMultiSelectEnumSchemaItems::fromArray(self::asArray($data['items']))
: $data['items'];
return new self(
$items,
self::asStringOrNull($data['title'] ?? null),
self::asStringOrNull($data['description'] ?? null),
self::asIntOrNull($data['minItems'] ?? null),
self::asIntOrNull($data['maxItems'] ?? null),
self::asStringArrayOrNull($data['default'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['type'] = $this->type;
if ($this->title !== null) {
$result['title'] = $this->title;
}
if ($this->description !== null) {
$result['description'] = $this->description;
}
if ($this->minItems !== null) {
$result['minItems'] = $this->minItems;
}
if ($this->maxItems !== null) {
$result['maxItems'] = $this->maxItems;
}
$result['items'] = $this->items->toArray();
if ($this->default !== null) {
$result['default'] = $this->default;
}
return $result;
}
/**
* @return 'array'
*/
public function getType(): string
{
return $this->type;
}
/**
* @return string|null
*/
public function getTitle(): ?string
{
return $this->title;
}
/**
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* @return int|null
*/
public function getMinItems(): ?int
{
return $this->minItems;
}
/**
* @return int|null
*/
public function getMaxItems(): ?int
{
return $this->maxItems;
}
/**
* @return \WP\McpSchema\Client\Elicitation\DTO\TitledMultiSelectEnumSchemaItems
*/
public function getItems(): TitledMultiSelectEnumSchemaItems
{
return $this->items;
}
/**
* @return array<string>|null
*/
public function getDefault(): ?array
{
return $this->default;
}
}
@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
/**
* Schema for array items with enum options and display labels.
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
class TitledMultiSelectEnumSchemaItems extends AbstractDataTransferObject
{
/**
*/
public function __construct()
{
}
/**
* Creates an instance from an array.
*
* @param array{
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
return new self();
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
return $result;
}
}
@@ -0,0 +1,182 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\DTO;
use WP\McpSchema\Client\Elicitation\Union\SingleSelectEnumSchemaInterface;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Schema for single-selection enumeration with display titles for each option.
*
* @since 2025-11-25
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
class TitledSingleSelectEnumSchema extends AbstractDataTransferObject implements SingleSelectEnumSchemaInterface
{
use ValidatesRequiredFields;
public const TYPE = 'string';
public const DISCRIMINATOR_FIELD = 'type';
public const DISCRIMINATOR_VALUE = 'string';
/**
* @since 2025-11-25
*
* @var 'string'
*/
protected string $type;
/**
* Optional title for the enum field.
*
* @since 2025-11-25
*
* @var string|null
*/
protected ?string $title;
/**
* Optional description for the enum field.
*
* @since 2025-11-25
*
* @var string|null
*/
protected ?string $description;
/**
* Array of enum options with values and display labels.
*
* @since 2025-11-25
*
* @var array<object>
*/
protected array $oneOf;
/**
* Optional default value.
*
* @since 2025-11-25
*
* @var string|null
*/
protected ?string $default;
/**
* @param array<object> $oneOf @since 2025-11-25
* @param string|null $title @since 2025-11-25
* @param string|null $description @since 2025-11-25
* @param string|null $default @since 2025-11-25
*/
public function __construct(
array $oneOf,
?string $title = null,
?string $description = null,
?string $default = null
) {
$this->type = self::TYPE;
$this->oneOf = $oneOf;
$this->title = $title;
$this->description = $description;
$this->default = $default;
}
/**
* Creates an instance from an array.
*
* @param array{
* type: 'string',
* title?: string|null,
* description?: string|null,
* oneOf: array<object>,
* default?: string|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['oneOf']);
/** @var array<object> $oneOf */
$oneOf = self::asArray($data['oneOf']);
return new self(
$oneOf,
self::asStringOrNull($data['title'] ?? null),
self::asStringOrNull($data['description'] ?? null),
self::asStringOrNull($data['default'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['type'] = $this->type;
if ($this->title !== null) {
$result['title'] = $this->title;
}
if ($this->description !== null) {
$result['description'] = $this->description;
}
$result['oneOf'] = $this->oneOf;
if ($this->default !== null) {
$result['default'] = $this->default;
}
return $result;
}
/**
* @return 'string'
*/
public function getType(): string
{
return $this->type;
}
/**
* @return string|null
*/
public function getTitle(): ?string
{
return $this->title;
}
/**
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* @return array<object>
*/
public function getOneOf(): array
{
return $this->oneOf;
}
/**
* @return string|null
*/
public function getDefault(): ?string
{
return $this->default;
}
}
@@ -0,0 +1,234 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\DTO;
use WP\McpSchema\Client\Elicitation\Union\MultiSelectEnumSchemaInterface;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Schema for multiple-selection enumeration without display titles for options.
*
* @since 2025-11-25
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
class UntitledMultiSelectEnumSchema extends AbstractDataTransferObject implements MultiSelectEnumSchemaInterface
{
use ValidatesRequiredFields;
public const TYPE = 'array';
public const DISCRIMINATOR_FIELD = 'type';
public const DISCRIMINATOR_VALUE = 'array';
/**
* @since 2025-11-25
*
* @var 'array'
*/
protected string $type;
/**
* Optional title for the enum field.
*
* @since 2025-11-25
*
* @var string|null
*/
protected ?string $title;
/**
* Optional description for the enum field.
*
* @since 2025-11-25
*
* @var string|null
*/
protected ?string $description;
/**
* Minimum number of items to select.
*
* @since 2025-11-25
*
* @var int|null
*/
protected ?int $minItems;
/**
* Maximum number of items to select.
*
* @since 2025-11-25
*
* @var int|null
*/
protected ?int $maxItems;
/**
* Schema for the array items.
*
* @since 2025-11-25
*
* @var \WP\McpSchema\Client\Elicitation\DTO\UntitledMultiSelectEnumSchemaItems
*/
protected UntitledMultiSelectEnumSchemaItems $items;
/**
* Optional default value.
*
* @since 2025-11-25
*
* @var array<string>|null
*/
protected ?array $default;
/**
* @param \WP\McpSchema\Client\Elicitation\DTO\UntitledMultiSelectEnumSchemaItems $items @since 2025-11-25
* @param string|null $title @since 2025-11-25
* @param string|null $description @since 2025-11-25
* @param int|null $minItems @since 2025-11-25
* @param int|null $maxItems @since 2025-11-25
* @param array<string>|null $default @since 2025-11-25
*/
public function __construct(
UntitledMultiSelectEnumSchemaItems $items,
?string $title = null,
?string $description = null,
?int $minItems = null,
?int $maxItems = null,
?array $default = null
) {
$this->type = self::TYPE;
$this->items = $items;
$this->title = $title;
$this->description = $description;
$this->minItems = $minItems;
$this->maxItems = $maxItems;
$this->default = $default;
}
/**
* Creates an instance from an array.
*
* @param array{
* type: 'array',
* title?: string|null,
* description?: string|null,
* minItems?: int|null,
* maxItems?: int|null,
* items: array<string, mixed>|\WP\McpSchema\Client\Elicitation\DTO\UntitledMultiSelectEnumSchemaItems,
* default?: array<string>|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['items']);
/** @var \WP\McpSchema\Client\Elicitation\DTO\UntitledMultiSelectEnumSchemaItems $items */
$items = is_array($data['items'])
? UntitledMultiSelectEnumSchemaItems::fromArray(self::asArray($data['items']))
: $data['items'];
return new self(
$items,
self::asStringOrNull($data['title'] ?? null),
self::asStringOrNull($data['description'] ?? null),
self::asIntOrNull($data['minItems'] ?? null),
self::asIntOrNull($data['maxItems'] ?? null),
self::asStringArrayOrNull($data['default'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['type'] = $this->type;
if ($this->title !== null) {
$result['title'] = $this->title;
}
if ($this->description !== null) {
$result['description'] = $this->description;
}
if ($this->minItems !== null) {
$result['minItems'] = $this->minItems;
}
if ($this->maxItems !== null) {
$result['maxItems'] = $this->maxItems;
}
$result['items'] = $this->items->toArray();
if ($this->default !== null) {
$result['default'] = $this->default;
}
return $result;
}
/**
* @return 'array'
*/
public function getType(): string
{
return $this->type;
}
/**
* @return string|null
*/
public function getTitle(): ?string
{
return $this->title;
}
/**
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* @return int|null
*/
public function getMinItems(): ?int
{
return $this->minItems;
}
/**
* @return int|null
*/
public function getMaxItems(): ?int
{
return $this->maxItems;
}
/**
* @return \WP\McpSchema\Client\Elicitation\DTO\UntitledMultiSelectEnumSchemaItems
*/
public function getItems(): UntitledMultiSelectEnumSchemaItems
{
return $this->items;
}
/**
* @return array<string>|null
*/
public function getDefault(): ?array
{
return $this->default;
}
}
@@ -0,0 +1,94 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Schema for the array items.
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
class UntitledMultiSelectEnumSchemaItems extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
public const TYPE = 'string';
/**
* @var 'string'
*/
protected string $type;
/**
* Array of enum values to choose from.
*
* @var array<string>
*/
protected array $enum;
/**
* @param array<string> $enum
*/
public function __construct(
array $enum
) {
$this->type = self::TYPE;
$this->enum = $enum;
}
/**
* Creates an instance from an array.
*
* @param array{
* type: 'string',
* enum: array<string>
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['enum']);
return new self(
self::asStringArray($data['enum'])
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['type'] = $this->type;
$result['enum'] = $this->enum;
return $result;
}
/**
* @return 'string'
*/
public function getType(): string
{
return $this->type;
}
/**
* @return array<string>
*/
public function getEnum(): array
{
return $this->enum;
}
}
@@ -0,0 +1,179 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\DTO;
use WP\McpSchema\Client\Elicitation\Union\SingleSelectEnumSchemaInterface;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Schema for single-selection enumeration without display titles for options.
*
* @since 2025-11-25
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
class UntitledSingleSelectEnumSchema extends AbstractDataTransferObject implements SingleSelectEnumSchemaInterface
{
use ValidatesRequiredFields;
public const TYPE = 'string';
public const DISCRIMINATOR_FIELD = 'type';
public const DISCRIMINATOR_VALUE = 'string';
/**
* @since 2025-11-25
*
* @var 'string'
*/
protected string $type;
/**
* Optional title for the enum field.
*
* @since 2025-11-25
*
* @var string|null
*/
protected ?string $title;
/**
* Optional description for the enum field.
*
* @since 2025-11-25
*
* @var string|null
*/
protected ?string $description;
/**
* Array of enum values to choose from.
*
* @since 2025-11-25
*
* @var array<string>
*/
protected array $enum;
/**
* Optional default value.
*
* @since 2025-11-25
*
* @var string|null
*/
protected ?string $default;
/**
* @param array<string> $enum @since 2025-11-25
* @param string|null $title @since 2025-11-25
* @param string|null $description @since 2025-11-25
* @param string|null $default @since 2025-11-25
*/
public function __construct(
array $enum,
?string $title = null,
?string $description = null,
?string $default = null
) {
$this->type = self::TYPE;
$this->enum = $enum;
$this->title = $title;
$this->description = $description;
$this->default = $default;
}
/**
* Creates an instance from an array.
*
* @param array{
* type: 'string',
* title?: string|null,
* description?: string|null,
* enum: array<string>,
* default?: string|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['enum']);
return new self(
self::asStringArray($data['enum']),
self::asStringOrNull($data['title'] ?? null),
self::asStringOrNull($data['description'] ?? null),
self::asStringOrNull($data['default'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['type'] = $this->type;
if ($this->title !== null) {
$result['title'] = $this->title;
}
if ($this->description !== null) {
$result['description'] = $this->description;
}
$result['enum'] = $this->enum;
if ($this->default !== null) {
$result['default'] = $this->default;
}
return $result;
}
/**
* @return 'string'
*/
public function getType(): string
{
return $this->type;
}
/**
* @return string|null
*/
public function getTitle(): ?string
{
return $this->title;
}
/**
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* @return array<string>
*/
public function getEnum(): array
{
return $this->enum;
}
/**
* @return string|null
*/
public function getDefault(): ?string
{
return $this->default;
}
}
@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\Factory;
use WP\McpSchema\Client\Elicitation\Union\ElicitRequestParamsInterface;
use WP\McpSchema\Client\Elicitation\DTO\ElicitRequestFormParams;
use WP\McpSchema\Client\Elicitation\DTO\ElicitRequestURLParams;
/**
* Factory for creating ElicitRequestParams union type instances.
*
* The parameters for a request to elicit additional information from the user via the client.
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
final class ElicitRequestParamsFactory
{
/**
* Registry mapping discriminator values to implementation classes.
*
* @var array<string, class-string<ElicitRequestParamsInterface>>
*/
public const REGISTRY = [
'form' => ElicitRequestFormParams::class,
'url' => ElicitRequestURLParams::class,
];
/**
* Creates an instance from an array.
*
* @param array<string, mixed> $data
* @return ElicitRequestParamsInterface
* @throws \InvalidArgumentException
*/
public static function fromArray(array $data): ElicitRequestParamsInterface
{
if (!isset($data['mode'])) {
throw new \InvalidArgumentException('Missing discriminator field: mode');
}
/** @var string $mode */
$mode = $data['mode'];
if (!isset(self::REGISTRY[$mode])) {
throw new \InvalidArgumentException(sprintf(
"Unknown mode value '%s'. Valid values: %s",
$mode,
implode(', ', array_keys(self::REGISTRY))
));
}
$class = self::REGISTRY[$mode];
return $class::fromArray($data);
}
/**
* Checks if a mode value is supported by this factory.
*
* @param string $mode
* @return bool
*/
public static function supports(string $mode): bool
{
return isset(self::REGISTRY[$mode]);
}
/**
* Returns all supported mode values.
*
* @return array<string>
*/
public static function modes(): array
{
return array_keys(self::REGISTRY);
}
}
@@ -0,0 +1,87 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\Factory;
use WP\McpSchema\Client\Elicitation\Union\EnumSchemaInterface;
use WP\McpSchema\Client\Elicitation\Factory\SingleSelectEnumSchemaFactory;
use WP\McpSchema\Client\Elicitation\Factory\MultiSelectEnumSchemaFactory;
use WP\McpSchema\Client\Elicitation\DTO\LegacyTitledEnumSchema;
/**
* Factory for creating EnumSchema union type instances.
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
final class EnumSchemaFactory
{
/**
* Registry mapping discriminator values to implementation classes.
* Note: Some values route to other factories for nested union resolution.
*
* @var array<string, class-string>
*/
public const REGISTRY = [
'array' => MultiSelectEnumSchemaFactory::class,
'string' => LegacyTitledEnumSchema::class,
];
/**
* Creates an instance from an array.
*
* @param array<string, mixed> $data
* @return EnumSchemaInterface
* @throws \InvalidArgumentException
*/
public static function fromArray(array $data): EnumSchemaInterface
{
if (!isset($data['type'])) {
throw new \InvalidArgumentException('Missing discriminator field: type');
}
switch ($data['type']) {
case 'array':
return MultiSelectEnumSchemaFactory::fromArray($data);
case 'string':
if (isset($data['oneOf'])) {
return SingleSelectEnumSchemaFactory::fromArray($data);
}
elseif (isset($data['enumNames'])) {
return LegacyTitledEnumSchema::fromArray($data);
}
else {
return LegacyTitledEnumSchema::fromArray($data);
}
default:
throw new \InvalidArgumentException(sprintf(
"Unknown type value '%s'. Valid values: %s",
is_scalar($data['type']) ? $data['type'] : gettype($data['type']),
implode(', ', array_keys(self::REGISTRY))
));
}
}
/**
* Checks if a type value is supported by this factory.
*
* @param string $type
* @return bool
*/
public static function supports(string $type): bool
{
return isset(self::REGISTRY[$type]);
}
/**
* Returns all supported type values.
*
* @return array<string>
*/
public static function types(): array
{
return array_keys(self::REGISTRY);
}
}
@@ -0,0 +1,74 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\Factory;
use WP\McpSchema\Client\Elicitation\Union\MultiSelectEnumSchemaInterface;
use WP\McpSchema\Client\Elicitation\DTO\UntitledMultiSelectEnumSchema;
use WP\McpSchema\Client\Elicitation\DTO\TitledMultiSelectEnumSchema;
/**
* Factory for creating MultiSelectEnumSchema union type instances.
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
final class MultiSelectEnumSchemaFactory
{
/**
* Registry mapping discriminator values to implementation classes.
*
* @var array<string, class-string<MultiSelectEnumSchemaInterface>>
*/
public const REGISTRY = [
'array' => UntitledMultiSelectEnumSchema::class,
];
/**
* Creates an instance from an array.
*
* @param array<string, mixed> $data
* @return MultiSelectEnumSchemaInterface
* @throws \InvalidArgumentException
*/
public static function fromArray(array $data): MultiSelectEnumSchemaInterface
{
if (!isset($data['type'])) {
throw new \InvalidArgumentException('Missing discriminator field: type');
}
switch ($data['type']) {
case 'array':
return UntitledMultiSelectEnumSchema::fromArray($data);
default:
throw new \InvalidArgumentException(sprintf(
"Unknown type value '%s'. Valid values: %s",
is_scalar($data['type']) ? $data['type'] : gettype($data['type']),
implode(', ', array_keys(self::REGISTRY))
));
}
}
/**
* Checks if a type value is supported by this factory.
*
* @param string $type
* @return bool
*/
public static function supports(string $type): bool
{
return isset(self::REGISTRY[$type]);
}
/**
* Returns all supported type values.
*
* @return array<string>
*/
public static function types(): array
{
return array_keys(self::REGISTRY);
}
}
@@ -0,0 +1,100 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\Factory;
use WP\McpSchema\Client\Elicitation\Union\PrimitiveSchemaDefinitionInterface;
use WP\McpSchema\Client\Elicitation\DTO\StringSchema;
use WP\McpSchema\Client\Elicitation\DTO\NumberSchema;
use WP\McpSchema\Client\Elicitation\DTO\BooleanSchema;
use WP\McpSchema\Client\Elicitation\Factory\EnumSchemaFactory;
/**
* Factory for creating PrimitiveSchemaDefinition union type instances.
*
* Restricted schema definitions that only allow primitive types
* without nested objects or arrays.
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
final class PrimitiveSchemaDefinitionFactory
{
/**
* Registry mapping discriminator values to implementation classes.
* Note: Some values route to other factories for nested union resolution.
*
* @var array<string, class-string>
*/
public const REGISTRY = [
'number' => NumberSchema::class,
'integer' => NumberSchema::class,
'boolean' => BooleanSchema::class,
'array' => EnumSchemaFactory::class,
'string' => StringSchema::class,
];
/**
* Creates an instance from an array.
*
* @param array<string, mixed> $data
* @return PrimitiveSchemaDefinitionInterface
* @throws \InvalidArgumentException
*/
public static function fromArray(array $data): PrimitiveSchemaDefinitionInterface
{
if (!isset($data['type'])) {
throw new \InvalidArgumentException('Missing discriminator field: type');
}
switch ($data['type']) {
case 'number':
return NumberSchema::fromArray($data);
case 'integer':
return NumberSchema::fromArray($data);
case 'boolean':
return BooleanSchema::fromArray($data);
case 'array':
return EnumSchemaFactory::fromArray($data);
case 'string':
if (isset($data['minLength'])) {
return StringSchema::fromArray($data);
}
elseif (isset($data['enum'])) {
return EnumSchemaFactory::fromArray($data);
}
else {
return StringSchema::fromArray($data);
}
default:
throw new \InvalidArgumentException(sprintf(
"Unknown type value '%s'. Valid values: %s",
is_scalar($data['type']) ? $data['type'] : gettype($data['type']),
implode(', ', array_keys(self::REGISTRY))
));
}
}
/**
* Checks if a type value is supported by this factory.
*
* @param string $type
* @return bool
*/
public static function supports(string $type): bool
{
return isset(self::REGISTRY[$type]);
}
/**
* Returns all supported type values.
*
* @return array<string>
*/
public static function types(): array
{
return array_keys(self::REGISTRY);
}
}
@@ -0,0 +1,82 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\Factory;
use WP\McpSchema\Client\Elicitation\Union\SingleSelectEnumSchemaInterface;
use WP\McpSchema\Client\Elicitation\DTO\UntitledSingleSelectEnumSchema;
use WP\McpSchema\Client\Elicitation\DTO\TitledSingleSelectEnumSchema;
/**
* Factory for creating SingleSelectEnumSchema union type instances.
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
final class SingleSelectEnumSchemaFactory
{
/**
* Registry mapping discriminator values to implementation classes.
*
* @var array<string, class-string<SingleSelectEnumSchemaInterface>>
*/
public const REGISTRY = [
'string' => UntitledSingleSelectEnumSchema::class,
];
/**
* Creates an instance from an array.
*
* @param array<string, mixed> $data
* @return SingleSelectEnumSchemaInterface
* @throws \InvalidArgumentException
*/
public static function fromArray(array $data): SingleSelectEnumSchemaInterface
{
if (!isset($data['type'])) {
throw new \InvalidArgumentException('Missing discriminator field: type');
}
switch ($data['type']) {
case 'string':
if (isset($data['enum'])) {
return UntitledSingleSelectEnumSchema::fromArray($data);
}
elseif (isset($data['oneOf'])) {
return TitledSingleSelectEnumSchema::fromArray($data);
}
else {
return UntitledSingleSelectEnumSchema::fromArray($data);
}
default:
throw new \InvalidArgumentException(sprintf(
"Unknown type value '%s'. Valid values: %s",
is_scalar($data['type']) ? $data['type'] : gettype($data['type']),
implode(', ', array_keys(self::REGISTRY))
));
}
}
/**
* Checks if a type value is supported by this factory.
*
* @param string $type
* @return bool
*/
public static function supports(string $type): bool
{
return isset(self::REGISTRY[$type]);
}
/**
* Returns all supported type values.
*
* @return array<string>
*/
public static function types(): array
{
return array_keys(self::REGISTRY);
}
}
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\Union;
/**
* The parameters for a request to elicit additional information from the user via the client.
*
* Union type members:
* - ElicitRequestFormParams
* - ElicitRequestURLParams
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
interface ElicitRequestParamsInterface
{
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array;
}
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\Union;
use WP\McpSchema\Client\Elicitation\Union\PrimitiveSchemaDefinitionInterface;
/**
* Union type members:
* - SingleSelectEnumSchema
* - MultiSelectEnumSchema
* - LegacyTitledEnumSchema
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
interface EnumSchemaInterface extends PrimitiveSchemaDefinitionInterface
{
}
@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\Union;
use WP\McpSchema\Client\Elicitation\Union\EnumSchemaInterface;
/**
* Union type members:
* - UntitledMultiSelectEnumSchema
* - TitledMultiSelectEnumSchema
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
interface MultiSelectEnumSchemaInterface extends EnumSchemaInterface
{
}
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\Union;
/**
* Restricted schema definitions that only allow primitive types
* without nested objects or arrays.
*
* Union type members:
* - StringSchema
* - NumberSchema
* - BooleanSchema
* - EnumSchema
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
interface PrimitiveSchemaDefinitionInterface
{
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array;
}
@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Elicitation\Union;
use WP\McpSchema\Client\Elicitation\Union\EnumSchemaInterface;
/**
* Union type members:
* - UntitledSingleSelectEnumSchema
* - TitledSingleSelectEnumSchema
*
* @mcp-domain Client
* @mcp-subdomain Elicitation
* @mcp-version 2025-11-25
*/
interface SingleSelectEnumSchemaInterface extends EnumSchemaInterface
{
}
@@ -0,0 +1,209 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Lifecycle\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Capabilities a client may support. Known capabilities are defined here, in this schema, but this is not a closed set: any client can define its own, additional capabilities.
*
* @since 2024-11-05
* @last-updated 2025-11-25 (added properties: tasks)
*
* @mcp-domain Client
* @mcp-subdomain Lifecycle
* @mcp-version 2025-11-25
*/
class ClientCapabilities extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* Experimental, non-standard capabilities that the client supports.
*
* @since 2024-11-05
*
* @var array<string, object>|null
*/
protected ?array $experimental;
/**
* Present if the client supports listing roots.
*
* @since 2024-11-05
*
* @var \WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilitiesRoots|null
*/
protected ?ClientCapabilitiesRoots $roots;
/**
* Present if the client supports sampling from an LLM.
*
* @since 2024-11-05
*
* @var \WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilitiesSampling|null
*/
protected ?ClientCapabilitiesSampling $sampling;
/**
* Present if the client supports elicitation from the server.
*
* @since 2025-06-18
*
* @var \WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilitiesElicitation|null
*/
protected ?ClientCapabilitiesElicitation $elicitation;
/**
* Present if the client supports task-augmented requests.
*
* @since 2025-11-25
*
* @var \WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilitiesTasks|null
*/
protected ?ClientCapabilitiesTasks $tasks;
/**
* @param array<string, object>|null $experimental @since 2024-11-05
* @param \WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilitiesRoots|null $roots @since 2024-11-05
* @param \WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilitiesSampling|null $sampling @since 2024-11-05
* @param \WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilitiesElicitation|null $elicitation @since 2025-06-18
* @param \WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilitiesTasks|null $tasks @since 2025-11-25
*/
public function __construct(
?array $experimental = null,
?ClientCapabilitiesRoots $roots = null,
?ClientCapabilitiesSampling $sampling = null,
?ClientCapabilitiesElicitation $elicitation = null,
?ClientCapabilitiesTasks $tasks = null
) {
$this->experimental = $experimental;
$this->roots = $roots;
$this->sampling = $sampling;
$this->elicitation = $elicitation;
$this->tasks = $tasks;
}
/**
* Creates an instance from an array.
*
* @param array{
* experimental?: array<string, object>|null,
* roots?: array<string, mixed>|\WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilitiesRoots|null,
* sampling?: array<string, mixed>|\WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilitiesSampling|null,
* elicitation?: array<string, mixed>|\WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilitiesElicitation|null,
* tasks?: array<string, mixed>|\WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilitiesTasks|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
/** @var \WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilitiesRoots|null $roots */
$roots = isset($data['roots'])
? (is_array($data['roots'])
? ClientCapabilitiesRoots::fromArray(self::asArray($data['roots']))
: $data['roots'])
: null;
/** @var \WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilitiesSampling|null $sampling */
$sampling = isset($data['sampling'])
? (is_array($data['sampling'])
? ClientCapabilitiesSampling::fromArray(self::asArray($data['sampling']))
: $data['sampling'])
: null;
/** @var \WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilitiesElicitation|null $elicitation */
$elicitation = isset($data['elicitation'])
? (is_array($data['elicitation'])
? ClientCapabilitiesElicitation::fromArray(self::asArray($data['elicitation']))
: $data['elicitation'])
: null;
/** @var \WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilitiesTasks|null $tasks */
$tasks = isset($data['tasks'])
? (is_array($data['tasks'])
? ClientCapabilitiesTasks::fromArray(self::asArray($data['tasks']))
: $data['tasks'])
: null;
return new self(
self::asObjectMapOrNull($data['experimental'] ?? null),
$roots,
$sampling,
$elicitation,
$tasks
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
if ($this->experimental !== null) {
$result['experimental'] = $this->experimental;
}
if ($this->roots !== null) {
$result['roots'] = $this->roots->toArray();
}
if ($this->sampling !== null) {
$result['sampling'] = $this->sampling->toArray();
}
if ($this->elicitation !== null) {
$result['elicitation'] = $this->elicitation->toArray();
}
if ($this->tasks !== null) {
$result['tasks'] = $this->tasks->toArray();
}
return $result;
}
/**
* @return array<string, object>|null
*/
public function getExperimental(): ?array
{
return $this->experimental;
}
/**
* @return \WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilitiesRoots|null
*/
public function getRoots(): ?ClientCapabilitiesRoots
{
return $this->roots;
}
/**
* @return \WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilitiesSampling|null
*/
public function getSampling(): ?ClientCapabilitiesSampling
{
return $this->sampling;
}
/**
* @return \WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilitiesElicitation|null
*/
public function getElicitation(): ?ClientCapabilitiesElicitation
{
return $this->elicitation;
}
/**
* @return \WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilitiesTasks|null
*/
public function getTasks(): ?ClientCapabilitiesTasks
{
return $this->tasks;
}
}
@@ -0,0 +1,95 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Lifecycle\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Present if the client supports elicitation from the server.
*
* @mcp-domain Client
* @mcp-subdomain Lifecycle
* @mcp-version 2025-11-25
*/
class ClientCapabilitiesElicitation extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* @var object|null
*/
protected ?object $form;
/**
* @var object|null
*/
protected ?object $url;
/**
* @param object|null $form
* @param object|null $url
*/
public function __construct(
?object $form = null,
?object $url = null
) {
$this->form = $form;
$this->url = $url;
}
/**
* Creates an instance from an array.
*
* @param array{
* form?: object|null,
* url?: object|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
return new self(
self::asObjectOrNull($data['form'] ?? null),
self::asObjectOrNull($data['url'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
if ($this->form !== null) {
$result['form'] = $this->form;
}
if ($this->url !== null) {
$result['url'] = $this->url;
}
return $result;
}
/**
* @return object|null
*/
public function getForm(): ?object
{
return $this->form;
}
/**
* @return object|null
*/
public function getUrl(): ?object
{
return $this->url;
}
}
@@ -0,0 +1,76 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Lifecycle\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Present if the client supports listing roots.
*
* @mcp-domain Client
* @mcp-subdomain Lifecycle
* @mcp-version 2025-11-25
*/
class ClientCapabilitiesRoots extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* Whether the client supports notifications for changes to the roots list.
*
* @var bool|null
*/
protected ?bool $listChanged;
/**
* @param bool|null $listChanged
*/
public function __construct(
?bool $listChanged = null
) {
$this->listChanged = $listChanged;
}
/**
* Creates an instance from an array.
*
* @param array{
* listChanged?: bool|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
return new self(
self::asBoolOrNull($data['listChanged'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
if ($this->listChanged !== null) {
$result['listChanged'] = $this->listChanged;
}
return $result;
}
/**
* @return bool|null
*/
public function getListChanged(): ?bool
{
return $this->listChanged;
}
}
@@ -0,0 +1,99 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Lifecycle\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Present if the client supports sampling from an LLM.
*
* @mcp-domain Client
* @mcp-subdomain Lifecycle
* @mcp-version 2025-11-25
*/
class ClientCapabilitiesSampling extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* Whether the client supports context inclusion via includeContext parameter. If not declared, servers SHOULD only use `includeContext: "none"` (or omit it).
*
* @var object|null
*/
protected ?object $context;
/**
* Whether the client supports tool use via tools and toolChoice parameters.
*
* @var object|null
*/
protected ?object $tools;
/**
* @param object|null $context
* @param object|null $tools
*/
public function __construct(
?object $context = null,
?object $tools = null
) {
$this->context = $context;
$this->tools = $tools;
}
/**
* Creates an instance from an array.
*
* @param array{
* context?: object|null,
* tools?: object|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
return new self(
self::asObjectOrNull($data['context'] ?? null),
self::asObjectOrNull($data['tools'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
if ($this->context !== null) {
$result['context'] = $this->context;
}
if ($this->tools !== null) {
$result['tools'] = $this->tools;
}
return $result;
}
/**
* @return object|null
*/
public function getContext(): ?object
{
return $this->context;
}
/**
* @return object|null
*/
public function getTools(): ?object
{
return $this->tools;
}
}
@@ -0,0 +1,99 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Lifecycle\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Present if the client supports task-augmented requests.
*
* @mcp-domain Client
* @mcp-subdomain Lifecycle
* @mcp-version 2025-11-25
*/
class ClientCapabilitiesTasks extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* Whether this client supports tasks/list.
*
* @var object|null
*/
protected ?object $list;
/**
* Whether this client supports tasks/cancel.
*
* @var object|null
*/
protected ?object $cancel;
/**
* @param object|null $list
* @param object|null $cancel
*/
public function __construct(
?object $list = null,
?object $cancel = null
) {
$this->list = $list;
$this->cancel = $cancel;
}
/**
* Creates an instance from an array.
*
* @param array{
* list?: object|null,
* cancel?: object|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
return new self(
self::asObjectOrNull($data['list'] ?? null),
self::asObjectOrNull($data['cancel'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
if ($this->list !== null) {
$result['list'] = $this->list;
}
if ($this->cancel !== null) {
$result['cancel'] = $this->cancel;
}
return $result;
}
/**
* @return object|null
*/
public function getList(): ?object
{
return $this->list;
}
/**
* @return object|null
*/
public function getCancel(): ?object
{
return $this->cancel;
}
}
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Lifecycle\Union;
/**
* Union type members:
* - EmptyResult
* - CreateMessageResult
* - ListRootsResult
* - ElicitResult
* - GetTaskResult
* - GetTaskPayloadResult
* - ListTasksResult
* - CancelTaskResult
*
* @mcp-domain Client
* @mcp-subdomain Lifecycle
* @mcp-version 2025-11-25
*/
interface ClientResultInterface
{
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array;
}
@@ -0,0 +1,115 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Roots\DTO;
use WP\McpSchema\Common\JsonRpc\DTO\JSONRPCRequest;
use WP\McpSchema\Common\JsonRpc\DTO\RequestParams;
use WP\McpSchema\Common\Protocol\Union\ServerRequestInterface;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Sent from the server to request a list of root URIs from the client. Roots allow
* servers to ask for specific directories or files to operate on. A common example
* for roots is providing a set of repositories or directories a server should operate
* on.
*
* This request is typically used when the server needs to understand the file system
* structure or access specific locations that the client has permission to read from.
*
* @since 2024-11-05
* @last-updated 2025-11-25 (modified property: params)
*
* @mcp-domain Client
* @mcp-subdomain Roots
* @mcp-version 2025-11-25
*/
class ListRootsRequest extends JSONRPCRequest implements ServerRequestInterface
{
use ValidatesRequiredFields;
public const METHOD = 'roots/list';
public const DISCRIMINATOR_FIELD = 'method';
public const DISCRIMINATOR_VALUE = 'roots/list';
/**
* @var \WP\McpSchema\Common\JsonRpc\DTO\RequestParams|null
*/
protected ?RequestParams $typedParams;
/**
* @param '2.0' $jsonrpc @since 2025-11-25
* @param string|number $id @since 2025-11-25
* @param \WP\McpSchema\Common\JsonRpc\DTO\RequestParams|null $params @since 2024-11-05
*/
public function __construct(
string $jsonrpc,
$id,
?RequestParams $params = null
) {
parent::__construct(self::METHOD, $jsonrpc, $id, null);
$this->typedParams = $params;
}
/**
* Creates an instance from an array.
*
* @param array{
* jsonrpc: '2.0',
* id: string|number,
* method: 'roots/list',
* params?: array<string, mixed>|\WP\McpSchema\Common\JsonRpc\DTO\RequestParams|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['jsonrpc', 'id']);
/** @var '2.0' $jsonrpc */
$jsonrpc = self::asString($data['jsonrpc']);
/** @var string|number $id */
$id = self::asStringOrNumber($data['id']);
/** @var \WP\McpSchema\Common\JsonRpc\DTO\RequestParams|null $params */
$params = isset($data['params'])
? (is_array($data['params'])
? RequestParams::fromArray(self::asArray($data['params']))
: $data['params'])
: null;
return new self(
$jsonrpc,
$id,
$params
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
if ($this->typedParams !== null) {
$result['params'] = $this->typedParams->toArray();
}
return $result;
}
/**
* @return \WP\McpSchema\Common\JsonRpc\DTO\RequestParams|null
*/
public function getTypedParams(): ?RequestParams
{
return $this->typedParams;
}
}
@@ -0,0 +1,105 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Roots\DTO;
use WP\McpSchema\Client\Lifecycle\Union\ClientResultInterface;
use WP\McpSchema\Common\Protocol\DTO\Result;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* The client's response to a roots/list request from the server.
* This result contains an array of Root objects, each representing a root directory
* or file that the server can operate on.
*
* @since 2024-11-05
* @last-updated 2025-11-25 (modified property: roots)
*
* @mcp-domain Client
* @mcp-subdomain Roots
* @mcp-version 2025-11-25
*/
class ListRootsResult extends Result implements ClientResultInterface
{
use ValidatesRequiredFields;
/**
* Wire keys this class models. Anything else is kept in $additionalProperties.
*
* @var array<int, string>
*/
private const KNOWN_KEYS = ['_meta', 'roots'];
/**
* @since 2024-11-05
*
* @var array<\WP\McpSchema\Client\Roots\DTO\Root>
*/
protected array $roots;
/**
* @param array<\WP\McpSchema\Client\Roots\DTO\Root> $roots @since 2024-11-05
* @param array<string, mixed>|null $_meta @since 2024-11-05
* @param array<string, mixed>|null $additionalProperties
*/
public function __construct(
array $roots,
?array $_meta = null,
?array $additionalProperties = null
) {
parent::__construct($_meta, $additionalProperties);
$this->roots = $roots;
}
/**
* Creates an instance from an array.
*
* @param array{
* _meta?: array<string, mixed>|null,
* roots: array<array<string, mixed>|\WP\McpSchema\Client\Roots\DTO\Root>
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['roots']);
/** @var array<\WP\McpSchema\Client\Roots\DTO\Root> $roots */
$roots = array_map(
static fn($item) => is_array($item)
? Root::fromArray($item)
: $item,
self::asArray($data['roots'])
);
return new self(
$roots,
self::asArrayOrNull($data['_meta'] ?? null),
self::additionalFields($data, self::KNOWN_KEYS)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
$result['roots'] = array_map(static fn($item) => $item->toArray(), $this->roots);
return $result;
}
/**
* @return array<\WP\McpSchema\Client\Roots\DTO\Root>
*/
public function getRoots(): array
{
return $this->roots;
}
}
@@ -0,0 +1,135 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Roots\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Represents a root directory or file that the server can operate on.
*
* @since 2024-11-05
* @last-updated 2025-06-18 (added properties: _meta)
*
* @mcp-domain Client
* @mcp-subdomain Roots
* @mcp-version 2025-11-25
*/
class Root extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* The URI identifying the root. This *must* start with file:// for now.
* This restriction may be relaxed in future versions of the protocol to allow
* other URI schemes.
*
* @since 2024-11-05
*
* @var string
*/
protected string $uri;
/**
* An optional name for the root. This can be used to provide a human-readable
* identifier for the root, which may be useful for display purposes or for
* referencing the root in other parts of the application.
*
* @since 2024-11-05
*
* @var string|null
*/
protected ?string $name;
/**
* See [General fields: `_meta`](/specification/2025-11-25/basic/index#meta) for notes on `_meta` usage.
*
* @since 2025-06-18
*
* @var array<string, mixed>|null
*/
protected ?array $_meta;
/**
* @param string $uri @since 2024-11-05
* @param string|null $name @since 2024-11-05
* @param array<string, mixed>|null $_meta @since 2025-06-18
*/
public function __construct(
string $uri,
?string $name = null,
?array $_meta = null
) {
$this->uri = $uri;
$this->name = $name;
$this->_meta = $_meta;
}
/**
* Creates an instance from an array.
*
* @param array{
* uri: string,
* name?: string|null,
* _meta?: array<string, mixed>|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['uri']);
return new self(
self::asString($data['uri']),
self::asStringOrNull($data['name'] ?? null),
self::asArrayOrNull($data['_meta'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['uri'] = $this->uri;
if ($this->name !== null) {
$result['name'] = $this->name;
}
if ($this->_meta !== null) {
$result['_meta'] = $this->_meta;
}
return $result;
}
/**
* @return string
*/
public function getUri(): string
{
return $this->uri;
}
/**
* @return string|null
*/
public function getName(): ?string
{
return $this->name;
}
/**
* @return array<string, mixed>|null
*/
public function get_meta(): ?array
{
return $this->_meta;
}
}
@@ -0,0 +1,104 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Roots\DTO;
use WP\McpSchema\Common\JsonRpc\DTO\JSONRPCNotification;
use WP\McpSchema\Common\JsonRpc\DTO\NotificationParams;
use WP\McpSchema\Common\Protocol\Union\ClientNotificationInterface;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* A notification from the client to the server, informing it that the list of roots has changed.
* This notification should be sent whenever the client adds, removes, or modifies any root.
* The server should then request an updated list of roots using the ListRootsRequest.
*
* @since 2024-11-05
* @last-updated 2025-11-25 (modified property: params)
*
* @mcp-domain Client
* @mcp-subdomain Roots
* @mcp-version 2025-11-25
*/
class RootsListChangedNotification extends JSONRPCNotification implements ClientNotificationInterface
{
use ValidatesRequiredFields;
public const METHOD = 'notifications/roots/list_changed';
public const DISCRIMINATOR_FIELD = 'method';
public const DISCRIMINATOR_VALUE = 'notifications/roots/list_changed';
/**
* @var \WP\McpSchema\Common\JsonRpc\DTO\NotificationParams|null
*/
protected ?NotificationParams $typedParams;
/**
* @param '2.0' $jsonrpc @since 2025-11-25
* @param \WP\McpSchema\Common\JsonRpc\DTO\NotificationParams|null $params @since 2024-11-05
*/
public function __construct(
string $jsonrpc,
?NotificationParams $params = null
) {
parent::__construct(self::METHOD, $jsonrpc, null);
$this->typedParams = $params;
}
/**
* Creates an instance from an array.
*
* @param array{
* jsonrpc: '2.0',
* method: 'notifications/roots/list_changed',
* params?: array<string, mixed>|\WP\McpSchema\Common\JsonRpc\DTO\NotificationParams|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['jsonrpc']);
/** @var '2.0' $jsonrpc */
$jsonrpc = self::asString($data['jsonrpc']);
/** @var \WP\McpSchema\Common\JsonRpc\DTO\NotificationParams|null $params */
$params = isset($data['params'])
? (is_array($data['params'])
? NotificationParams::fromArray(self::asArray($data['params']))
: $data['params'])
: null;
return new self(
$jsonrpc,
$params
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
if ($this->typedParams !== null) {
$result['params'] = $this->typedParams->toArray();
}
return $result;
}
/**
* @return \WP\McpSchema\Common\JsonRpc\DTO\NotificationParams|null
*/
public function getTypedParams(): ?NotificationParams
{
return $this->typedParams;
}
}
@@ -0,0 +1,104 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Sampling\DTO;
use WP\McpSchema\Common\JsonRpc\DTO\JSONRPCRequest;
use WP\McpSchema\Common\Protocol\Union\ServerRequestInterface;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* A request from the server to sample an LLM via the client. The client has full discretion over which model to select. The client should also inform the user before beginning sampling, to allow them to inspect the request (human in the loop) and decide whether to approve it.
*
* @since 2024-11-05
* @last-updated 2025-11-25 (modified property: params)
*
* @mcp-domain Client
* @mcp-subdomain Sampling
* @mcp-version 2025-11-25
*/
class CreateMessageRequest extends JSONRPCRequest implements ServerRequestInterface
{
use ValidatesRequiredFields;
public const METHOD = 'sampling/createMessage';
public const DISCRIMINATOR_FIELD = 'method';
public const DISCRIMINATOR_VALUE = 'sampling/createMessage';
/**
* @var \WP\McpSchema\Client\Sampling\DTO\CreateMessageRequestParams
*/
protected CreateMessageRequestParams $typedParams;
/**
* @param '2.0' $jsonrpc @since 2025-11-25
* @param string|number $id @since 2025-11-25
* @param \WP\McpSchema\Client\Sampling\DTO\CreateMessageRequestParams $params @since 2024-11-05
*/
public function __construct(
string $jsonrpc,
$id,
CreateMessageRequestParams $params
) {
parent::__construct(self::METHOD, $jsonrpc, $id, null);
$this->typedParams = $params;
}
/**
* Creates an instance from an array.
*
* @param array{
* jsonrpc: '2.0',
* id: string|number,
* method: 'sampling/createMessage',
* params: array<string, mixed>|\WP\McpSchema\Client\Sampling\DTO\CreateMessageRequestParams
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['jsonrpc', 'id', 'params']);
/** @var '2.0' $jsonrpc */
$jsonrpc = self::asString($data['jsonrpc']);
/** @var string|number $id */
$id = self::asStringOrNumber($data['id']);
/** @var \WP\McpSchema\Client\Sampling\DTO\CreateMessageRequestParams $params */
$params = is_array($data['params'])
? CreateMessageRequestParams::fromArray(self::asArray($data['params']))
: $data['params'];
return new self(
$jsonrpc,
$id,
$params
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
$result['params'] = $this->typedParams->toArray();
return $result;
}
/**
* @return \WP\McpSchema\Client\Sampling\DTO\CreateMessageRequestParams
*/
public function getTypedParams(): CreateMessageRequestParams
{
return $this->typedParams;
}
}
@@ -0,0 +1,369 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Sampling\DTO;
use WP\McpSchema\Client\Tasks\DTO\TaskMetadata;
use WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta;
use WP\McpSchema\Common\Tasks\DTO\TaskAugmentedRequestParams;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
use WP\McpSchema\Server\Tools\DTO\Tool;
/**
* Parameters for a `sampling/createMessage` request.
*
* @since 2025-11-25
*
* @mcp-domain Client
* @mcp-subdomain Sampling
* @mcp-version 2025-11-25
*/
class CreateMessageRequestParams extends TaskAugmentedRequestParams
{
use ValidatesRequiredFields;
/**
* @since 2025-11-25
*
* @var array<\WP\McpSchema\Client\Sampling\DTO\SamplingMessage>
*/
protected array $messages;
/**
* The server's preferences for which model to select. The client MAY ignore these preferences.
*
* @since 2025-11-25
*
* @var \WP\McpSchema\Client\Sampling\DTO\ModelPreferences|null
*/
protected ?ModelPreferences $modelPreferences;
/**
* An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.
*
* @since 2025-11-25
*
* @var string|null
*/
protected ?string $systemPrompt;
/**
* A request to include context from one or more MCP servers (including the caller), to be attached to the prompt.
* The client MAY ignore this request.
*
* Default is "none". Values "thisServer" and "allServers" are soft-deprecated. Servers SHOULD only use these values if the client
* declares ClientCapabilities.sampling.context. These values may be removed in future spec releases.
*
* @since 2025-11-25
*
* @var 'none'|'thisServer'|'allServers'|null
*/
protected ?string $includeContext;
/**
* @since 2025-11-25
*
* @var float|null
*/
protected ?float $temperature;
/**
* The requested maximum number of tokens to sample (to prevent runaway completions).
*
* The client MAY choose to sample fewer tokens than the requested maximum.
*
* @since 2025-11-25
*
* @var float
*/
protected float $maxTokens;
/**
* @since 2025-11-25
*
* @var array<string>|null
*/
protected ?array $stopSequences;
/**
* Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
*
* @since 2025-11-25
*
* @var object|null
*/
protected ?object $metadata;
/**
* Tools that the model may use during generation.
* The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
*
* @since 2025-11-25
*
* @var array<\WP\McpSchema\Server\Tools\DTO\Tool>|null
*/
protected ?array $tools;
/**
* Controls how the model uses tools.
* The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
* Default is `{ mode: "auto" }`.
*
* @since 2025-11-25
*
* @var \WP\McpSchema\Client\Sampling\DTO\ToolChoice|null
*/
protected ?ToolChoice $toolChoice;
/**
* @param array<\WP\McpSchema\Client\Sampling\DTO\SamplingMessage> $messages @since 2025-11-25
* @param float $maxTokens @since 2025-11-25
* @param \WP\McpSchema\Client\Tasks\DTO\TaskMetadata|null $task @since 2025-11-25
* @param \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null $_meta @since 2025-11-25
* @param \WP\McpSchema\Client\Sampling\DTO\ModelPreferences|null $modelPreferences @since 2025-11-25
* @param string|null $systemPrompt @since 2025-11-25
* @param 'none'|'thisServer'|'allServers'|null $includeContext @since 2025-11-25
* @param float|null $temperature @since 2025-11-25
* @param array<string>|null $stopSequences @since 2025-11-25
* @param object|null $metadata @since 2025-11-25
* @param array<\WP\McpSchema\Server\Tools\DTO\Tool>|null $tools @since 2025-11-25
* @param \WP\McpSchema\Client\Sampling\DTO\ToolChoice|null $toolChoice @since 2025-11-25
*/
public function __construct(
array $messages,
float $maxTokens,
?TaskMetadata $task = null,
?RequestParamsMeta $_meta = null,
?ModelPreferences $modelPreferences = null,
?string $systemPrompt = null,
?string $includeContext = null,
?float $temperature = null,
?array $stopSequences = null,
?object $metadata = null,
?array $tools = null,
?ToolChoice $toolChoice = null
) {
parent::__construct($_meta, $task);
$this->messages = $messages;
$this->maxTokens = $maxTokens;
$this->modelPreferences = $modelPreferences;
$this->systemPrompt = $systemPrompt;
$this->includeContext = $includeContext;
$this->temperature = $temperature;
$this->stopSequences = $stopSequences;
$this->metadata = $metadata;
$this->tools = $tools;
$this->toolChoice = $toolChoice;
}
/**
* Creates an instance from an array.
*
* @param array{
* task?: array<string, mixed>|\WP\McpSchema\Client\Tasks\DTO\TaskMetadata|null,
* _meta?: array<string, mixed>|\WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null,
* messages: array<array<string, mixed>|\WP\McpSchema\Client\Sampling\DTO\SamplingMessage>,
* modelPreferences?: array<string, mixed>|\WP\McpSchema\Client\Sampling\DTO\ModelPreferences|null,
* systemPrompt?: string|null,
* includeContext?: 'none'|'thisServer'|'allServers'|null,
* temperature?: float|null,
* maxTokens: float,
* stopSequences?: array<string>|null,
* metadata?: object|null,
* tools?: array<array<string, mixed>|\WP\McpSchema\Server\Tools\DTO\Tool>|null,
* toolChoice?: array<string, mixed>|\WP\McpSchema\Client\Sampling\DTO\ToolChoice|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['messages', 'maxTokens']);
/** @var array<\WP\McpSchema\Client\Sampling\DTO\SamplingMessage> $messages */
$messages = array_map(
static fn($item) => is_array($item)
? SamplingMessage::fromArray($item)
: $item,
self::asArray($data['messages'])
);
/** @var \WP\McpSchema\Client\Tasks\DTO\TaskMetadata|null $task */
$task = isset($data['task'])
? (is_array($data['task'])
? TaskMetadata::fromArray(self::asArray($data['task']))
: $data['task'])
: null;
/** @var \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null $_meta */
$_meta = isset($data['_meta'])
? (is_array($data['_meta'])
? RequestParamsMeta::fromArray(self::asArray($data['_meta']))
: $data['_meta'])
: null;
/** @var \WP\McpSchema\Client\Sampling\DTO\ModelPreferences|null $modelPreferences */
$modelPreferences = isset($data['modelPreferences'])
? (is_array($data['modelPreferences'])
? ModelPreferences::fromArray(self::asArray($data['modelPreferences']))
: $data['modelPreferences'])
: null;
/** @var 'none'|'thisServer'|'allServers'|null $includeContext */
$includeContext = isset($data['includeContext'])
? self::asStringOrNull($data['includeContext'])
: null;
/** @var array<\WP\McpSchema\Server\Tools\DTO\Tool>|null $tools */
$tools = isset($data['tools'])
? array_map(
static fn($item) => is_array($item)
? Tool::fromArray($item)
: $item,
self::asArray($data['tools'])
)
: null;
/** @var \WP\McpSchema\Client\Sampling\DTO\ToolChoice|null $toolChoice */
$toolChoice = isset($data['toolChoice'])
? (is_array($data['toolChoice'])
? ToolChoice::fromArray(self::asArray($data['toolChoice']))
: $data['toolChoice'])
: null;
return new self(
$messages,
self::asFloat($data['maxTokens']),
$task,
$_meta,
$modelPreferences,
self::asStringOrNull($data['systemPrompt'] ?? null),
$includeContext,
self::asFloatOrNull($data['temperature'] ?? null),
self::asStringArrayOrNull($data['stopSequences'] ?? null),
self::asObjectOrNull($data['metadata'] ?? null),
$tools,
$toolChoice
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
$result['messages'] = array_map(static fn($item) => $item->toArray(), $this->messages);
if ($this->modelPreferences !== null) {
$result['modelPreferences'] = $this->modelPreferences->toArray();
}
if ($this->systemPrompt !== null) {
$result['systemPrompt'] = $this->systemPrompt;
}
if ($this->includeContext !== null) {
$result['includeContext'] = $this->includeContext;
}
if ($this->temperature !== null) {
$result['temperature'] = $this->temperature;
}
$result['maxTokens'] = $this->maxTokens;
if ($this->stopSequences !== null) {
$result['stopSequences'] = $this->stopSequences;
}
if ($this->metadata !== null) {
$result['metadata'] = $this->metadata;
}
if ($this->tools !== null) {
$result['tools'] = array_map(static fn($item) => $item->toArray(), $this->tools);
}
if ($this->toolChoice !== null) {
$result['toolChoice'] = $this->toolChoice->toArray();
}
return $result;
}
/**
* @return array<\WP\McpSchema\Client\Sampling\DTO\SamplingMessage>
*/
public function getMessages(): array
{
return $this->messages;
}
/**
* @return \WP\McpSchema\Client\Sampling\DTO\ModelPreferences|null
*/
public function getModelPreferences(): ?ModelPreferences
{
return $this->modelPreferences;
}
/**
* @return string|null
*/
public function getSystemPrompt(): ?string
{
return $this->systemPrompt;
}
/**
* @return 'none'|'thisServer'|'allServers'|null
*/
public function getIncludeContext(): ?string
{
return $this->includeContext;
}
/**
* @return float|null
*/
public function getTemperature(): ?float
{
return $this->temperature;
}
/**
* @return float
*/
public function getMaxTokens(): float
{
return $this->maxTokens;
}
/**
* @return array<string>|null
*/
public function getStopSequences(): ?array
{
return $this->stopSequences;
}
/**
* @return object|null
*/
public function getMetadata(): ?object
{
return $this->metadata;
}
/**
* @return array<\WP\McpSchema\Server\Tools\DTO\Tool>|null
*/
public function getTools(): ?array
{
return $this->tools;
}
/**
* @return \WP\McpSchema\Client\Sampling\DTO\ToolChoice|null
*/
public function getToolChoice(): ?ToolChoice
{
return $this->toolChoice;
}
}
@@ -0,0 +1,191 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Sampling\DTO;
use WP\McpSchema\Client\Lifecycle\Union\ClientResultInterface;
use WP\McpSchema\Common\Protocol\DTO\Result;
use WP\McpSchema\Common\Protocol\Factory\SamplingMessageContentBlockFactory;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* The client's response to a sampling/createMessage request from the server.
* The client should inform the user before returning the sampled message, to allow them
* to inspect the response (human in the loop) and decide whether to allow the server to see it.
*
* @since 2024-11-05
* @last-updated 2025-11-25 (modified properties: content, role)
*
* @mcp-domain Client
* @mcp-subdomain Sampling
* @mcp-version 2025-11-25
*/
class CreateMessageResult extends Result implements ClientResultInterface
{
use ValidatesRequiredFields;
/**
* Wire keys this class models. Anything else is kept in $additionalProperties.
*
* @var array<int, string>
*/
private const KNOWN_KEYS = ['_meta', 'model', 'stopReason', 'role', 'content'];
/**
* The name of the model that generated the message.
*
* @since 2024-11-05
*
* @var string
*/
protected string $model;
/**
* The reason why sampling stopped, if known.
*
* Standard values:
* - "endTurn": Natural end of the assistant's turn
* - "stopSequence": A stop sequence was encountered
* - "maxTokens": Maximum token limit was reached
* - "toolUse": The model wants to use one or more tools
*
* This field is an open string to allow for provider-specific stop reasons.
*
* @since 2024-11-05
*
* @var "endTurn"|"stopSequence"|"maxTokens"|"toolUse"|string|null
*/
protected $stopReason;
/**
* @since 2024-11-05
*
* @var 'user'|'assistant'
*/
protected string $role;
/**
* @since 2024-11-05
*
* @var array<\WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface|\WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface>
*/
protected array $content;
/**
* @param string $model @since 2024-11-05
* @param 'user'|'assistant' $role @since 2024-11-05
* @param array<\WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface|\WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface> $content @since 2024-11-05
* @param array<string, mixed>|null $_meta @since 2024-11-05
* @param "endTurn"|"stopSequence"|"maxTokens"|"toolUse"|string|null $stopReason @since 2024-11-05
* @param array<string, mixed>|null $additionalProperties
*/
public function __construct(
string $model,
string $role,
array $content,
?array $_meta = null,
$stopReason = null,
?array $additionalProperties = null
) {
parent::__construct($_meta, $additionalProperties);
$this->model = $model;
$this->role = $role;
$this->content = $content;
$this->stopReason = $stopReason;
}
/**
* Creates an instance from an array.
*
* @param array{
* _meta?: array<string, mixed>|null,
* model: string,
* stopReason?: "endTurn"|"stopSequence"|"maxTokens"|"toolUse"|string|null,
* role: 'user'|'assistant',
* content: array<\WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface|\WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface>
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['model', 'role', 'content']);
/** @var 'user'|'assistant' $role */
$role = self::asString($data['role']);
/** @var array<\WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface|\WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface> $content */
$content = array_map(
static fn($item) => is_array($item)
? SamplingMessageContentBlockFactory::fromArray($item)
: $item,
self::asArray($data['content'])
);
/** @var "endTurn"|"stopSequence"|"maxTokens"|"toolUse"|string|null $stopReason */
$stopReason = isset($data['stopReason'])
? $data['stopReason']
: null;
return new self(
self::asString($data['model']),
$role,
$content,
self::asArrayOrNull($data['_meta'] ?? null),
$stopReason,
self::additionalFields($data, self::KNOWN_KEYS)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
$result['model'] = $this->model;
if ($this->stopReason !== null) {
$result['stopReason'] = $this->stopReason;
}
$result['role'] = $this->role;
$result['content'] = array_map(static fn($item) => (is_object($item) && method_exists($item, 'toArray')) ? $item->toArray() : $item, $this->content);
return $result;
}
/**
* @return string
*/
public function getModel(): string
{
return $this->model;
}
/**
* @return "endTurn"|"stopSequence"|"maxTokens"|"toolUse"|string|null
*/
public function getStopReason()
{
return $this->stopReason;
}
/**
* @return 'user'|'assistant'
*/
public function getRole(): string
{
return $this->role;
}
/**
* @return array<\WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface|\WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface>
*/
public function getContent(): array
{
return $this->content;
}
}
@@ -0,0 +1,91 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Sampling\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Hints to use for model selection.
*
* Keys not declared here are currently left unspecified by the spec and are up
* to the client to interpret.
*
* @since 2024-11-05
*
* @mcp-domain Client
* @mcp-subdomain Sampling
* @mcp-version 2025-11-25
*/
class ModelHint extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* A hint for a model name.
*
* The client SHOULD treat this as a substring of a model name; for example:
* - `claude-3-5-sonnet` should match `claude-3-5-sonnet-20241022`
* - `sonnet` should match `claude-3-5-sonnet-20241022`, `claude-3-sonnet-20240229`, etc.
* - `claude` should match any Claude model
*
* The client MAY also map the string to a different provider's model name or a different model family, as long as it fills a similar niche; for example:
* - `gemini-1.5-flash` could match `claude-3-haiku-20240307`
*
* @since 2024-11-05
*
* @var string|null
*/
protected ?string $name;
/**
* @param string|null $name @since 2024-11-05
*/
public function __construct(
?string $name = null
) {
$this->name = $name;
}
/**
* Creates an instance from an array.
*
* @param array{
* name?: string|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
return new self(
self::asStringOrNull($data['name'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
if ($this->name !== null) {
$result['name'] = $this->name;
}
return $result;
}
/**
* @return string|null
*/
public function getName(): ?string
{
return $this->name;
}
}
@@ -0,0 +1,188 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Sampling\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* The server's preferences for model selection, requested of the client during sampling.
*
* Because LLMs can vary along multiple dimensions, choosing the "best" model is
* rarely straightforward. Different models excel in different areas—some are
* faster but less capable, others are more capable but more expensive, and so
* on. This interface allows servers to express their priorities across multiple
* dimensions to help clients make an appropriate selection for their use case.
*
* These preferences are always advisory. The client MAY ignore them. It is also
* up to the client to decide how to interpret these preferences and how to
* balance them against other considerations.
*
* @since 2024-11-05
* @last-updated 2025-11-25 (modified property: hints)
*
* @mcp-domain Client
* @mcp-subdomain Sampling
* @mcp-version 2025-11-25
*/
class ModelPreferences extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* Optional hints to use for model selection.
*
* If multiple hints are specified, the client MUST evaluate them in order
* (such that the first match is taken).
*
* The client SHOULD prioritize these hints over the numeric priorities, but
* MAY still use the priorities to select from ambiguous matches.
*
* @since 2024-11-05
*
* @var array<\WP\McpSchema\Client\Sampling\DTO\ModelHint>|null
*/
protected ?array $hints;
/**
* How much to prioritize cost when selecting a model. A value of 0 means cost
* is not important, while a value of 1 means cost is the most important
* factor.
*
* @since 2024-11-05
*
* @var float|null
*/
protected ?float $costPriority;
/**
* How much to prioritize sampling speed (latency) when selecting a model. A
* value of 0 means speed is not important, while a value of 1 means speed is
* the most important factor.
*
* @since 2024-11-05
*
* @var float|null
*/
protected ?float $speedPriority;
/**
* How much to prioritize intelligence and capabilities when selecting a
* model. A value of 0 means intelligence is not important, while a value of 1
* means intelligence is the most important factor.
*
* @since 2024-11-05
*
* @var float|null
*/
protected ?float $intelligencePriority;
/**
* @param array<\WP\McpSchema\Client\Sampling\DTO\ModelHint>|null $hints @since 2024-11-05
* @param float|null $costPriority @since 2024-11-05
* @param float|null $speedPriority @since 2024-11-05
* @param float|null $intelligencePriority @since 2024-11-05
*/
public function __construct(
?array $hints = null,
?float $costPriority = null,
?float $speedPriority = null,
?float $intelligencePriority = null
) {
$this->hints = $hints;
$this->costPriority = $costPriority;
$this->speedPriority = $speedPriority;
$this->intelligencePriority = $intelligencePriority;
}
/**
* Creates an instance from an array.
*
* @param array{
* hints?: array<array<string, mixed>|\WP\McpSchema\Client\Sampling\DTO\ModelHint>|null,
* costPriority?: float|null,
* speedPriority?: float|null,
* intelligencePriority?: float|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
/** @var array<\WP\McpSchema\Client\Sampling\DTO\ModelHint>|null $hints */
$hints = isset($data['hints'])
? array_map(
static fn($item) => is_array($item)
? ModelHint::fromArray($item)
: $item,
self::asArray($data['hints'])
)
: null;
return new self(
$hints,
self::asFloatOrNull($data['costPriority'] ?? null),
self::asFloatOrNull($data['speedPriority'] ?? null),
self::asFloatOrNull($data['intelligencePriority'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
if ($this->hints !== null) {
$result['hints'] = array_map(static fn($item) => $item->toArray(), $this->hints);
}
if ($this->costPriority !== null) {
$result['costPriority'] = $this->costPriority;
}
if ($this->speedPriority !== null) {
$result['speedPriority'] = $this->speedPriority;
}
if ($this->intelligencePriority !== null) {
$result['intelligencePriority'] = $this->intelligencePriority;
}
return $result;
}
/**
* @return array<\WP\McpSchema\Client\Sampling\DTO\ModelHint>|null
*/
public function getHints(): ?array
{
return $this->hints;
}
/**
* @return float|null
*/
public function getCostPriority(): ?float
{
return $this->costPriority;
}
/**
* @return float|null
*/
public function getSpeedPriority(): ?float
{
return $this->speedPriority;
}
/**
* @return float|null
*/
public function getIntelligencePriority(): ?float
{
return $this->intelligencePriority;
}
}
@@ -0,0 +1,137 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Sampling\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Protocol\Factory\SamplingMessageContentBlockFactory;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Describes a message issued to or received from an LLM API.
*
* @since 2024-11-05
* @last-updated 2025-11-25 (added properties: _meta; modified properties: content, role)
*
* @mcp-domain Client
* @mcp-subdomain Sampling
* @mcp-version 2025-11-25
*/
class SamplingMessage extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* @since 2024-11-05
*
* @var 'user'|'assistant'
*/
protected string $role;
/**
* @since 2024-11-05
*
* @var array<\WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface|\WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface>
*/
protected array $content;
/**
* See [General fields: `_meta`](/specification/2025-11-25/basic/index#meta) for notes on `_meta` usage.
*
* @since 2025-11-25
*
* @var array<string, mixed>|null
*/
protected ?array $_meta;
/**
* @param 'user'|'assistant' $role @since 2024-11-05
* @param array<\WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface|\WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface> $content @since 2024-11-05
* @param array<string, mixed>|null $_meta @since 2025-11-25
*/
public function __construct(
string $role,
array $content,
?array $_meta = null
) {
$this->role = $role;
$this->content = $content;
$this->_meta = $_meta;
}
/**
* Creates an instance from an array.
*
* @param array{
* role: 'user'|'assistant',
* content: array<\WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface|\WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface>,
* _meta?: array<string, mixed>|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['role', 'content']);
/** @var 'user'|'assistant' $role */
$role = self::asString($data['role']);
/** @var array<\WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface|\WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface> $content */
$content = array_map(
static fn($item) => is_array($item)
? SamplingMessageContentBlockFactory::fromArray($item)
: $item,
self::asArray($data['content'])
);
return new self(
$role,
$content,
self::asArrayOrNull($data['_meta'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['role'] = $this->role;
$result['content'] = array_map(static fn($item) => (is_object($item) && method_exists($item, 'toArray')) ? $item->toArray() : $item, $this->content);
if ($this->_meta !== null) {
$result['_meta'] = $this->_meta;
}
return $result;
}
/**
* @return 'user'|'assistant'
*/
public function getRole(): string
{
return $this->role;
}
/**
* @return array<\WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface|\WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface>
*/
public function getContent(): array
{
return $this->content;
}
/**
* @return array<string, mixed>|null
*/
public function get_meta(): ?array
{
return $this->_meta;
}
}
@@ -0,0 +1,88 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Sampling\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Controls tool selection behavior for sampling requests.
*
* @since 2025-11-25
*
* @mcp-domain Client
* @mcp-subdomain Sampling
* @mcp-version 2025-11-25
*/
class ToolChoice extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* Controls the tool use ability of the model:
* - "auto": Model decides whether to use tools (default)
* - "required": Model MUST use at least one tool before completing
* - "none": Model MUST NOT use any tools
*
* @since 2025-11-25
*
* @var 'auto'|'required'|'none'|null
*/
protected ?string $mode;
/**
* @param 'auto'|'required'|'none'|null $mode @since 2025-11-25
*/
public function __construct(
?string $mode = null
) {
$this->mode = $mode;
}
/**
* Creates an instance from an array.
*
* @param array{
* mode?: 'auto'|'required'|'none'|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
/** @var 'auto'|'required'|'none'|null $mode */
$mode = isset($data['mode'])
? self::asStringOrNull($data['mode'])
: null;
return new self(
$mode
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
if ($this->mode !== null) {
$result['mode'] = $this->mode;
}
return $result;
}
/**
* @return 'auto'|'required'|'none'|null
*/
public function getMode(): ?string
{
return $this->mode;
}
}
@@ -0,0 +1,225 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Sampling\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Protocol\Factory\ContentBlockFactory;
use WP\McpSchema\Common\Protocol\Union\ContentBlockInterface;
use WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* The result of a tool use, provided by the user back to the assistant.
*
* @since 2025-11-25
*
* @mcp-domain Client
* @mcp-subdomain Sampling
* @mcp-version 2025-11-25
*/
class ToolResultContent extends AbstractDataTransferObject implements SamplingMessageContentBlockInterface
{
use ValidatesRequiredFields;
public const TYPE = 'tool_result';
public const DISCRIMINATOR_FIELD = 'type';
public const DISCRIMINATOR_VALUE = 'tool_result';
/**
* @since 2025-11-25
*
* @var 'tool_result'
*/
protected string $type;
/**
* The ID of the tool use this result corresponds to.
*
* This MUST match the ID from a previous ToolUseContent.
*
* @since 2025-11-25
*
* @var string
*/
protected string $toolUseId;
/**
* The unstructured result content of the tool use.
*
* This has the same format as CallToolResult.content and can include text, images,
* audio, resource links, and embedded resources.
*
* @since 2025-11-25
*
* @var array<\WP\McpSchema\Common\Protocol\Union\ContentBlockInterface>
*/
protected array $content;
/**
* An optional structured result object.
*
* If the tool defined an outputSchema, this SHOULD conform to that schema.
*
* @since 2025-11-25
*
* @var array<string, mixed>|null
*/
protected ?array $structuredContent;
/**
* Whether the tool use resulted in an error.
*
* If true, the content typically describes the error that occurred.
* Default: false
*
* @since 2025-11-25
*
* @var bool|null
*/
protected ?bool $isError;
/**
* Optional metadata about the tool result. Clients SHOULD preserve this field when
* including tool results in subsequent sampling requests to enable caching optimizations.
*
* See [General fields: `_meta`](/specification/2025-11-25/basic/index#meta) for notes on `_meta` usage.
*
* @since 2025-11-25
*
* @var array<string, mixed>|null
*/
protected ?array $_meta;
/**
* @param string $toolUseId @since 2025-11-25
* @param array<\WP\McpSchema\Common\Protocol\Union\ContentBlockInterface> $content @since 2025-11-25
* @param array<string, mixed>|null $structuredContent @since 2025-11-25
* @param bool|null $isError @since 2025-11-25
* @param array<string, mixed>|null $_meta @since 2025-11-25
*/
public function __construct(
string $toolUseId,
array $content,
?array $structuredContent = null,
?bool $isError = null,
?array $_meta = null
) {
$this->type = self::TYPE;
$this->toolUseId = $toolUseId;
$this->content = $content;
$this->structuredContent = $structuredContent;
$this->isError = $isError;
$this->_meta = $_meta;
}
/**
* Creates an instance from an array.
*
* @param array{
* type: 'tool_result',
* toolUseId: string,
* content: array<array<string, mixed>|\WP\McpSchema\Common\Protocol\Union\ContentBlockInterface>,
* structuredContent?: array<string, mixed>|null,
* isError?: bool|null,
* _meta?: array<string, mixed>|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['toolUseId', 'content']);
/** @var array<\WP\McpSchema\Common\Protocol\Union\ContentBlockInterface> $content */
$content = array_map(
static fn($item) => is_array($item)
? ContentBlockFactory::fromArray($item)
: $item,
self::asArray($data['content'])
);
return new self(
self::asString($data['toolUseId']),
$content,
self::asArrayOrNull($data['structuredContent'] ?? null),
self::asBoolOrNull($data['isError'] ?? null),
self::asArrayOrNull($data['_meta'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['type'] = $this->type;
$result['toolUseId'] = $this->toolUseId;
$result['content'] = array_map(static fn($item) => $item->toArray(), $this->content);
if ($this->structuredContent !== null) {
$result['structuredContent'] = $this->structuredContent;
}
if ($this->isError !== null) {
$result['isError'] = $this->isError;
}
if ($this->_meta !== null) {
$result['_meta'] = $this->_meta;
}
return $result;
}
/**
* @return 'tool_result'
*/
public function getType(): string
{
return $this->type;
}
/**
* @return string
*/
public function getToolUseId(): string
{
return $this->toolUseId;
}
/**
* @return array<\WP\McpSchema\Common\Protocol\Union\ContentBlockInterface>
*/
public function getContent(): array
{
return $this->content;
}
/**
* @return array<string, mixed>|null
*/
public function getStructuredContent(): ?array
{
return $this->structuredContent;
}
/**
* @return bool|null
*/
public function getIsError(): ?bool
{
return $this->isError;
}
/**
* @return array<string, mixed>|null
*/
public function get_meta(): ?array
{
return $this->_meta;
}
}
@@ -0,0 +1,180 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Sampling\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* A request from the assistant to call a tool.
*
* @since 2025-11-25
*
* @mcp-domain Client
* @mcp-subdomain Sampling
* @mcp-version 2025-11-25
*/
class ToolUseContent extends AbstractDataTransferObject implements SamplingMessageContentBlockInterface
{
use ValidatesRequiredFields;
public const TYPE = 'tool_use';
public const DISCRIMINATOR_FIELD = 'type';
public const DISCRIMINATOR_VALUE = 'tool_use';
/**
* @since 2025-11-25
*
* @var 'tool_use'
*/
protected string $type;
/**
* A unique identifier for this tool use.
*
* This ID is used to match tool results to their corresponding tool uses.
*
* @since 2025-11-25
*
* @var string
*/
protected string $id;
/**
* The name of the tool to call.
*
* @since 2025-11-25
*
* @var string
*/
protected string $name;
/**
* The arguments to pass to the tool, conforming to the tool's input schema.
*
* @since 2025-11-25
*
* @var array<string, mixed>
*/
protected array $input;
/**
* Optional metadata about the tool use. Clients SHOULD preserve this field when
* including tool uses in subsequent sampling requests to enable caching optimizations.
*
* See [General fields: `_meta`](/specification/2025-11-25/basic/index#meta) for notes on `_meta` usage.
*
* @since 2025-11-25
*
* @var array<string, mixed>|null
*/
protected ?array $_meta;
/**
* @param string $id @since 2025-11-25
* @param string $name @since 2025-11-25
* @param array<string, mixed> $input @since 2025-11-25
* @param array<string, mixed>|null $_meta @since 2025-11-25
*/
public function __construct(
string $id,
string $name,
array $input,
?array $_meta = null
) {
$this->type = self::TYPE;
$this->id = $id;
$this->name = $name;
$this->input = $input;
$this->_meta = $_meta;
}
/**
* Creates an instance from an array.
*
* @param array{
* type: 'tool_use',
* id: string,
* name: string,
* input: array<string, mixed>,
* _meta?: array<string, mixed>|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['id', 'name', 'input']);
return new self(
self::asString($data['id']),
self::asString($data['name']),
self::asArray($data['input']),
self::asArrayOrNull($data['_meta'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['type'] = $this->type;
$result['id'] = $this->id;
$result['name'] = $this->name;
$result['input'] = $this->input;
if ($this->_meta !== null) {
$result['_meta'] = $this->_meta;
}
return $result;
}
/**
* @return 'tool_use'
*/
public function getType(): string
{
return $this->type;
}
/**
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @return array<string, mixed>
*/
public function getInput(): array
{
return $this->input;
}
/**
* @return array<string, mixed>|null
*/
public function get_meta(): ?array
{
return $this->_meta;
}
}
@@ -0,0 +1,98 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Tasks\DTO;
use WP\McpSchema\Common\Protocol\DTO\Result;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* A response to a task-augmented request.
*
* @since 2025-11-25
*
* @mcp-domain Client
* @mcp-subdomain Tasks
* @mcp-version 2025-11-25
*/
class CreateTaskResult extends Result
{
use ValidatesRequiredFields;
/**
* Wire keys this class models. Anything else is kept in $additionalProperties.
*
* @var array<int, string>
*/
private const KNOWN_KEYS = ['_meta', 'task'];
/**
* @since 2025-11-25
*
* @var \WP\McpSchema\Client\Tasks\DTO\Task
*/
protected Task $task;
/**
* @param \WP\McpSchema\Client\Tasks\DTO\Task $task @since 2025-11-25
* @param array<string, mixed>|null $_meta @since 2025-11-25
* @param array<string, mixed>|null $additionalProperties
*/
public function __construct(
Task $task,
?array $_meta = null,
?array $additionalProperties = null
) {
parent::__construct($_meta, $additionalProperties);
$this->task = $task;
}
/**
* Creates an instance from an array.
*
* @param array{
* _meta?: array<string, mixed>|null,
* task: array<string, mixed>|\WP\McpSchema\Client\Tasks\DTO\Task
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['task']);
/** @var \WP\McpSchema\Client\Tasks\DTO\Task $task */
$task = is_array($data['task'])
? Task::fromArray(self::asArray($data['task']))
: $data['task'];
return new self(
$task,
self::asArrayOrNull($data['_meta'] ?? null),
self::additionalFields($data, self::KNOWN_KEYS)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
$result['task'] = $this->task->toArray();
return $result;
}
/**
* @return \WP\McpSchema\Client\Tasks\DTO\Task
*/
public function getTask(): Task
{
return $this->task;
}
}
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Tasks\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Metadata for associating messages with a task.
* Include this in the `_meta` field under the key `io.modelcontextprotocol/related-task`.
*
* @since 2025-11-25
*
* @mcp-domain Client
* @mcp-subdomain Tasks
* @mcp-version 2025-11-25
*/
class RelatedTaskMetadata extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* The task identifier this message is associated with.
*
* @since 2025-11-25
*
* @var string
*/
protected string $taskId;
/**
* @param string $taskId @since 2025-11-25
*/
public function __construct(
string $taskId
) {
$this->taskId = $taskId;
}
/**
* Creates an instance from an array.
*
* @param array{
* taskId: string
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['taskId']);
return new self(
self::asString($data['taskId'])
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['taskId'] = $this->taskId;
return $result;
}
/**
* @return string
*/
public function getTaskId(): string
{
return $this->taskId;
}
}
@@ -0,0 +1,231 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Tasks\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Data associated with a task.
*
* @since 2025-11-25
*
* @mcp-domain Client
* @mcp-subdomain Tasks
* @mcp-version 2025-11-25
*/
class Task extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* The task identifier.
*
* @since 2025-11-25
*
* @var string
*/
protected string $taskId;
/**
* Current task state.
*
* @since 2025-11-25
*
* @var 'working'|'input_required'|'completed'|'failed'|'cancelled'
*/
protected string $status;
/**
* Optional human-readable message describing the current task state.
* This can provide context for any status, including:
* - Reasons for "cancelled" status
* - Summaries for "completed" status
* - Diagnostic information for "failed" status (e.g., error details, what went wrong)
*
* @since 2025-11-25
*
* @var string|null
*/
protected ?string $statusMessage;
/**
* ISO 8601 timestamp when the task was created.
*
* @since 2025-11-25
*
* @var string
*/
protected string $createdAt;
/**
* ISO 8601 timestamp when the task was last updated.
*
* @since 2025-11-25
*
* @var string
*/
protected string $lastUpdatedAt;
/**
* Actual retention duration from creation in milliseconds, null for unlimited.
*
* @since 2025-11-25
*
* @var int|null
*/
protected ?int $ttl;
/**
* Suggested polling interval in milliseconds.
*
* @since 2025-11-25
*
* @var int|null
*/
protected ?int $pollInterval;
/**
* @param string $taskId @since 2025-11-25
* @param 'working'|'input_required'|'completed'|'failed'|'cancelled' $status @since 2025-11-25
* @param string $createdAt @since 2025-11-25
* @param string $lastUpdatedAt @since 2025-11-25
* @param int|null $ttl @since 2025-11-25
* @param string|null $statusMessage @since 2025-11-25
* @param int|null $pollInterval @since 2025-11-25
*/
public function __construct(
string $taskId,
string $status,
string $createdAt,
string $lastUpdatedAt,
?int $ttl,
?string $statusMessage = null,
?int $pollInterval = null
) {
$this->taskId = $taskId;
$this->status = $status;
$this->createdAt = $createdAt;
$this->lastUpdatedAt = $lastUpdatedAt;
$this->ttl = $ttl;
$this->statusMessage = $statusMessage;
$this->pollInterval = $pollInterval;
}
/**
* Creates an instance from an array.
*
* @param array{
* taskId: string,
* status: 'working'|'input_required'|'completed'|'failed'|'cancelled',
* statusMessage?: string|null,
* createdAt: string,
* lastUpdatedAt: string,
* ttl: int|null,
* pollInterval?: int|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['taskId', 'status', 'createdAt', 'lastUpdatedAt', 'ttl']);
/** @var 'working'|'input_required'|'completed'|'failed'|'cancelled' $status */
$status = self::asString($data['status']);
return new self(
self::asString($data['taskId']),
$status,
self::asString($data['createdAt']),
self::asString($data['lastUpdatedAt']),
self::asInt($data['ttl']),
self::asStringOrNull($data['statusMessage'] ?? null),
self::asIntOrNull($data['pollInterval'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['taskId'] = $this->taskId;
$result['status'] = $this->status;
if ($this->statusMessage !== null) {
$result['statusMessage'] = $this->statusMessage;
}
$result['createdAt'] = $this->createdAt;
$result['lastUpdatedAt'] = $this->lastUpdatedAt;
if ($this->ttl !== null) {
$result['ttl'] = $this->ttl;
}
if ($this->pollInterval !== null) {
$result['pollInterval'] = $this->pollInterval;
}
return $result;
}
/**
* @return string
*/
public function getTaskId(): string
{
return $this->taskId;
}
/**
* @return 'working'|'input_required'|'completed'|'failed'|'cancelled'
*/
public function getStatus(): string
{
return $this->status;
}
/**
* @return string|null
*/
public function getStatusMessage(): ?string
{
return $this->statusMessage;
}
/**
* @return string
*/
public function getCreatedAt(): string
{
return $this->createdAt;
}
/**
* @return string
*/
public function getLastUpdatedAt(): string
{
return $this->lastUpdatedAt;
}
/**
* @return int|null
*/
public function getTtl(): ?int
{
return $this->ttl;
}
/**
* @return int|null
*/
public function getPollInterval(): ?int
{
return $this->pollInterval;
}
}
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Tasks\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Metadata for augmenting a request with task execution.
* Include this in the `task` field of the request parameters.
*
* @since 2025-11-25
*
* @mcp-domain Client
* @mcp-subdomain Tasks
* @mcp-version 2025-11-25
*/
class TaskMetadata extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* Requested duration in milliseconds to retain task from creation.
*
* @since 2025-11-25
*
* @var int|null
*/
protected ?int $ttl;
/**
* @param int|null $ttl @since 2025-11-25
*/
public function __construct(
?int $ttl = null
) {
$this->ttl = $ttl;
}
/**
* Creates an instance from an array.
*
* @param array{
* ttl?: int|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
return new self(
self::asIntOrNull($data['ttl'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
if ($this->ttl !== null) {
$result['ttl'] = $this->ttl;
}
return $result;
}
/**
* @return int|null
*/
public function getTtl(): ?int
{
return $this->ttl;
}
}
@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Client\Tasks\Enum;
use WP\McpSchema\Common\AbstractEnum;
/**
* The status of a task.
*
* @mcp-domain Client
* @mcp-subdomain Tasks
* @mcp-version 2025-11-25
*/
final class TaskStatus extends AbstractEnum
{
public const WORKING = 'working';
public const INPUT_REQUIRED = 'input_required';
public const COMPLETED = 'completed';
public const FAILED = 'failed';
public const CANCELLED = 'cancelled';
public static function working(): self
{
return self::from('working');
}
public static function inputRequired(): self
{
return self::from('input_required');
}
public static function completed(): self
{
return self::from('completed');
}
public static function failed(): self
{
return self::from('failed');
}
public static function cancelled(): self
{
return self::from('cancelled');
}
/**
* Returns all valid values for this enum.
*
* @return string[]
*/
public static function values(): array
{
return [
self::WORKING,
self::INPUT_REQUIRED,
self::COMPLETED,
self::FAILED,
self::CANCELLED,
];
}
}
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common;
/**
* Base class for all Data Transfer Objects.
*
* @mcp-version 2025-11-25
*/
abstract class AbstractDataTransferObject
{
/**
* Creates an instance from an array.
*
* @param array<string, mixed> $data
* @return static
*/
abstract public static function fromArray(array $data): self;
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
abstract public function toArray(): array;
/**
* Converts the instance to JSON.
*
* @return string
*/
public function toJson(): string
{
return json_encode($this->toArray(), JSON_THROW_ON_ERROR);
}
/**
* Creates an instance from JSON.
*
* @param string $json
* @return static
*/
public static function fromJson(string $json): self
{
/** @var array<string, mixed> $data */
$data = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
return static::fromArray($data);
}
}
@@ -0,0 +1,115 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common;
/**
* Base class for PHP 7.4 enum emulation.
*
* @mcp-version 2025-11-25
*/
abstract class AbstractEnum
{
/** @var string */
private string $value;
/** @var array<string, static> */
private static array $instances = [];
/**
* @param string $value
*/
private function __construct(string $value)
{
$this->value = $value;
}
/**
* Creates an instance from a value.
*
* @param string $value
* @return static
* @throws \InvalidArgumentException
*/
public static function from(string $value): self
{
$values = static::values();
if (!in_array($value, $values, true)) {
throw new \InvalidArgumentException(
sprintf('Invalid enum value: %s. Valid values: %s', $value, implode(', ', $values))
);
}
$key = static::class . '::' . $value;
if (!isset(self::$instances[$key])) {
/** @phpstan-ignore new.static (Intentional: private constructor prevents subclass override) */
self::$instances[$key] = new static($value);
}
return self::$instances[$key];
}
/**
* Creates an instance from a value, or null if invalid.
*
* @param string $value
* @return static|null
*/
public static function tryFrom(string $value): ?self
{
try {
return static::from($value);
} catch (\InvalidArgumentException $e) {
return null;
}
}
/**
* Returns all valid values for this enum.
*
* @return string[]
*/
abstract public static function values(): array;
/**
* Returns all cases as instances.
*
* @return static[]
*/
public static function cases(): array
{
return array_map(fn(string $value) => static::from($value), static::values());
}
/**
* Gets the enum value.
*
* @return string
*/
public function getValue(): string
{
return $this->value;
}
/**
* Converts to string.
*
* @return string
*/
public function __toString(): string
{
return $this->value;
}
/**
* Compares with another instance.
*
* @param self $other
* @return bool
*/
public function equals(self $other): bool
{
return $this->value === $other->value && static::class === get_class($other);
}
}
@@ -0,0 +1,187 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Content\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Protocol\DTO\Annotations;
use WP\McpSchema\Common\Protocol\Union\ContentBlockInterface;
use WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Audio provided to or from an LLM.
*
* @since 2025-03-26
* @last-updated 2025-11-25 (modified property: annotations)
*
* @mcp-domain Common
* @mcp-subdomain Content
* @mcp-version 2025-11-25
*/
class AudioContent extends AbstractDataTransferObject implements SamplingMessageContentBlockInterface, ContentBlockInterface
{
use ValidatesRequiredFields;
public const TYPE = 'audio';
public const DISCRIMINATOR_FIELD = 'type';
public const DISCRIMINATOR_VALUE = 'audio';
/**
* @since 2025-03-26
*
* @var 'audio'
*/
protected string $type;
/**
* The base64-encoded audio data.
*
* @since 2025-03-26
*
* @var string
*/
protected string $data;
/**
* The MIME type of the audio. Different providers may support different audio types.
*
* @since 2025-03-26
*
* @var string
*/
protected string $mimeType;
/**
* Optional annotations for the client.
*
* @since 2025-03-26
*
* @var \WP\McpSchema\Common\Protocol\DTO\Annotations|null
*/
protected ?Annotations $annotations;
/**
* See [General fields: `_meta`](/specification/2025-11-25/basic/index#meta) for notes on `_meta` usage.
*
* @since 2025-06-18
*
* @var array<string, mixed>|null
*/
protected ?array $_meta;
/**
* @param string $data @since 2025-03-26
* @param string $mimeType @since 2025-03-26
* @param \WP\McpSchema\Common\Protocol\DTO\Annotations|null $annotations @since 2025-03-26
* @param array<string, mixed>|null $_meta @since 2025-06-18
*/
public function __construct(
string $data,
string $mimeType,
?Annotations $annotations = null,
?array $_meta = null
) {
$this->type = self::TYPE;
$this->data = $data;
$this->mimeType = $mimeType;
$this->annotations = $annotations;
$this->_meta = $_meta;
}
/**
* Creates an instance from an array.
*
* @param array{
* type: 'audio',
* data: string,
* mimeType: string,
* annotations?: array<string, mixed>|\WP\McpSchema\Common\Protocol\DTO\Annotations|null,
* _meta?: array<string, mixed>|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['data', 'mimeType']);
/** @var \WP\McpSchema\Common\Protocol\DTO\Annotations|null $annotations */
$annotations = isset($data['annotations'])
? (is_array($data['annotations'])
? Annotations::fromArray(self::asArray($data['annotations']))
: $data['annotations'])
: null;
return new self(
self::asString($data['data']),
self::asString($data['mimeType']),
$annotations,
self::asArrayOrNull($data['_meta'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['type'] = $this->type;
$result['data'] = $this->data;
$result['mimeType'] = $this->mimeType;
if ($this->annotations !== null) {
$result['annotations'] = $this->annotations->toArray();
}
if ($this->_meta !== null) {
$result['_meta'] = $this->_meta;
}
return $result;
}
/**
* @return 'audio'
*/
public function getType(): string
{
return $this->type;
}
/**
* @return string
*/
public function getData(): string
{
return $this->data;
}
/**
* @return string
*/
public function getMimeType(): string
{
return $this->mimeType;
}
/**
* @return \WP\McpSchema\Common\Protocol\DTO\Annotations|null
*/
public function getAnnotations(): ?Annotations
{
return $this->annotations;
}
/**
* @return array<string, mixed>|null
*/
public function get_meta(): ?array
{
return $this->_meta;
}
}
@@ -0,0 +1,187 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Content\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Protocol\DTO\Annotations;
use WP\McpSchema\Common\Protocol\Union\ContentBlockInterface;
use WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* An image provided to or from an LLM.
*
* @since 2024-11-05
* @last-updated 2025-11-25 (modified property: annotations)
*
* @mcp-domain Common
* @mcp-subdomain Content
* @mcp-version 2025-11-25
*/
class ImageContent extends AbstractDataTransferObject implements SamplingMessageContentBlockInterface, ContentBlockInterface
{
use ValidatesRequiredFields;
public const TYPE = 'image';
public const DISCRIMINATOR_FIELD = 'type';
public const DISCRIMINATOR_VALUE = 'image';
/**
* @since 2024-11-05
*
* @var 'image'
*/
protected string $type;
/**
* The base64-encoded image data.
*
* @since 2024-11-05
*
* @var string
*/
protected string $data;
/**
* The MIME type of the image. Different providers may support different image types.
*
* @since 2024-11-05
*
* @var string
*/
protected string $mimeType;
/**
* Optional annotations for the client.
*
* @since 2024-11-05
*
* @var \WP\McpSchema\Common\Protocol\DTO\Annotations|null
*/
protected ?Annotations $annotations;
/**
* See [General fields: `_meta`](/specification/2025-11-25/basic/index#meta) for notes on `_meta` usage.
*
* @since 2025-06-18
*
* @var array<string, mixed>|null
*/
protected ?array $_meta;
/**
* @param string $data @since 2024-11-05
* @param string $mimeType @since 2024-11-05
* @param \WP\McpSchema\Common\Protocol\DTO\Annotations|null $annotations @since 2024-11-05
* @param array<string, mixed>|null $_meta @since 2025-06-18
*/
public function __construct(
string $data,
string $mimeType,
?Annotations $annotations = null,
?array $_meta = null
) {
$this->type = self::TYPE;
$this->data = $data;
$this->mimeType = $mimeType;
$this->annotations = $annotations;
$this->_meta = $_meta;
}
/**
* Creates an instance from an array.
*
* @param array{
* type: 'image',
* data: string,
* mimeType: string,
* annotations?: array<string, mixed>|\WP\McpSchema\Common\Protocol\DTO\Annotations|null,
* _meta?: array<string, mixed>|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['data', 'mimeType']);
/** @var \WP\McpSchema\Common\Protocol\DTO\Annotations|null $annotations */
$annotations = isset($data['annotations'])
? (is_array($data['annotations'])
? Annotations::fromArray(self::asArray($data['annotations']))
: $data['annotations'])
: null;
return new self(
self::asString($data['data']),
self::asString($data['mimeType']),
$annotations,
self::asArrayOrNull($data['_meta'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['type'] = $this->type;
$result['data'] = $this->data;
$result['mimeType'] = $this->mimeType;
if ($this->annotations !== null) {
$result['annotations'] = $this->annotations->toArray();
}
if ($this->_meta !== null) {
$result['_meta'] = $this->_meta;
}
return $result;
}
/**
* @return 'image'
*/
public function getType(): string
{
return $this->type;
}
/**
* @return string
*/
public function getData(): string
{
return $this->data;
}
/**
* @return string
*/
public function getMimeType(): string
{
return $this->mimeType;
}
/**
* @return \WP\McpSchema\Common\Protocol\DTO\Annotations|null
*/
public function getAnnotations(): ?Annotations
{
return $this->annotations;
}
/**
* @return array<string, mixed>|null
*/
public function get_meta(): ?array
{
return $this->_meta;
}
}
@@ -0,0 +1,164 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Content\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Protocol\DTO\Annotations;
use WP\McpSchema\Common\Protocol\Union\ContentBlockInterface;
use WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Text provided to or from an LLM.
*
* @since 2024-11-05
* @last-updated 2025-11-25 (modified property: annotations)
*
* @mcp-domain Common
* @mcp-subdomain Content
* @mcp-version 2025-11-25
*/
class TextContent extends AbstractDataTransferObject implements SamplingMessageContentBlockInterface, ContentBlockInterface
{
use ValidatesRequiredFields;
public const TYPE = 'text';
public const DISCRIMINATOR_FIELD = 'type';
public const DISCRIMINATOR_VALUE = 'text';
/**
* @since 2024-11-05
*
* @var 'text'
*/
protected string $type;
/**
* The text content of the message.
*
* @since 2024-11-05
*
* @var string
*/
protected string $text;
/**
* Optional annotations for the client.
*
* @since 2024-11-05
*
* @var \WP\McpSchema\Common\Protocol\DTO\Annotations|null
*/
protected ?Annotations $annotations;
/**
* See [General fields: `_meta`](/specification/2025-11-25/basic/index#meta) for notes on `_meta` usage.
*
* @since 2025-06-18
*
* @var array<string, mixed>|null
*/
protected ?array $_meta;
/**
* @param string $text @since 2024-11-05
* @param \WP\McpSchema\Common\Protocol\DTO\Annotations|null $annotations @since 2024-11-05
* @param array<string, mixed>|null $_meta @since 2025-06-18
*/
public function __construct(
string $text,
?Annotations $annotations = null,
?array $_meta = null
) {
$this->type = self::TYPE;
$this->text = $text;
$this->annotations = $annotations;
$this->_meta = $_meta;
}
/**
* Creates an instance from an array.
*
* @param array{
* type: 'text',
* text: string,
* annotations?: array<string, mixed>|\WP\McpSchema\Common\Protocol\DTO\Annotations|null,
* _meta?: array<string, mixed>|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['text']);
/** @var \WP\McpSchema\Common\Protocol\DTO\Annotations|null $annotations */
$annotations = isset($data['annotations'])
? (is_array($data['annotations'])
? Annotations::fromArray(self::asArray($data['annotations']))
: $data['annotations'])
: null;
return new self(
self::asString($data['text']),
$annotations,
self::asArrayOrNull($data['_meta'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['type'] = $this->type;
$result['text'] = $this->text;
if ($this->annotations !== null) {
$result['annotations'] = $this->annotations->toArray();
}
if ($this->_meta !== null) {
$result['_meta'] = $this->_meta;
}
return $result;
}
/**
* @return 'text'
*/
public function getType(): string
{
return $this->type;
}
/**
* @return string
*/
public function getText(): string
{
return $this->text;
}
/**
* @return \WP\McpSchema\Common\Protocol\DTO\Annotations|null
*/
public function getAnnotations(): ?Annotations
{
return $this->annotations;
}
/**
* @return array<string, mixed>|null
*/
public function get_meta(): ?array
{
return $this->_meta;
}
}
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Contracts;
/**
* Interface for types that extend BaseMetadata.
*
* This interface is auto-generated from TypeScript extends metadata.
* Types implementing this interface: Implementation, Resource, ResourceTemplate, Prompt, PromptArgument, ResourceLink, Tool, PromptReference
*
* @mcp-version 2025-11-25
*/
interface BaseMetadataInterface extends WithArrayTransformationInterface
{
}
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Contracts;
/**
* Interface for types that extend Icons.
*
* This interface is auto-generated from TypeScript extends metadata.
* Types implementing this interface: Implementation, Resource, ResourceTemplate, Prompt, ResourceLink, Tool
*
* @mcp-version 2025-11-25
*/
interface IconsInterface extends WithArrayTransformationInterface
{
}
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Contracts;
/**
* Interface for types that extend JSONRPCNotification.
*
* This interface is auto-generated from TypeScript extends metadata.
* Types implementing this interface: CancelledNotification, InitializedNotification, ProgressNotification, ResourceListChangedNotification, ResourceUpdatedNotification, PromptListChangedNotification, ToolListChangedNotification, TaskStatusNotification, LoggingMessageNotification, RootsListChangedNotification, ElicitationCompleteNotification
*
* @mcp-version 2025-11-25
*/
interface JSONRPCNotificationInterface extends WithArrayTransformationInterface
{
}
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Contracts;
/**
* Interface for types that extend JSONRPCRequest.
*
* This interface is auto-generated from TypeScript extends metadata.
* Types implementing this interface: InitializeRequest, PingRequest, PaginatedRequest, ListResourcesRequest, ListResourceTemplatesRequest, ReadResourceRequest, SubscribeRequest, UnsubscribeRequest, ListPromptsRequest, GetPromptRequest, ListToolsRequest, CallToolRequest, GetTaskRequest, GetTaskPayloadRequest, CancelTaskRequest, ListTasksRequest, SetLevelRequest, CreateMessageRequest, CompleteRequest, ListRootsRequest, ElicitRequest
*
* @mcp-version 2025-11-25
*/
interface JSONRPCRequestInterface extends WithArrayTransformationInterface
{
}
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Contracts;
/**
* Interface for types that extend NotificationParams.
*
* This interface is auto-generated from TypeScript extends metadata.
* Types implementing this interface: CancelledNotificationParams, ProgressNotificationParams, ResourceUpdatedNotificationParams, LoggingMessageNotificationParams
*
* @mcp-version 2025-11-25
*/
interface NotificationParamsInterface extends WithArrayTransformationInterface
{
}
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Contracts;
/**
* Interface for types that extend PaginatedRequest.
*
* This interface is auto-generated from TypeScript extends metadata.
* Types implementing this interface: ListResourcesRequest, ListResourceTemplatesRequest, ListPromptsRequest, ListToolsRequest, ListTasksRequest
*
* @mcp-version 2025-11-25
*/
interface PaginatedRequestInterface extends WithArrayTransformationInterface
{
}
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Contracts;
/**
* Interface for types that extend PaginatedResult.
*
* This interface is auto-generated from TypeScript extends metadata.
* Types implementing this interface: ListResourcesResult, ListResourceTemplatesResult, ListPromptsResult, ListToolsResult, ListTasksResult
*
* @mcp-version 2025-11-25
*/
interface PaginatedResultInterface extends WithArrayTransformationInterface
{
}
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Contracts;
/**
* Interface for types that extend RequestParams.
*
* This interface is auto-generated from TypeScript extends metadata.
* Types implementing this interface: TaskAugmentedRequestParams, InitializeRequestParams, PaginatedRequestParams, ResourceRequestParams, ReadResourceRequestParams, SubscribeRequestParams, UnsubscribeRequestParams, GetPromptRequestParams, CallToolRequestParams, SetLevelRequestParams, CreateMessageRequestParams, CompleteRequestParams, ElicitRequestFormParams, ElicitRequestURLParams
*
* @mcp-version 2025-11-25
*/
interface RequestParamsInterface extends WithArrayTransformationInterface
{
}
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Contracts;
/**
* Interface for types that extend ResourceContents.
*
* This interface is auto-generated from TypeScript extends metadata.
* Types implementing this interface: TextResourceContents, BlobResourceContents
*
* @mcp-version 2025-11-25
*/
interface ResourceContentsInterface extends WithArrayTransformationInterface
{
}
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Contracts;
/**
* Interface for types that extend ResourceRequestParams.
*
* This interface is auto-generated from TypeScript extends metadata.
* Types implementing this interface: ReadResourceRequestParams, SubscribeRequestParams, UnsubscribeRequestParams
*
* @mcp-version 2025-11-25
*/
interface ResourceRequestParamsInterface extends WithArrayTransformationInterface
{
}
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Contracts;
/**
* Interface for types that extend Result.
*
* This interface is auto-generated from TypeScript extends metadata.
* Types implementing this interface: InitializeResult, PaginatedResult, ListResourcesResult, ListResourceTemplatesResult, ReadResourceResult, ListPromptsResult, GetPromptResult, ListToolsResult, CallToolResult, CreateTaskResult, GetTaskPayloadResult, ListTasksResult, CreateMessageResult, CompleteResult, ListRootsResult, ElicitResult
*
* @mcp-version 2025-11-25
*/
interface ResultInterface extends WithArrayTransformationInterface
{
}
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Contracts;
/**
* Interface for types that extend TaskAugmentedRequestParams.
*
* This interface is auto-generated from TypeScript extends metadata.
* Types implementing this interface: CallToolRequestParams, CreateMessageRequestParams, ElicitRequestFormParams, ElicitRequestURLParams
*
* @mcp-version 2025-11-25
*/
interface TaskAugmentedRequestParamsInterface extends WithArrayTransformationInterface
{
}
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Contracts;
/**
* Interface for objects that support array transformation.
*
* @mcp-version 2025-11-25
*/
interface WithArrayTransformationInterface
{
/**
* Converts the object to an array representation.
*
* @return array<string, mixed> The array representation.
*/
public function toArray(): array;
/**
* Creates an instance from array data.
*
* @param array<string, mixed> $data The array data.
* @return static The created instance.
*/
public static function fromArray(array $data);
}
@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Contracts;
/**
* Interface for objects that provide their JSON Schema definition.
*
* @mcp-version 2025-11-25
*/
interface WithJsonSchemaInterface
{
/**
* Returns the JSON Schema definition for this type.
*
* @return array<string, mixed> The JSON Schema definition.
*/
public static function getJsonSchema(): array;
}
@@ -0,0 +1,175 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Core\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* An optionally-sized icon that can be displayed in a user interface.
*
* @since 2025-11-25
*
* @mcp-domain Common
* @mcp-subdomain Core
* @mcp-version 2025-11-25
*/
class Icon extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* A standard URI pointing to an icon resource. May be an HTTP/HTTPS URL or a
* `data:` URI with Base64-encoded image data.
*
* Consumers SHOULD takes steps to ensure URLs serving icons are from the
* same domain as the client/server or a trusted domain.
*
* Consumers SHOULD take appropriate precautions when consuming SVGs as they can contain
* executable JavaScript.
*
* @since 2025-11-25
*
* @var string
*/
protected string $src;
/**
* Optional MIME type override if the source MIME type is missing or generic.
* For example: `"image/png"`, `"image/jpeg"`, or `"image/svg+xml"`.
*
* @since 2025-11-25
*
* @var string|null
*/
protected ?string $mimeType;
/**
* Optional array of strings that specify sizes at which the icon can be used.
* Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
*
* If not provided, the client should assume that the icon can be used at any size.
*
* @since 2025-11-25
*
* @var array<string>|null
*/
protected ?array $sizes;
/**
* Optional specifier for the theme this icon is designed for. `light` indicates
* the icon is designed to be used with a light background, and `dark` indicates
* the icon is designed to be used with a dark background.
*
* If not provided, the client should assume the icon can be used with any theme.
*
* @since 2025-11-25
*
* @var 'light'|'dark'|null
*/
protected ?string $theme;
/**
* @param string $src @since 2025-11-25
* @param string|null $mimeType @since 2025-11-25
* @param array<string>|null $sizes @since 2025-11-25
* @param 'light'|'dark'|null $theme @since 2025-11-25
*/
public function __construct(
string $src,
?string $mimeType = null,
?array $sizes = null,
?string $theme = null
) {
$this->src = $src;
$this->mimeType = $mimeType;
$this->sizes = $sizes;
$this->theme = $theme;
}
/**
* Creates an instance from an array.
*
* @param array{
* src: string,
* mimeType?: string|null,
* sizes?: array<string>|null,
* theme?: 'light'|'dark'|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['src']);
/** @var 'light'|'dark'|null $theme */
$theme = isset($data['theme'])
? self::asStringOrNull($data['theme'])
: null;
return new self(
self::asString($data['src']),
self::asStringOrNull($data['mimeType'] ?? null),
self::asStringArrayOrNull($data['sizes'] ?? null),
$theme
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['src'] = $this->src;
if ($this->mimeType !== null) {
$result['mimeType'] = $this->mimeType;
}
if ($this->sizes !== null) {
$result['sizes'] = $this->sizes;
}
if ($this->theme !== null) {
$result['theme'] = $this->theme;
}
return $result;
}
/**
* @return string
*/
public function getSrc(): string
{
return $this->src;
}
/**
* @return string|null
*/
public function getMimeType(): ?string
{
return $this->mimeType;
}
/**
* @return array<string>|null
*/
public function getSizes(): ?array
{
return $this->sizes;
}
/**
* @return 'light'|'dark'|null
*/
public function getTheme(): ?string
{
return $this->theme;
}
}
@@ -0,0 +1,126 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\JsonRpc\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* @since 2025-11-25
*
* @mcp-domain Common
* @mcp-subdomain JsonRpc
* @mcp-version 2025-11-25
*/
class Error extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* The error type that occurred.
*
* @since 2025-11-25
*
* @var int
*/
protected int $code;
/**
* A short description of the error. The message SHOULD be limited to a concise single sentence.
*
* @since 2025-11-25
*
* @var string
*/
protected string $message;
/**
* Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
*
* @since 2025-11-25
*
* @var mixed|null
*/
protected $data;
/**
* @param int $code @since 2025-11-25
* @param string $message @since 2025-11-25
* @param mixed|null $data @since 2025-11-25
*/
public function __construct(
int $code,
string $message,
$data = null
) {
$this->code = $code;
$this->message = $message;
$this->data = $data;
}
/**
* Creates an instance from an array.
*
* @param array{
* code: int,
* message: string,
* data?: mixed|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['code', 'message']);
return new self(
self::asInt($data['code']),
self::asString($data['message']),
$data['data'] ?? null
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['code'] = $this->code;
$result['message'] = $this->message;
if ($this->data !== null) {
$result['data'] = $this->data;
}
return $result;
}
/**
* @return int
*/
public function getCode(): int
{
return $this->code;
}
/**
* @return string
*/
public function getMessage(): string
{
return $this->message;
}
/**
* @return mixed|null
*/
public function getData()
{
return $this->data;
}
}
@@ -0,0 +1,136 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\JsonRpc\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\JsonRpc\Union\JSONRPCResponseInterface;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* A response to a request that indicates an error occurred.
*
* @since 2025-11-25
*
* @mcp-domain Common
* @mcp-subdomain JsonRpc
* @mcp-version 2025-11-25
*/
class JSONRPCErrorResponse extends AbstractDataTransferObject implements JSONRPCResponseInterface
{
use ValidatesRequiredFields;
/**
* @since 2025-11-25
*
* @var '2.0'
*/
protected string $jsonrpc;
/**
* @since 2025-11-25
*
* @var string|number|null
*/
protected $id;
/**
* @since 2025-11-25
*
* @var \WP\McpSchema\Common\JsonRpc\DTO\Error
*/
protected Error $error;
/**
* @param '2.0' $jsonrpc @since 2025-11-25
* @param \WP\McpSchema\Common\JsonRpc\DTO\Error $error @since 2025-11-25
* @param string|number|null $id @since 2025-11-25
*/
public function __construct(
string $jsonrpc,
Error $error,
$id = null
) {
$this->jsonrpc = $jsonrpc;
$this->error = $error;
$this->id = $id;
}
/**
* Creates an instance from an array.
*
* @param array{
* jsonrpc: '2.0',
* id?: string|number|null,
* error: array<string, mixed>|\WP\McpSchema\Common\JsonRpc\DTO\Error
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['jsonrpc', 'error']);
/** @var '2.0' $jsonrpc */
$jsonrpc = self::asString($data['jsonrpc']);
/** @var \WP\McpSchema\Common\JsonRpc\DTO\Error $error */
$error = is_array($data['error'])
? Error::fromArray(self::asArray($data['error']))
: $data['error'];
/** @var string|number|null $id */
$id = isset($data['id'])
? self::asStringOrNumberOrNull($data['id'])
: null;
return new self(
$jsonrpc,
$error,
$id
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['jsonrpc'] = $this->jsonrpc;
if ($this->id !== null) {
$result['id'] = $this->id;
}
$result['error'] = $this->error->toArray();
return $result;
}
/**
* @return '2.0'
*/
public function getJsonrpc(): string
{
return $this->jsonrpc;
}
/**
* @return string|number|null
*/
public function getId()
{
return $this->id;
}
/**
* @return \WP\McpSchema\Common\JsonRpc\DTO\Error
*/
public function getError(): Error
{
return $this->error;
}
}
@@ -0,0 +1,90 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\JsonRpc\DTO;
use WP\McpSchema\Common\JsonRpc\Union\JSONRPCMessageInterface;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* A notification which does not expect a response.
*
* @since 2024-11-05
*
* @mcp-domain Common
* @mcp-subdomain JsonRpc
* @mcp-version 2025-11-25
*/
class JSONRPCNotification extends Notification implements JSONRPCMessageInterface
{
use ValidatesRequiredFields;
/**
* @since 2024-11-05
*
* @var '2.0'
*/
protected string $jsonrpc;
/**
* @param string $method @since 2024-11-05
* @param '2.0' $jsonrpc @since 2024-11-05
* @param array<string, mixed>|null $params @since 2024-11-05
*/
public function __construct(
string $method,
string $jsonrpc,
?array $params = null
) {
parent::__construct($method, $params);
$this->jsonrpc = $jsonrpc;
}
/**
* Creates an instance from an array.
*
* @param array{
* method: string,
* params?: array<string, mixed>|null,
* jsonrpc: '2.0'
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['method', 'jsonrpc']);
/** @var '2.0' $jsonrpc */
$jsonrpc = self::asString($data['jsonrpc']);
return new self(
self::asString($data['method']),
$jsonrpc,
self::asArrayOrNull($data['params'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
$result['jsonrpc'] = $this->jsonrpc;
return $result;
}
/**
* @return '2.0'
*/
public function getJsonrpc(): string
{
return $this->jsonrpc;
}
}
@@ -0,0 +1,114 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\JsonRpc\DTO;
use WP\McpSchema\Common\JsonRpc\Union\JSONRPCMessageInterface;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* A request that expects a response.
*
* @since 2024-11-05
*
* @mcp-domain Common
* @mcp-subdomain JsonRpc
* @mcp-version 2025-11-25
*/
class JSONRPCRequest extends Request implements JSONRPCMessageInterface
{
use ValidatesRequiredFields;
/**
* @since 2024-11-05
*
* @var '2.0'
*/
protected string $jsonrpc;
/**
* @since 2024-11-05
*
* @var string|number
*/
protected $id;
/**
* @param string $method @since 2024-11-05
* @param '2.0' $jsonrpc @since 2024-11-05
* @param string|number $id @since 2024-11-05
* @param array<string, mixed>|null $params @since 2024-11-05
*/
public function __construct(
string $method,
string $jsonrpc,
$id,
?array $params = null
) {
parent::__construct($method, $params);
$this->jsonrpc = $jsonrpc;
$this->id = $id;
}
/**
* Creates an instance from an array.
*
* @param array{
* method: string,
* params?: array<string, mixed>|null,
* jsonrpc: '2.0',
* id: string|number
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['method', 'jsonrpc', 'id']);
/** @var '2.0' $jsonrpc */
$jsonrpc = self::asString($data['jsonrpc']);
/** @var string|number $id */
$id = self::asStringOrNumber($data['id']);
return new self(
self::asString($data['method']),
$jsonrpc,
$id,
self::asArrayOrNull($data['params'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
$result['jsonrpc'] = $this->jsonrpc;
$result['id'] = $this->id;
return $result;
}
/**
* @return '2.0'
*/
public function getJsonrpc(): string
{
return $this->jsonrpc;
}
/**
* @return string|number
*/
public function getId()
{
return $this->id;
}
}
@@ -0,0 +1,133 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\JsonRpc\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\JsonRpc\Union\JSONRPCResponseInterface;
use WP\McpSchema\Common\Protocol\DTO\Result;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* A successful (non-error) response to a request.
*
* @since 2025-11-25
*
* @mcp-domain Common
* @mcp-subdomain JsonRpc
* @mcp-version 2025-11-25
*/
class JSONRPCResultResponse extends AbstractDataTransferObject implements JSONRPCResponseInterface
{
use ValidatesRequiredFields;
/**
* @since 2025-11-25
*
* @var '2.0'
*/
protected string $jsonrpc;
/**
* @since 2025-11-25
*
* @var string|number
*/
protected $id;
/**
* @since 2025-11-25
*
* @var \WP\McpSchema\Common\Protocol\DTO\Result
*/
protected Result $result;
/**
* @param '2.0' $jsonrpc @since 2025-11-25
* @param string|number $id @since 2025-11-25
* @param \WP\McpSchema\Common\Protocol\DTO\Result $result @since 2025-11-25
*/
public function __construct(
string $jsonrpc,
$id,
Result $result
) {
$this->jsonrpc = $jsonrpc;
$this->id = $id;
$this->result = $result;
}
/**
* Creates an instance from an array.
*
* @param array{
* jsonrpc: '2.0',
* id: string|number,
* result: array<string, mixed>|\WP\McpSchema\Common\Protocol\DTO\Result
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['jsonrpc', 'id', 'result']);
/** @var '2.0' $jsonrpc */
$jsonrpc = self::asString($data['jsonrpc']);
/** @var string|number $id */
$id = self::asStringOrNumber($data['id']);
/** @var \WP\McpSchema\Common\Protocol\DTO\Result $result */
$result = is_array($data['result'])
? Result::fromArray(self::asArray($data['result']))
: $data['result'];
return new self(
$jsonrpc,
$id,
$result
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['jsonrpc'] = $this->jsonrpc;
$result['id'] = $this->id;
$result['result'] = $this->result->toArray();
return $result;
}
/**
* @return '2.0'
*/
public function getJsonrpc(): string
{
return $this->jsonrpc;
}
/**
* @return string|number
*/
public function getId()
{
return $this->id;
}
/**
* @return \WP\McpSchema\Common\Protocol\DTO\Result
*/
public function getResult(): Result
{
return $this->result;
}
}
@@ -0,0 +1,99 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\JsonRpc\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* @since 2024-11-05
*
* @mcp-domain Common
* @mcp-subdomain JsonRpc
* @mcp-version 2025-11-25
*/
class Notification extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* @since 2024-11-05
*
* @var string
*/
protected string $method;
/**
* @since 2024-11-05
*
* @var array<string, mixed>|null
*/
protected ?array $params;
/**
* @param string $method @since 2024-11-05
* @param array<string, mixed>|null $params @since 2024-11-05
*/
public function __construct(
string $method,
?array $params = null
) {
$this->method = $method;
$this->params = $params;
}
/**
* Creates an instance from an array.
*
* @param array{
* method: string,
* params?: array<string, mixed>|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['method']);
return new self(
self::asString($data['method']),
self::asArrayOrNull($data['params'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['method'] = $this->method;
if ($this->params !== null) {
$result['params'] = $this->params;
}
return $result;
}
/**
* @return string
*/
public function getMethod(): string
{
return $this->method;
}
/**
* @return array<string, mixed>|null
*/
public function getParams(): ?array
{
return $this->params;
}
}
@@ -0,0 +1,78 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\JsonRpc\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* @since 2025-11-25
*
* @mcp-domain Common
* @mcp-subdomain JsonRpc
* @mcp-version 2025-11-25
*/
class NotificationParams extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* See [General fields: `_meta`](/specification/2025-11-25/basic/index#meta) for notes on `_meta` usage.
*
* @since 2025-11-25
*
* @var array<string, mixed>|null
*/
protected ?array $_meta;
/**
* @param array<string, mixed>|null $_meta @since 2025-11-25
*/
public function __construct(
?array $_meta = null
) {
$this->_meta = $_meta;
}
/**
* Creates an instance from an array.
*
* @param array{
* _meta?: array<string, mixed>|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
return new self(
self::asArrayOrNull($data['_meta'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
if ($this->_meta !== null) {
$result['_meta'] = $this->_meta;
}
return $result;
}
/**
* @return array<string, mixed>|null
*/
public function get_meta(): ?array
{
return $this->_meta;
}
}
@@ -0,0 +1,99 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\JsonRpc\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* @since 2024-11-05
*
* @mcp-domain Common
* @mcp-subdomain JsonRpc
* @mcp-version 2025-11-25
*/
class Request extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* @since 2024-11-05
*
* @var string
*/
protected string $method;
/**
* @since 2024-11-05
*
* @var array<string, mixed>|null
*/
protected ?array $params;
/**
* @param string $method @since 2024-11-05
* @param array<string, mixed>|null $params @since 2024-11-05
*/
public function __construct(
string $method,
?array $params = null
) {
$this->method = $method;
$this->params = $params;
}
/**
* Creates an instance from an array.
*
* @param array{
* method: string,
* params?: array<string, mixed>|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['method']);
return new self(
self::asString($data['method']),
self::asArrayOrNull($data['params'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['method'] = $this->method;
if ($this->params !== null) {
$result['params'] = $this->params;
}
return $result;
}
/**
* @return string
*/
public function getMethod(): string
{
return $this->method;
}
/**
* @return array<string, mixed>|null
*/
public function getParams(): ?array
{
return $this->params;
}
}
@@ -0,0 +1,87 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\JsonRpc\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Common params for any request.
*
* @since 2025-11-25
*
* @mcp-domain Common
* @mcp-subdomain JsonRpc
* @mcp-version 2025-11-25
*/
class RequestParams extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* See [General fields: `_meta`](/specification/2025-11-25/basic/index#meta) for notes on `_meta` usage.
*
* @since 2025-11-25
*
* @var \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null
*/
protected ?RequestParamsMeta $_meta;
/**
* @param \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null $_meta @since 2025-11-25
*/
public function __construct(
?RequestParamsMeta $_meta = null
) {
$this->_meta = $_meta;
}
/**
* Creates an instance from an array.
*
* @param array{
* _meta?: array<string, mixed>|\WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
/** @var \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null $_meta */
$_meta = isset($data['_meta'])
? (is_array($data['_meta'])
? RequestParamsMeta::fromArray(self::asArray($data['_meta']))
: $data['_meta'])
: null;
return new self(
$_meta
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
if ($this->_meta !== null) {
$result['_meta'] = $this->_meta->toArray();
}
return $result;
}
/**
* @return \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null
*/
public function get_meta(): ?RequestParamsMeta
{
return $this->_meta;
}
}
@@ -0,0 +1,107 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\JsonRpc\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* See [General fields: `_meta`](/specification/2025-11-25/basic/index#meta) for notes on `_meta` usage.
*
* @mcp-domain Common
* @mcp-subdomain JsonRpc
* @mcp-version 2025-11-25
*/
class RequestParamsMeta extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* Wire keys this class models. Anything else is kept in $additionalProperties.
*
* @var array<int, string>
*/
private const KNOWN_KEYS = ['progressToken'];
/**
* If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
*
* @var string|number|null
*/
protected $progressToken;
/**
* Keys carried on the wire that this type does not model. Preserved verbatim so unrecognized fields survive a round trip.
*
* @var array<string, mixed>|null
*/
protected ?array $additionalProperties;
/**
* @param string|number|null $progressToken
* @param array<string, mixed>|null $additionalProperties
*/
public function __construct(
$progressToken = null,
?array $additionalProperties = null
) {
$this->progressToken = $progressToken;
$this->additionalProperties = $additionalProperties;
}
/**
* Creates an instance from an array.
*
* @param array{
* progressToken?: string|number|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
/** @var string|number|null $progressToken */
$progressToken = isset($data['progressToken'])
? self::asStringOrNumberOrNull($data['progressToken'])
: null;
return new self(
$progressToken,
self::additionalFields($data, self::KNOWN_KEYS)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
if ($this->progressToken !== null) {
$result['progressToken'] = $this->progressToken;
}
return $result + ($this->additionalProperties ?? []);
}
/**
* @return string|number|null
*/
public function getProgressToken()
{
return $this->progressToken;
}
/**
* @return array<string, mixed>|null
*/
public function getAdditionalProperties(): ?array
{
return $this->additionalProperties;
}
}
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\JsonRpc\Union;
/**
* Refers to any valid JSON-RPC object that can be decoded off the wire, or encoded to be sent.
*
* Union type members:
* - JSONRPCRequest
* - JSONRPCNotification
* - JSONRPCResponse
*
* @mcp-domain Common
* @mcp-subdomain JsonRpc
* @mcp-version 2025-11-25
*/
interface JSONRPCMessageInterface
{
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array;
}
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\JsonRpc\Union;
use WP\McpSchema\Common\JsonRpc\Union\JSONRPCMessageInterface;
/**
* A response to a request, containing either the result or error.
*
* Union type members:
* - JSONRPCResultResponse
* - JSONRPCErrorResponse
*
* @mcp-domain Common
* @mcp-subdomain JsonRpc
* @mcp-version 2025-11-25
*/
interface JSONRPCResponseInterface extends JSONRPCMessageInterface
{
}
@@ -0,0 +1,186 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Lifecycle\DTO;
use WP\McpSchema\Common\Core\DTO\Icon;
use WP\McpSchema\Common\Protocol\DTO\BaseMetadata;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Describes the MCP implementation.
*
* @since 2024-11-05
* @last-updated 2025-11-25 (added properties: description, icons, websiteUrl)
*
* @mcp-domain Common
* @mcp-subdomain Lifecycle
* @mcp-version 2025-11-25
*/
class Implementation extends BaseMetadata
{
use ValidatesRequiredFields;
/**
* @since 2024-11-05
*
* @var string
*/
protected string $version;
/**
* An optional human-readable description of what this implementation does.
*
* This can be used by clients or servers to provide context about their purpose
* and capabilities. For example, a server might describe the types of resources
* or tools it provides, while a client might describe its intended use case.
*
* @since 2025-11-25
*
* @var string|null
*/
protected ?string $description;
/**
* An optional URL of the website for this implementation.
*
* @since 2025-11-25
*
* @var string|null
*/
protected ?string $websiteUrl;
/**
* Optional set of sized icons that the client can display in a user interface.
*
* Clients that support rendering icons MUST support at least the following MIME types:
* - `image/png` - PNG images (safe, universal compatibility)
* - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
*
* Clients that support rendering icons SHOULD also support:
* - `image/svg+xml` - SVG images (scalable but requires security precautions)
* - `image/webp` - WebP images (modern, efficient format)
*
* @since 2025-11-25
*
* @var array<\WP\McpSchema\Common\Core\DTO\Icon>|null
*/
protected ?array $icons;
/**
* @param string $name @since 2024-11-05
* @param string $version @since 2024-11-05
* @param string|null $title @since 2025-06-18
* @param string|null $description @since 2025-11-25
* @param string|null $websiteUrl @since 2025-11-25
* @param array<\WP\McpSchema\Common\Core\DTO\Icon>|null $icons @since 2025-11-25
*/
public function __construct(
string $name,
string $version,
?string $title = null,
?string $description = null,
?string $websiteUrl = null,
?array $icons = null
) {
parent::__construct($name, $title);
$this->version = $version;
$this->description = $description;
$this->websiteUrl = $websiteUrl;
$this->icons = $icons;
}
/**
* Creates an instance from an array.
*
* @param array{
* name: string,
* title?: string|null,
* version: string,
* description?: string|null,
* websiteUrl?: string|null,
* icons?: array<array<string, mixed>|\WP\McpSchema\Common\Core\DTO\Icon>|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['name', 'version']);
/** @var array<\WP\McpSchema\Common\Core\DTO\Icon>|null $icons */
$icons = isset($data['icons'])
? array_map(
static fn($item) => is_array($item)
? Icon::fromArray($item)
: $item,
self::asArray($data['icons'])
)
: null;
return new self(
self::asString($data['name']),
self::asString($data['version']),
self::asStringOrNull($data['title'] ?? null),
self::asStringOrNull($data['description'] ?? null),
self::asStringOrNull($data['websiteUrl'] ?? null),
$icons
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
$result['version'] = $this->version;
if ($this->description !== null) {
$result['description'] = $this->description;
}
if ($this->websiteUrl !== null) {
$result['websiteUrl'] = $this->websiteUrl;
}
if ($this->icons !== null) {
$result['icons'] = array_map(static fn($item) => $item->toArray(), $this->icons);
}
return $result;
}
/**
* @return string
*/
public function getVersion(): string
{
return $this->version;
}
/**
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* @return string|null
*/
public function getWebsiteUrl(): ?string
{
return $this->websiteUrl;
}
/**
* @return array<\WP\McpSchema\Common\Core\DTO\Icon>|null
*/
public function getIcons(): ?array
{
return $this->icons;
}
}
@@ -0,0 +1,103 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common;
/**
* MCP Protocol Constants.
*
* Contains all exported constants from the MCP TypeScript schema including:
* - Protocol version constants
* - JSON-RPC version
* - Standard JSON-RPC error codes
* - MCP-specific error codes
*
* @since 2025-11-25
*
* @mcp-version 2025-11-25
*/
final class McpConstants
{
// Protocol constants
public const LATEST_PROTOCOL_VERSION = '2025-11-25';
public const JSONRPC_VERSION = '2.0';
// Error codes
public const PARSE_ERROR = -32700;
public const INVALID_REQUEST = -32600;
public const METHOD_NOT_FOUND = -32601;
public const INVALID_PARAMS = -32602;
public const INTERNAL_ERROR = -32603;
public const URL_ELICITATION_REQUIRED = -32042;
/**
* Returns all error codes defined in this class.
*
* @return int[]
*/
public static function getErrorCodes(): array
{
return [
self::PARSE_ERROR,
self::INVALID_REQUEST,
self::METHOD_NOT_FOUND,
self::INVALID_PARAMS,
self::INTERNAL_ERROR,
self::URL_ELICITATION_REQUIRED,
];
}
/**
* Returns error code names mapped to their values.
*
* @return array<string, int>
*/
public static function getErrorCodeNames(): array
{
return [
'PARSE_ERROR' => self::PARSE_ERROR,
'INVALID_REQUEST' => self::INVALID_REQUEST,
'METHOD_NOT_FOUND' => self::METHOD_NOT_FOUND,
'INVALID_PARAMS' => self::INVALID_PARAMS,
'INTERNAL_ERROR' => self::INTERNAL_ERROR,
'URL_ELICITATION_REQUIRED' => self::URL_ELICITATION_REQUIRED,
];
}
/**
* Checks if the given error code is valid.
*
* @param int $code
* @return bool
*/
public static function isValidErrorCode(int $code): bool
{
return in_array($code, self::getErrorCodes(), true);
}
/**
* Gets the constant name for an error code.
*
* @param int $code
* @return string|null The constant name, or null if not found
*/
public static function getErrorCodeName(int $code): ?string
{
$flipped = array_flip(self::getErrorCodeNames());
return $flipped[$code] ?? null;
}
/**
* Checks if an error code is a standard JSON-RPC error.
*
* Standard JSON-RPC errors are in the range -32700 to -32600.
*
* @param int $code
* @return bool
*/
public static function isStandardJsonRpcError(int $code): bool
{
return $code >= -32700 && $code <= -32600;
}
}
@@ -0,0 +1,147 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Protocol\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Optional annotations for the client. The client can use annotations to inform how objects are used or displayed
*
* @since 2025-03-26
* @last-updated 2025-11-25 (modified property: audience)
*
* @mcp-domain Common
* @mcp-subdomain Protocol
* @mcp-version 2025-11-25
*/
class Annotations extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* Describes who the intended audience of this object or data is.
*
* It can include multiple entries to indicate content useful for multiple audiences (e.g., `["user", "assistant"]`).
*
* @since 2025-03-26
*
* @var array<'user'|'assistant'>|null
*/
protected ?array $audience;
/**
* Describes how important this data is for operating the server.
*
* A value of 1 means "most important," and indicates that the data is
* effectively required, while 0 means "least important," and indicates that
* the data is entirely optional.
*
* @since 2025-03-26
*
* @var float|null
*/
protected ?float $priority;
/**
* The moment the resource was last modified, as an ISO 8601 formatted string.
*
* Should be an ISO 8601 formatted string (e.g., "2025-01-12T15:00:58Z").
*
* Examples: last activity timestamp in an open file, timestamp when the resource
* was attached, etc.
*
* @since 2025-06-18
*
* @var string|null
*/
protected ?string $lastModified;
/**
* @param array<'user'|'assistant'>|null $audience @since 2025-03-26
* @param float|null $priority @since 2025-03-26
* @param string|null $lastModified @since 2025-06-18
*/
public function __construct(
?array $audience = null,
?float $priority = null,
?string $lastModified = null
) {
$this->audience = $audience;
$this->priority = $priority;
$this->lastModified = $lastModified;
}
/**
* Creates an instance from an array.
*
* @param array{
* audience?: array<'user'|'assistant'>|null,
* priority?: float|null,
* lastModified?: string|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
/** @var array<'user'|'assistant'>|null $audience */
$audience = isset($data['audience'])
? self::asStringArrayOrNull($data['audience'])
: null;
return new self(
$audience,
self::asFloatOrNull($data['priority'] ?? null),
self::asStringOrNull($data['lastModified'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
if ($this->audience !== null) {
$result['audience'] = $this->audience;
}
if ($this->priority !== null) {
$result['priority'] = $this->priority;
}
if ($this->lastModified !== null) {
$result['lastModified'] = $this->lastModified;
}
return $result;
}
/**
* @return array<'user'|'assistant'>|null
*/
public function getAudience(): ?array
{
return $this->audience;
}
/**
* @return float|null
*/
public function getPriority(): ?float
{
return $this->priority;
}
/**
* @return string|null
*/
public function getLastModified(): ?string
{
return $this->lastModified;
}
}
@@ -0,0 +1,110 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Protocol\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Base interface for metadata with name (identifier) and title (display name) properties.
*
* @since 2025-06-18
*
* @mcp-domain Common
* @mcp-subdomain Protocol
* @mcp-version 2025-11-25
*/
class BaseMetadata extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* Intended for programmatic or logical use, but used as a display name in past specs or fallback (if title isn't present).
*
* @since 2025-06-18
*
* @var string
*/
protected string $name;
/**
* Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
* even by those unfamiliar with domain-specific terminology.
*
* If not provided, the name should be used for display (except for Tool,
* where `annotations.title` should be given precedence over using `name`,
* if present).
*
* @since 2025-06-18
*
* @var string|null
*/
protected ?string $title;
/**
* @param string $name @since 2025-06-18
* @param string|null $title @since 2025-06-18
*/
public function __construct(
string $name,
?string $title = null
) {
$this->name = $name;
$this->title = $title;
}
/**
* Creates an instance from an array.
*
* @param array{
* name: string,
* title?: string|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['name']);
return new self(
self::asString($data['name']),
self::asStringOrNull($data['title'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['name'] = $this->name;
if ($this->title !== null) {
$result['title'] = $this->title;
}
return $result;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @return string|null
*/
public function getTitle(): ?string
{
return $this->title;
}
}
@@ -0,0 +1,92 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Protocol\DTO;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
use WP\McpSchema\Server\Resources\DTO\ResourceContents;
/**
* @since 2024-11-05
* @last-updated 2025-06-18 (added properties: _meta)
*
* @mcp-domain Common
* @mcp-subdomain Protocol
* @mcp-version 2025-11-25
*/
class BlobResourceContents extends ResourceContents
{
use ValidatesRequiredFields;
/**
* A base64-encoded string representing the binary data of the item.
*
* @since 2024-11-05
*
* @var string
*/
protected string $blob;
/**
* @param string $uri @since 2024-11-05
* @param string $blob @since 2024-11-05
* @param string|null $mimeType @since 2024-11-05
* @param array<string, mixed>|null $_meta @since 2025-06-18
*/
public function __construct(
string $uri,
string $blob,
?string $mimeType = null,
?array $_meta = null
) {
parent::__construct($uri, $mimeType, $_meta);
$this->blob = $blob;
}
/**
* Creates an instance from an array.
*
* @param array{
* uri: string,
* mimeType?: string|null,
* _meta?: array<string, mixed>|null,
* blob: string
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['uri', 'blob']);
return new self(
self::asString($data['uri']),
self::asString($data['blob']),
self::asStringOrNull($data['mimeType'] ?? null),
self::asArrayOrNull($data['_meta'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
$result['blob'] = $this->blob;
return $result;
}
/**
* @return string
*/
public function getBlob(): string
{
return $this->blob;
}
}
@@ -0,0 +1,106 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Protocol\DTO;
use WP\McpSchema\Common\JsonRpc\DTO\JSONRPCNotification;
use WP\McpSchema\Common\Protocol\Union\ClientNotificationInterface;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
use WP\McpSchema\Server\Lifecycle\Union\ServerNotificationInterface;
/**
* This notification can be sent by either side to indicate that it is cancelling a previously-issued request.
*
* The request SHOULD still be in-flight, but due to communication latency, it is always possible that this notification MAY arrive after the request has already finished.
*
* This notification indicates that the result will be unused, so any associated processing SHOULD cease.
*
* A client MUST NOT attempt to cancel its `initialize` request.
*
* For task cancellation, use the `tasks/cancel` request instead of this notification.
*
* @since 2024-11-05
* @last-updated 2025-11-25 (modified property: params)
*
* @mcp-domain Common
* @mcp-subdomain Protocol
* @mcp-version 2025-11-25
*/
class CancelledNotification extends JSONRPCNotification implements ClientNotificationInterface, ServerNotificationInterface
{
use ValidatesRequiredFields;
public const METHOD = 'notifications/cancelled';
public const DISCRIMINATOR_FIELD = 'method';
public const DISCRIMINATOR_VALUE = 'notifications/cancelled';
/**
* @var \WP\McpSchema\Common\Protocol\DTO\CancelledNotificationParams
*/
protected CancelledNotificationParams $typedParams;
/**
* @param '2.0' $jsonrpc @since 2025-11-25
* @param \WP\McpSchema\Common\Protocol\DTO\CancelledNotificationParams $params @since 2024-11-05
*/
public function __construct(
string $jsonrpc,
CancelledNotificationParams $params
) {
parent::__construct(self::METHOD, $jsonrpc, null);
$this->typedParams = $params;
}
/**
* Creates an instance from an array.
*
* @param array{
* jsonrpc: '2.0',
* method: 'notifications/cancelled',
* params: array<string, mixed>|\WP\McpSchema\Common\Protocol\DTO\CancelledNotificationParams
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['jsonrpc', 'params']);
/** @var '2.0' $jsonrpc */
$jsonrpc = self::asString($data['jsonrpc']);
/** @var \WP\McpSchema\Common\Protocol\DTO\CancelledNotificationParams $params */
$params = is_array($data['params'])
? CancelledNotificationParams::fromArray(self::asArray($data['params']))
: $data['params'];
return new self(
$jsonrpc,
$params
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
$result['params'] = $this->typedParams->toArray();
return $result;
}
/**
* @return \WP\McpSchema\Common\Protocol\DTO\CancelledNotificationParams
*/
public function getTypedParams(): CancelledNotificationParams
{
return $this->typedParams;
}
}
@@ -0,0 +1,119 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Protocol\DTO;
use WP\McpSchema\Common\JsonRpc\DTO\NotificationParams;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Parameters for a `notifications/cancelled` notification.
*
* @since 2025-11-25
*
* @mcp-domain Common
* @mcp-subdomain Protocol
* @mcp-version 2025-11-25
*/
class CancelledNotificationParams extends NotificationParams
{
use ValidatesRequiredFields;
/**
* The ID of the request to cancel.
*
* This MUST correspond to the ID of a request previously issued in the same direction.
* This MUST be provided for cancelling non-task requests.
* This MUST NOT be used for cancelling tasks (use the `tasks/cancel` request instead).
*
* @since 2025-11-25
*
* @var string|number|null
*/
protected $requestId;
/**
* An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
*
* @since 2025-11-25
*
* @var string|null
*/
protected ?string $reason;
/**
* @param array<string, mixed>|null $_meta @since 2025-11-25
* @param string|number|null $requestId @since 2025-11-25
* @param string|null $reason @since 2025-11-25
*/
public function __construct(
?array $_meta = null,
$requestId = null,
?string $reason = null
) {
parent::__construct($_meta);
$this->requestId = $requestId;
$this->reason = $reason;
}
/**
* Creates an instance from an array.
*
* @param array{
* _meta?: array<string, mixed>|null,
* requestId?: string|number|null,
* reason?: string|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
/** @var string|number|null $requestId */
$requestId = isset($data['requestId'])
? self::asStringOrNumberOrNull($data['requestId'])
: null;
return new self(
self::asArrayOrNull($data['_meta'] ?? null),
$requestId,
self::asStringOrNull($data['reason'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
if ($this->requestId !== null) {
$result['requestId'] = $this->requestId;
}
if ($this->reason !== null) {
$result['reason'] = $this->reason;
}
return $result;
}
/**
* @return string|number|null
*/
public function getRequestId()
{
return $this->requestId;
}
/**
* @return string|null
*/
public function getReason(): ?string
{
return $this->reason;
}
}
@@ -0,0 +1,166 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Protocol\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Protocol\Union\ContentBlockInterface;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* The contents of a resource, embedded into a prompt or tool call result.
*
* It is up to the client how best to render embedded resources for the benefit
* of the LLM and/or the user.
*
* @since 2024-11-05
* @last-updated 2025-11-25 (modified property: annotations)
*
* @mcp-domain Common
* @mcp-subdomain Protocol
* @mcp-version 2025-11-25
*/
class EmbeddedResource extends AbstractDataTransferObject implements ContentBlockInterface
{
use ValidatesRequiredFields;
public const TYPE = 'resource';
public const DISCRIMINATOR_FIELD = 'type';
public const DISCRIMINATOR_VALUE = 'resource';
/**
* @since 2024-11-05
*
* @var 'resource'
*/
protected string $type;
/**
* @since 2024-11-05
*
* @var \WP\McpSchema\Common\Protocol\DTO\TextResourceContents|\WP\McpSchema\Common\Protocol\DTO\BlobResourceContents
*/
protected $resource;
/**
* Optional annotations for the client.
*
* @since 2024-11-05
*
* @var \WP\McpSchema\Common\Protocol\DTO\Annotations|null
*/
protected ?Annotations $annotations;
/**
* See [General fields: `_meta`](/specification/2025-11-25/basic/index#meta) for notes on `_meta` usage.
*
* @since 2025-06-18
*
* @var array<string, mixed>|null
*/
protected ?array $_meta;
/**
* @param \WP\McpSchema\Common\Protocol\DTO\TextResourceContents|\WP\McpSchema\Common\Protocol\DTO\BlobResourceContents $resource @since 2024-11-05
* @param \WP\McpSchema\Common\Protocol\DTO\Annotations|null $annotations @since 2024-11-05
* @param array<string, mixed>|null $_meta @since 2025-06-18
*/
public function __construct(
$resource,
?Annotations $annotations = null,
?array $_meta = null
) {
$this->type = self::TYPE;
$this->resource = $resource;
$this->annotations = $annotations;
$this->_meta = $_meta;
}
/**
* Creates an instance from an array.
*
* @param array{
* type: 'resource',
* resource: \WP\McpSchema\Common\Protocol\DTO\TextResourceContents|\WP\McpSchema\Common\Protocol\DTO\BlobResourceContents,
* annotations?: array<string, mixed>|\WP\McpSchema\Common\Protocol\DTO\Annotations|null,
* _meta?: array<string, mixed>|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['resource']);
/** @var \WP\McpSchema\Common\Protocol\DTO\TextResourceContents|\WP\McpSchema\Common\Protocol\DTO\BlobResourceContents $resource */
$resource = $data['resource'];
/** @var \WP\McpSchema\Common\Protocol\DTO\Annotations|null $annotations */
$annotations = isset($data['annotations'])
? (is_array($data['annotations'])
? Annotations::fromArray(self::asArray($data['annotations']))
: $data['annotations'])
: null;
return new self(
$resource,
$annotations,
self::asArrayOrNull($data['_meta'] ?? null)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['type'] = $this->type;
$result['resource'] = (is_object($this->resource) && method_exists($this->resource, 'toArray')) ? $this->resource->toArray() : $this->resource;
if ($this->annotations !== null) {
$result['annotations'] = $this->annotations->toArray();
}
if ($this->_meta !== null) {
$result['_meta'] = $this->_meta;
}
return $result;
}
/**
* @return 'resource'
*/
public function getType(): string
{
return $this->type;
}
/**
* @return \WP\McpSchema\Common\Protocol\DTO\TextResourceContents|\WP\McpSchema\Common\Protocol\DTO\BlobResourceContents
*/
public function getResource()
{
return $this->resource;
}
/**
* @return \WP\McpSchema\Common\Protocol\DTO\Annotations|null
*/
public function getAnnotations(): ?Annotations
{
return $this->annotations;
}
/**
* @return array<string, mixed>|null
*/
public function get_meta(): ?array
{
return $this->_meta;
}
}
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Protocol\DTO;
use WP\McpSchema\Client\Lifecycle\Union\ClientResultInterface;
use WP\McpSchema\Server\Lifecycle\Union\ServerResultInterface;
/**
* A response that indicates success but carries no data.
*
* This class is a wrapper for {@see Result} that implements union interfaces.
* In TypeScript, this is defined as: `type EmptyResult = Result`
*
* PHP requires actual classes for union interface implementation, so this wrapper
* provides type-safe compatibility with:
* - {@see ClientResultInterface}
* - {@see ServerResultInterface}
*
* @mcp-domain Common
* @mcp-subdomain Protocol
* @mcp-version 2025-11-25
*/
class EmptyResult extends Result implements ClientResultInterface, ServerResultInterface
{
// Inherits all functionality from Result.
// This wrapper exists solely to implement union interfaces for type safety.
}
@@ -0,0 +1,104 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Protocol\DTO;
use WP\McpSchema\Common\JsonRpc\DTO\JSONRPCRequest;
use WP\McpSchema\Common\Protocol\Union\ClientRequestInterface;
use WP\McpSchema\Common\Protocol\Union\ServerRequestInterface;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* A request to retrieve the result of a completed task.
*
* @since 2025-11-25
*
* @mcp-domain Common
* @mcp-subdomain Protocol
* @mcp-version 2025-11-25
*/
class GetTaskPayloadRequest extends JSONRPCRequest implements ClientRequestInterface, ServerRequestInterface
{
use ValidatesRequiredFields;
public const METHOD = 'tasks/result';
public const DISCRIMINATOR_FIELD = 'method';
public const DISCRIMINATOR_VALUE = 'tasks/result';
/**
* @var \WP\McpSchema\Common\Protocol\DTO\GetTaskPayloadRequestParams
*/
protected GetTaskPayloadRequestParams $typedParams;
/**
* @param '2.0' $jsonrpc @since 2025-11-25
* @param string|number $id @since 2025-11-25
* @param \WP\McpSchema\Common\Protocol\DTO\GetTaskPayloadRequestParams $params @since 2025-11-25
*/
public function __construct(
string $jsonrpc,
$id,
GetTaskPayloadRequestParams $params
) {
parent::__construct(self::METHOD, $jsonrpc, $id, null);
$this->typedParams = $params;
}
/**
* Creates an instance from an array.
*
* @param array{
* jsonrpc: '2.0',
* id: string|number,
* method: 'tasks/result',
* params: array<string, mixed>|\WP\McpSchema\Common\Protocol\DTO\GetTaskPayloadRequestParams
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['jsonrpc', 'id', 'params']);
/** @var '2.0' $jsonrpc */
$jsonrpc = self::asString($data['jsonrpc']);
/** @var string|number $id */
$id = self::asStringOrNumber($data['id']);
/** @var \WP\McpSchema\Common\Protocol\DTO\GetTaskPayloadRequestParams $params */
$params = is_array($data['params'])
? GetTaskPayloadRequestParams::fromArray(self::asArray($data['params']))
: $data['params'];
return new self(
$jsonrpc,
$id,
$params
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
$result['params'] = $this->typedParams->toArray();
return $result;
}
/**
* @return \WP\McpSchema\Common\Protocol\DTO\GetTaskPayloadRequestParams
*/
public function getTypedParams(): GetTaskPayloadRequestParams
{
return $this->typedParams;
}
}
@@ -0,0 +1,74 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Protocol\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* @mcp-domain Common
* @mcp-subdomain Protocol
* @mcp-version 2025-11-25
*/
class GetTaskPayloadRequestParams extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* The task identifier to retrieve results for.
*
* @var string
*/
protected string $taskId;
/**
* @param string $taskId
*/
public function __construct(
string $taskId
) {
$this->taskId = $taskId;
}
/**
* Creates an instance from an array.
*
* @param array{
* taskId: string
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['taskId']);
return new self(
self::asString($data['taskId'])
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
$result['taskId'] = $this->taskId;
return $result;
}
/**
* @return string
*/
public function getTaskId(): string
{
return $this->taskId;
}
}
@@ -0,0 +1,76 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Protocol\DTO;
use WP\McpSchema\Client\Lifecycle\Union\ClientResultInterface;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
use WP\McpSchema\Server\Lifecycle\Union\ServerResultInterface;
/**
* The response to a tasks/result request.
* The structure matches the result type of the original request.
* For example, a tools/call task would return the CallToolResult structure.
*
* Note: This class is structurally identical to Result.
* It exists as a separate type for semantic distinction per MCP specification.
*
* @since 2025-11-25
*
* @mcp-domain Common
* @mcp-subdomain Protocol
* @mcp-version 2025-11-25
* @see Result
*/
class GetTaskPayloadResult extends Result implements ClientResultInterface, ServerResultInterface
{
use ValidatesRequiredFields;
/**
* Wire keys this class models. Anything else is kept in $additionalProperties.
*
* @var array<int, string>
*/
private const KNOWN_KEYS = ['_meta'];
/**
* @param array<string, mixed>|null $_meta @since 2025-11-25
* @param array<string, mixed>|null $additionalProperties
*/
public function __construct(
?array $_meta = null,
?array $additionalProperties = null
) {
parent::__construct($_meta, $additionalProperties);
}
/**
* Creates an instance from an array.
*
* @param array{
* _meta?: array<string, mixed>|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
return new self(
self::asArrayOrNull($data['_meta'] ?? null),
self::additionalFields($data, self::KNOWN_KEYS)
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
return $result;
}
}
@@ -0,0 +1,99 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Protocol\DTO;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Core\DTO\Icon;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Base interface to add `icons` property.
*
* @since 2025-11-25
*
* @mcp-domain Common
* @mcp-subdomain Protocol
* @mcp-version 2025-11-25
*/
class Icons extends AbstractDataTransferObject
{
use ValidatesRequiredFields;
/**
* Optional set of sized icons that the client can display in a user interface.
*
* Clients that support rendering icons MUST support at least the following MIME types:
* - `image/png` - PNG images (safe, universal compatibility)
* - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
*
* Clients that support rendering icons SHOULD also support:
* - `image/svg+xml` - SVG images (scalable but requires security precautions)
* - `image/webp` - WebP images (modern, efficient format)
*
* @since 2025-11-25
*
* @var array<\WP\McpSchema\Common\Core\DTO\Icon>|null
*/
protected ?array $icons;
/**
* @param array<\WP\McpSchema\Common\Core\DTO\Icon>|null $icons @since 2025-11-25
*/
public function __construct(
?array $icons = null
) {
$this->icons = $icons;
}
/**
* Creates an instance from an array.
*
* @param array{
* icons?: array<array<string, mixed>|\WP\McpSchema\Common\Core\DTO\Icon>|null
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
/** @var array<\WP\McpSchema\Common\Core\DTO\Icon>|null $icons */
$icons = isset($data['icons'])
? array_map(
static fn($item) => is_array($item)
? Icon::fromArray($item)
: $item,
self::asArray($data['icons'])
)
: null;
return new self(
$icons
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [];
if ($this->icons !== null) {
$result['icons'] = array_map(static fn($item) => $item->toArray(), $this->icons);
}
return $result;
}
/**
* @return array<\WP\McpSchema\Common\Core\DTO\Icon>|null
*/
public function getIcons(): ?array
{
return $this->icons;
}
}
@@ -0,0 +1,104 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Protocol\DTO;
use WP\McpSchema\Common\JsonRpc\DTO\JSONRPCRequest;
use WP\McpSchema\Common\Protocol\Union\ClientRequestInterface;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* This request is sent from the client to the server when it first connects, asking it to begin initialization.
*
* @since 2024-11-05
* @last-updated 2025-11-25 (modified property: params)
*
* @mcp-domain Common
* @mcp-subdomain Protocol
* @mcp-version 2025-11-25
*/
class InitializeRequest extends JSONRPCRequest implements ClientRequestInterface
{
use ValidatesRequiredFields;
public const METHOD = 'initialize';
public const DISCRIMINATOR_FIELD = 'method';
public const DISCRIMINATOR_VALUE = 'initialize';
/**
* @var \WP\McpSchema\Common\Protocol\DTO\InitializeRequestParams
*/
protected InitializeRequestParams $typedParams;
/**
* @param '2.0' $jsonrpc @since 2025-11-25
* @param string|number $id @since 2025-11-25
* @param \WP\McpSchema\Common\Protocol\DTO\InitializeRequestParams $params @since 2024-11-05
*/
public function __construct(
string $jsonrpc,
$id,
InitializeRequestParams $params
) {
parent::__construct(self::METHOD, $jsonrpc, $id, null);
$this->typedParams = $params;
}
/**
* Creates an instance from an array.
*
* @param array{
* jsonrpc: '2.0',
* id: string|number,
* method: 'initialize',
* params: array<string, mixed>|\WP\McpSchema\Common\Protocol\DTO\InitializeRequestParams
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['jsonrpc', 'id', 'params']);
/** @var '2.0' $jsonrpc */
$jsonrpc = self::asString($data['jsonrpc']);
/** @var string|number $id */
$id = self::asStringOrNumber($data['id']);
/** @var \WP\McpSchema\Common\Protocol\DTO\InitializeRequestParams $params */
$params = is_array($data['params'])
? InitializeRequestParams::fromArray(self::asArray($data['params']))
: $data['params'];
return new self(
$jsonrpc,
$id,
$params
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
$result['params'] = $this->typedParams->toArray();
return $result;
}
/**
* @return \WP\McpSchema\Common\Protocol\DTO\InitializeRequestParams
*/
public function getTypedParams(): InitializeRequestParams
{
return $this->typedParams;
}
}
@@ -0,0 +1,147 @@
<?php
declare(strict_types=1);
namespace WP\McpSchema\Common\Protocol\DTO;
use WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilities;
use WP\McpSchema\Common\JsonRpc\DTO\RequestParams;
use WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta;
use WP\McpSchema\Common\Lifecycle\DTO\Implementation;
use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
/**
* Parameters for an `initialize` request.
*
* @since 2025-11-25
*
* @mcp-domain Common
* @mcp-subdomain Protocol
* @mcp-version 2025-11-25
*/
class InitializeRequestParams extends RequestParams
{
use ValidatesRequiredFields;
/**
* The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
*
* @since 2025-11-25
*
* @var string
*/
protected string $protocolVersion;
/**
* @since 2025-11-25
*
* @var \WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilities
*/
protected ClientCapabilities $capabilities;
/**
* @since 2025-11-25
*
* @var \WP\McpSchema\Common\Lifecycle\DTO\Implementation
*/
protected Implementation $clientInfo;
/**
* @param string $protocolVersion @since 2025-11-25
* @param \WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilities $capabilities @since 2025-11-25
* @param \WP\McpSchema\Common\Lifecycle\DTO\Implementation $clientInfo @since 2025-11-25
* @param \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null $_meta @since 2025-11-25
*/
public function __construct(
string $protocolVersion,
ClientCapabilities $capabilities,
Implementation $clientInfo,
?RequestParamsMeta $_meta = null
) {
parent::__construct($_meta);
$this->protocolVersion = $protocolVersion;
$this->capabilities = $capabilities;
$this->clientInfo = $clientInfo;
}
/**
* Creates an instance from an array.
*
* @param array{
* _meta?: array<string, mixed>|\WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null,
* protocolVersion: string,
* capabilities: array<string, mixed>|\WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilities,
* clientInfo: array<string, mixed>|\WP\McpSchema\Common\Lifecycle\DTO\Implementation
* } $data
* @phpstan-param array<string, mixed> $data
* @return self
*/
public static function fromArray(array $data): self
{
self::assertRequired($data, ['protocolVersion', 'capabilities', 'clientInfo']);
/** @var \WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilities $capabilities */
$capabilities = is_array($data['capabilities'])
? ClientCapabilities::fromArray(self::asArray($data['capabilities']))
: $data['capabilities'];
/** @var \WP\McpSchema\Common\Lifecycle\DTO\Implementation $clientInfo */
$clientInfo = is_array($data['clientInfo'])
? Implementation::fromArray(self::asArray($data['clientInfo']))
: $data['clientInfo'];
/** @var \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null $_meta */
$_meta = isset($data['_meta'])
? (is_array($data['_meta'])
? RequestParamsMeta::fromArray(self::asArray($data['_meta']))
: $data['_meta'])
: null;
return new self(
self::asString($data['protocolVersion']),
$capabilities,
$clientInfo,
$_meta
);
}
/**
* Converts the instance to an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = parent::toArray();
$result['protocolVersion'] = $this->protocolVersion;
$result['capabilities'] = $this->capabilities->toArray();
$result['clientInfo'] = $this->clientInfo->toArray();
return $result;
}
/**
* @return string
*/
public function getProtocolVersion(): string
{
return $this->protocolVersion;
}
/**
* @return \WP\McpSchema\Client\Lifecycle\DTO\ClientCapabilities
*/
public function getCapabilities(): ClientCapabilities
{
return $this->capabilities;
}
/**
* @return \WP\McpSchema\Common\Lifecycle\DTO\Implementation
*/
public function getClientInfo(): Implementation
{
return $this->clientInfo;
}
}

Some files were not shown because too many files have changed in this diff Show More