Adopt Schema component in server handlers

This commit is contained in:
Christopher Hertel 2025-08-03 22:06:46 +02:00
commit 09707b4798
No known key found for this signature in database
GPG key ID: 111F6BFF7B6B5AA3
12 changed files with 1516 additions and 2424 deletions

View file

@ -1,28 +0,0 @@
<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mcp\Capability\Prompt;
/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
final class PromptGet
{
/**
* @param array<string, mixed> $arguments
*/
public function __construct(
public readonly string $id,
public readonly string $name,
public readonly array $arguments = [],
) {
}
}

View file

@ -1,27 +0,0 @@
<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mcp\Capability\Prompt;
/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
final class PromptGetResult
{
/**
* @param list<PromptGetResultMessages> $messages
*/
public function __construct(
public readonly string $description,
public readonly array $messages = [],
) {
}
}

View file

@ -1,30 +0,0 @@
<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mcp\Capability\Prompt;
/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
final class PromptGetResultMessages
{
public function __construct(
public readonly string $role,
public readonly string $result,
/**
* @var "text"|"image"|"audio"|"resource"|non-empty-string
*/
public readonly string $type = 'text',
public readonly string $mimeType = 'text/plan',
public readonly ?string $uri = null,
) {
}
}

View file

@ -13,6 +13,8 @@ namespace Mcp\Capability\Prompt;
use Mcp\Exception\PromptGetException;
use Mcp\Exception\PromptNotFoundException;
use Mcp\Schema\Request\GetPromptRequest;
use Mcp\Schema\Result\GetPromptResult;
/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
@ -23,5 +25,5 @@ interface PromptGetterInterface
* @throws PromptGetException if the prompt execution fails
* @throws PromptNotFoundException if the prompt is not found
*/
public function get(PromptGet $input): PromptGetResult;
public function get(GetPromptRequest $request): GetPromptResult;
}

View file

@ -14,12 +14,12 @@ namespace Mcp\Capability;
use Mcp\Capability\Prompt\CollectionInterface;
use Mcp\Capability\Prompt\IdentifierInterface;
use Mcp\Capability\Prompt\MetadataInterface;
use Mcp\Capability\Prompt\PromptGet;
use Mcp\Capability\Prompt\PromptGetResult;
use Mcp\Capability\Prompt\PromptGetterInterface;
use Mcp\Exception\InvalidCursorException;
use Mcp\Exception\PromptGetException;
use Mcp\Exception\PromptNotFoundException;
use Mcp\Schema\Request\GetPromptRequest;
use Mcp\Schema\Result\GetPromptResult;
/**
* A collection of prompts. All prompts need to implement IdentifierInterface.
@ -60,18 +60,18 @@ class PromptChain implements PromptGetterInterface, CollectionInterface
}
}
public function get(PromptGet $input): PromptGetResult
public function get(GetPromptRequest $request): GetPromptResult
{
foreach ($this->items as $item) {
if ($item instanceof PromptGetterInterface && $input->name === $item->getName()) {
if ($item instanceof PromptGetterInterface && $request->name === $item->getName()) {
try {
return $item->get($input);
return $item->get($request);
} catch (\Throwable $e) {
throw new PromptGetException($input, $e);
throw new PromptGetException($request, $e);
}
}
}
throw new PromptNotFoundException($input);
throw new PromptNotFoundException($request);
}
}

View file

@ -1,24 +0,0 @@
<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mcp\Capability\Resource;
/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
final class ResourceRead
{
public function __construct(
public readonly string $id,
public readonly string $uri,
) {
}
}

View file

@ -13,6 +13,8 @@ namespace Mcp\Capability\Resource;
use Mcp\Exception\ResourceNotFoundException;
use Mcp\Exception\ResourceReadException;
use Mcp\Schema\Request\ReadResourceRequest;
use Mcp\Schema\Result\ReadResourceResult;
/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
@ -23,5 +25,5 @@ interface ResourceReaderInterface
* @throws ResourceReadException if the resource execution fails
* @throws ResourceNotFoundException if the resource is not found
*/
public function read(ResourceRead $input): ResourceReadResult;
public function read(ReadResourceRequest $request): ReadResourceResult;
}

View file

@ -14,12 +14,12 @@ namespace Mcp\Capability;
use Mcp\Capability\Resource\CollectionInterface;
use Mcp\Capability\Resource\IdentifierInterface;
use Mcp\Capability\Resource\MetadataInterface;
use Mcp\Capability\Resource\ResourceRead;
use Mcp\Capability\Resource\ResourceReaderInterface;
use Mcp\Capability\Resource\ResourceReadResult;
use Mcp\Exception\InvalidCursorException;
use Mcp\Exception\ResourceNotFoundException;
use Mcp\Exception\ResourceReadException;
use Mcp\Schema\Request\ReadResourceRequest;
use Mcp\Schema\Result\ReadResourceResult;
/**
* A collection of resources. All resources need to implement IdentifierInterface.
@ -60,18 +60,18 @@ class ResourceChain implements CollectionInterface, ResourceReaderInterface
}
}
public function read(ResourceRead $input): ResourceReadResult
public function read(ReadResourceRequest $request): ReadResourceResult
{
foreach ($this->items as $item) {
if ($item instanceof ResourceReaderInterface && $input->uri === $item->getUri()) {
if ($item instanceof ResourceReaderInterface && $request->uri === $item->getUri()) {
try {
return $item->read($input);
return $item->read($request);
} catch (\Throwable $e) {
throw new ResourceReadException($input, $e);
throw new ResourceReadException($request, $e);
}
}
}
throw new ResourceNotFoundException($input);
throw new ResourceNotFoundException($request);
}
}

View file

@ -1,28 +0,0 @@
<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mcp\Capability\Tool;
/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
final class ToolCall
{
/**
* @param array<string, mixed> $arguments
*/
public function __construct(
public readonly string $id,
public readonly string $name,
public readonly array $arguments = [],
) {
}
}

View file

@ -1,30 +0,0 @@
<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mcp\Capability\Tool;
/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
final class ToolCallResult
{
public function __construct(
public readonly string $result,
/**
* @var "text"|"image"|"audio"|"resource"|non-empty-string
*/
public readonly string $type = 'text',
public readonly string $mimeType = 'text/plan',
public readonly bool $isError = false,
public readonly ?string $uri = null,
) {
}
}

View file

@ -13,6 +13,8 @@ namespace Mcp\Capability\Tool;
use Mcp\Exception\ToolExecutionException;
use Mcp\Exception\ToolNotFoundException;
use Mcp\Schema\Request\CallToolRequest;
use Mcp\Schema\Result\CallToolResult;
/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
@ -23,5 +25,5 @@ interface ToolExecutorInterface
* @throws ToolExecutionException if the tool execution fails
* @throws ToolNotFoundException if the tool is not found
*/
public function call(ToolCall $input): ToolCallResult;
public function call(CallToolRequest $request): CallToolResult;
}

View file

@ -14,12 +14,12 @@ namespace Mcp\Capability;
use Mcp\Capability\Tool\CollectionInterface;
use Mcp\Capability\Tool\IdentifierInterface;
use Mcp\Capability\Tool\MetadataInterface;
use Mcp\Capability\Tool\ToolCall;
use Mcp\Capability\Tool\ToolCallResult;
use Mcp\Capability\Tool\ToolExecutorInterface;
use Mcp\Exception\InvalidCursorException;
use Mcp\Exception\ToolExecutionException;
use Mcp\Exception\ToolNotFoundException;
use Mcp\Schema\Request\CallToolRequest;
use Mcp\Schema\Result\CallToolResult;
/**
* A collection of tools. All tools need to implement IdentifierInterface.
@ -60,18 +60,18 @@ class ToolChain implements ToolExecutorInterface, CollectionInterface
}
}
public function call(ToolCall $input): ToolCallResult
public function call(CallToolRequest $request): CallToolResult
{
foreach ($this->items as $item) {
if ($item instanceof ToolExecutorInterface && $input->name === $item->getName()) {
if ($item instanceof ToolExecutorInterface && $request->name === $item->getName()) {
try {
return $item->call($input);
return $item->call($request);
} catch (\Throwable $e) {
throw new ToolExecutionException($input, $e);
throw new ToolExecutionException($request, $e);
}
}
}
throw new ToolNotFoundException($input);
throw new ToolNotFoundException($request);
}
}