Skip to content

Commit 69c9fed

Browse files
committed
Adopt Schema component in server handlers
1 parent 0c6d7bf commit 69c9fed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+163
-572
lines changed

examples/cli/src/ExampleTool.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,25 @@
1212
namespace App;
1313

1414
use Mcp\Capability\Tool\MetadataInterface;
15-
use Mcp\Capability\Tool\ToolCall;
16-
use Mcp\Capability\Tool\ToolCallResult;
1715
use Mcp\Capability\Tool\ToolExecutorInterface;
16+
use Mcp\Schema\Content\TextContent;
17+
use Mcp\Schema\Request\CallToolRequest;
18+
use Mcp\Schema\Result\CallToolResult;
1819

1920
/**
2021
* @author Tobias Nyholm <[email protected]>
2122
*/
2223
class ExampleTool implements MetadataInterface, ToolExecutorInterface
2324
{
24-
public function call(ToolCall $input): ToolCallResult
25+
public function call(CallToolRequest $request): CallToolResult
2526
{
2627
$format = $input->arguments['format'] ?? 'Y-m-d H:i:s';
2728

28-
return new ToolCallResult(
29-
(new \DateTime('now', new \DateTimeZone('UTC')))->format($format)
30-
);
29+
return new CallToolResult([
30+
new TextContent(
31+
(new \DateTime('now', new \DateTimeZone('UTC')))->format($format),
32+
),
33+
]);
3134
}
3235

3336
public function getName(): string

src/Capability/Tool/ToolCall.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/Capability/Tool/ToolCallResult.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/Capability/Tool/ToolExecutorInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Mcp\Exception\ToolExecutionException;
1515
use Mcp\Exception\ToolNotFoundException;
16+
use Mcp\Schema\Request\CallToolRequest;
17+
use Mcp\Schema\Result\CallToolResult;
1618

1719
/**
1820
* @author Tobias Nyholm <[email protected]>
@@ -23,5 +25,5 @@ interface ToolExecutorInterface
2325
* @throws ToolExecutionException if the tool execution fails
2426
* @throws ToolNotFoundException if the tool is not found
2527
*/
26-
public function call(ToolCall $input): ToolCallResult;
28+
public function call(CallToolRequest $request): CallToolResult;
2729
}

src/Capability/ToolChain.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
use Mcp\Capability\Tool\CollectionInterface;
1515
use Mcp\Capability\Tool\IdentifierInterface;
1616
use Mcp\Capability\Tool\MetadataInterface;
17-
use Mcp\Capability\Tool\ToolCall;
18-
use Mcp\Capability\Tool\ToolCallResult;
1917
use Mcp\Capability\Tool\ToolExecutorInterface;
2018
use Mcp\Exception\InvalidCursorException;
2119
use Mcp\Exception\ToolExecutionException;
2220
use Mcp\Exception\ToolNotFoundException;
21+
use Mcp\Schema\Request\CallToolRequest;
22+
use Mcp\Schema\Request\ToolCallRequest;
23+
use Mcp\Schema\Result\CallToolResult;
24+
use Mcp\Schema\Result\ToolCallResult;
2325

2426
/**
2527
* A collection of tools. All tools need to implement IdentifierInterface.
@@ -60,18 +62,18 @@ public function getMetadata(int $count, ?string $lastIdentifier = null): iterabl
6062
}
6163
}
6264

63-
public function call(ToolCall $input): ToolCallResult
65+
public function call(CallToolRequest $request): CallToolResult
6466
{
6567
foreach ($this->items as $item) {
66-
if ($item instanceof ToolExecutorInterface && $input->name === $item->getName()) {
68+
if ($item instanceof ToolExecutorInterface && $request->name === $item->getName()) {
6769
try {
68-
return $item->call($input);
70+
return $item->call($request);
6971
} catch (\Throwable $e) {
70-
throw new ToolExecutionException($input, $e);
72+
throw new ToolExecutionException($request, $e);
7173
}
7274
}
7375
}
7476

75-
throw new ToolNotFoundException($input);
77+
throw new ToolNotFoundException($request);
7678
}
7779
}

src/Exception/ToolExecutionException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111

1212
namespace Mcp\Exception;
1313

14-
use Mcp\Capability\Tool\ToolCall;
14+
use Mcp\Schema\Request\CallToolRequest;
1515

1616
/**
1717
* @author Tobias Nyholm <[email protected]>
1818
*/
1919
final class ToolExecutionException extends \RuntimeException implements ExceptionInterface
2020
{
2121
public function __construct(
22-
public readonly ToolCall $toolCall,
22+
public readonly CallToolRequest $callToolRequest,
2323
?\Throwable $previous = null,
2424
) {
25-
parent::__construct(\sprintf('Execution of tool "%s" failed with error: %s', $toolCall->name, $previous?->getMessage() ?? ''), previous: $previous);
25+
parent::__construct(\sprintf('Execution of tool "%s" failed with error: "%s".', $callToolRequest->name, $previous?->getMessage() ?? ''), previous: $previous);
2626
}
2727
}

src/Exception/ToolNotFoundException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111

1212
namespace Mcp\Exception;
1313

14-
use Mcp\Capability\Tool\ToolCall;
14+
use Mcp\Schema\Request\CallToolRequest;
1515

1616
/**
1717
* @author Tobias Nyholm <[email protected]>
1818
*/
1919
final class ToolNotFoundException extends \RuntimeException implements NotFoundExceptionInterface
2020
{
2121
public function __construct(
22-
public readonly ToolCall $toolCall,
22+
public readonly CallToolRequest $callToolRequest,
2323
) {
24-
parent::__construct(\sprintf('Tool not found for call: "%s"', $toolCall->name));
24+
parent::__construct(\sprintf('Tool not found for call: "%s".', $callToolRequest->name));
2525
}
2626
}

src/Message/Error.php

Lines changed: 0 additions & 76 deletions
This file was deleted.

src/Message/Factory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Mcp\Message;
1313

1414
use Mcp\Exception\InvalidInputMessageException;
15+
use Mcp\Schema\JsonRpc\Notification;
16+
use Mcp\Schema\JsonRpc\Request;
1517

1618
/**
1719
* @author Christopher Hertel <[email protected]>
@@ -35,9 +37,9 @@ public function create(string $input): iterable
3537
if (!isset($message['method'])) {
3638
yield new InvalidInputMessageException('Invalid JSON-RPC request, missing "method".');
3739
} elseif (str_starts_with((string) $message['method'], 'notifications/')) {
38-
yield Notification::from($message);
40+
yield Notification::fromArray($message);
3941
} else {
40-
yield Request::from($message);
42+
yield Request::fromArray($message);
4143
}
4244
}
4345
}

src/Message/Notification.php

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)