Skip to content

Commit ef9f562

Browse files
committed
Adopt Schema component in server handlers
1 parent 0f0fe84 commit ef9f562

File tree

81 files changed

+633
-1326
lines changed

Some content is hidden

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

81 files changed

+633
-1326
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\ToolCallRequest;
18+
use Mcp\Schema\Result\ToolCallResult;
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(ToolCallRequest $input): ToolCallResult
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 ToolCallResult([
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\ToolCallRequest;
17+
use Mcp\Schema\Result\ToolCallResult;
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(ToolCallRequest $input): ToolCallResult;
2729
}

src/Capability/ToolChain.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
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\ToolCallRequest;
22+
use Mcp\Schema\Result\ToolCallResult;
2323

2424
/**
2525
* A collection of tools. All tools need to implement IdentifierInterface.
@@ -60,7 +60,7 @@ public function getMetadata(int $count, ?string $lastIdentifier = null): iterabl
6060
}
6161
}
6262

63-
public function call(ToolCall $input): ToolCallResult
63+
public function call(ToolCallRequest $input): ToolCallResult
6464
{
6565
foreach ($this->items as $item) {
6666
if ($item instanceof ToolExecutorInterface && $input->name === $item->getName()) {

src/Exception/ToolNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Mcp\Exception;
1313

14-
use Mcp\Capability\Tool\ToolCall;
14+
use readonly class;
1515

1616
/**
1717
* @author Tobias Nyholm <[email protected]>

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.

src/Message/Request.php

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

0 commit comments

Comments
 (0)