Skip to content

Commit 780db8a

Browse files
committed
Prepare package slicing by strict namespace refactoring into Client, Schema, and Server
1 parent c5dbfb6 commit 780db8a

427 files changed

Lines changed: 1387 additions & 1202 deletions

File tree

Some content is hidden

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

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.deptrac.cache
12
.phpunit.cache
23
.php-cs-fixer.cache
34
composer.lock

‎CHANGELOG.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22

33
All notable changes to `mcp/sdk` will be documented in this file.
44

5+
0.9.0
6+
-----
7+
8+
* [BC Break] Split the root namespace into `Mcp\Schema`, `Mcp\Client` and `Mcp\Server` to prepare package slicing. `Mcp\Schema` depends on nothing, `Mcp\Client` and `Mcp\Server` depend on `Mcp\Schema` only — enforced by Deptrac (`make deptrac`).
9+
* `Mcp\Server` => `Mcp\Server\Server`
10+
* `Mcp\Client` => `Mcp\Client\Client`
11+
* `Mcp\Capability\*` => `Mcp\Server\Capability\*` (`Attribute`, `Completion`, `Discovery`, `Formatter`, `Logger`, `Registry`, `Tool`, plus `Registry` and `RegistryInterface`)
12+
* `Mcp\Event\*` => `Mcp\Server\Event\*`
13+
* `Mcp\JsonRpc\MessageFactory` => `Mcp\Schema\MessageFactory`
14+
* `Mcp\Server\Stateless\RequestMeta` => `Mcp\Schema\RequestMeta`
15+
* [BC Break] Distribute `Mcp\Exception\*` across the three namespaces.
16+
* `Mcp\Exception\{ExceptionInterface,InvalidArgumentException,LogicException,RuntimeException}` => the same names under `Mcp\Schema\Exception\`, `Mcp\Client\Exception\` and `Mcp\Server\Exception\` — pick the one matching the package you catch around
17+
* `Mcp\Exception\Exception` => `Mcp\Client\Exception\Exception` and `Mcp\Server\Exception\Exception`
18+
* `Mcp\Exception\{InvalidInputMessageException,MissingRequestMetaException}` => `Mcp\Schema\Exception\*`
19+
* `Mcp\Exception\{ConnectionException,ElicitationException,RequestException,RootsException,SamplingException}` => `Mcp\Client\Exception\*`
20+
* `Mcp\Exception\{BadMethodCallException,ClientException,ClientRegistrationException,ConfigurationException,ContainerException,InvalidCursorException,MissingRequiredClientCapabilityException,NotFoundExceptionInterface,PromptGetException,PromptNotFoundException,RegistryException,RequestStateException,ResourceNotFoundException,ResourceReadException,ServiceNotFoundException,ToolCallException,ToolNotFoundException}` => `Mcp\Server\Exception\*`
21+
* `Mcp\Exception\TimeoutException` and `Mcp\Exception\HandlerNotFoundException` are removed; both were unused.
22+
* `Mcp\Server\Exception\ExceptionInterface` and `Mcp\Client\Exception\ExceptionInterface` extend `Mcp\Schema\Exception\ExceptionInterface`, so catching the latter still catches any SDK exception.
23+
* The named exceptions now extend their package's `RuntimeException`/`InvalidArgumentException` instead of the global ones, so `catch (Mcp\Server\Exception\RuntimeException)` reaches `ToolCallException`, `PromptGetException` and friends.
24+
525
0.8.0
626
-----
727

‎Makefile‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ cs:
2323
phpstan:
2424
vendor/bin/phpstan --memory-limit=-1
2525

26+
deptrac:
27+
vendor/bin/deptrac analyze
28+
2629
tests:
2730
vendor/bin/phpunit
2831

@@ -74,9 +77,9 @@ coverage:
7477

7578
ci: ci-stable
7679

77-
ci-stable: deps-stable cs phpstan tests
80+
ci-stable: deps-stable cs phpstan deptrac tests
7881

79-
ci-lowest: deps-low cs phpstan tests
82+
ci-lowest: deps-low cs phpstan deptrac tests
8083

8184
# The published site is the guides (Zensical) with the phpDocumentor API
8285
# reference mounted at /api/. `zensical build` wipes site/, so it runs first.

‎README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ composer require mcp/sdk
3636
A server is a plain PHP class plus three lines of wiring:
3737

3838
```php
39-
use Mcp\Capability\Attribute\McpResource;
40-
use Mcp\Capability\Attribute\McpTool;
41-
use Mcp\Server;
39+
use Mcp\Server\Capability\Attribute\McpResource;
40+
use Mcp\Server\Capability\Attribute\McpTool;
41+
use Mcp\Server\Server;
4242
use Mcp\Server\Transport\StdioTransport;
4343

4444
class Calculator
@@ -72,7 +72,7 @@ The walkthrough in [First server](docs/get-started/first-server.md) explains eac
7272
## Build a client
7373

7474
```php
75-
use Mcp\Client;
75+
use Mcp\Client\Client;
7676
use Mcp\Client\Transport\StdioTransport;
7777

7878
$client = Client::builder()

‎composer.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"require-dev": {
4242
"ext-openssl": "*",
4343
"composer/semver": "^3.0",
44+
"deptrac/deptrac": "^4.7",
4445
"firebase/php-jwt": "^6.10 || ^7.0",
4546
"laminas/laminas-httphandlerrunner": "^2.12",
4647
"nyholm/psr7": "^1.8",
@@ -84,7 +85,7 @@
8485
"Mcp\\Tests\\": "tests/"
8586
},
8687
"classmap": [
87-
"tests/Unit/Capability/Discovery/Fixtures/AlternativeFileNameToolHandler.class.inc"
88+
"tests/Unit/Server/Capability/Discovery/Fixtures/AlternativeFileNameToolHandler.class.inc"
8889
]
8990
},
9091
"config": {

‎deptrac.yaml‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
deptrac:
2+
paths:
3+
- src
4+
layers:
5+
- name: Client
6+
collectors:
7+
- type: classLike
8+
value: Mcp\\Client\\.*
9+
- name: Schema
10+
collectors:
11+
- type: classLike
12+
value: Mcp\\Schema\\.*
13+
- name: Server
14+
collectors:
15+
- type: classLike
16+
value: Mcp\\Server\\.*
17+
ruleset:
18+
Client: [Schema]
19+
Schema: []
20+
Server: [Schema]
21+
22+
# Slicing of Extensions is currently unclear
23+
skip_violations:
24+
Mcp\Schema\Extension\ExtensionInterface:
25+
- Mcp\Server\Handler\Request\RequestHandlerInterface
26+
Mcp\Schema\Extension\AbstractExtension:
27+
- Mcp\Server\Handler\Request\RequestHandlerInterface
28+
Mcp\Schema\Extension\Apps\McpApps:
29+
- Mcp\Server\Handler\Request\RequestHandlerInterface

‎docs/advanced/events.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ The MCP SDK provides a PSR-14 compatible event system that allows you to hook in
77
Configure an event dispatcher when building your server:
88

99
```php
10-
use Mcp\Event\RequestEvent;
11-
use Mcp\Server;
10+
use Mcp\Server\Event\RequestEvent;
11+
use Mcp\Server\Server;
1212
use Symfony\Component\EventDispatcher\EventDispatcher;
1313

1414
$dispatcher = new EventDispatcher();
@@ -86,7 +86,7 @@ These events are dispatched when the lists of available capabilities change:
8686
These events carry no data and are used to notify clients that they should refresh their capability lists.
8787

8888
```php
89-
use Mcp\Event\ToolListChangedEvent;
89+
use Mcp\Server\Event\ToolListChangedEvent;
9090

9191
$dispatcher->addListener(ToolListChangedEvent::class, function (ToolListChangedEvent $event) {
9292
$logger->info('Tool list has changed, clients should refresh');

‎docs/advanced/extensions.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ the SDK places the advertisement correctly for whichever era the client speaks:
77

88
```php
99
use Mcp\Schema\Extension\Apps\McpApps;
10-
use Mcp\Server;
10+
use Mcp\Server\Server;
1111

1212
$server = Server::builder()
1313
->setServerInfo('My Server', '1.0.0')
@@ -112,11 +112,11 @@ descriptor marker: `McpApps::resourceMarker()` is a method call and cannot appea
112112
in an attribute, so spell it as `new \stdClass()` there.
113113

114114
```php
115-
use Mcp\Capability\Attribute\McpResource;
116-
use Mcp\Capability\Attribute\McpTool;
117115
use Mcp\Schema\Extension\Apps\McpApps;
118116
use Mcp\Schema\Extension\Apps\ToolVisibility;
119117
use Mcp\Schema\Extension\Apps\UiToolMeta;
118+
use Mcp\Server\Capability\Attribute\McpResource;
119+
use Mcp\Server\Capability\Attribute\McpTool;
120120

121121
final class WeatherApp
122122
{

‎docs/client/connecting.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The `Client\Builder` provides fluent configuration of client instances.
1313
### Basic Configuration
1414

1515
```php
16-
use Mcp\Client;
16+
use Mcp\Client\Client;
1717

1818
$client = Client::builder()
1919
->setClientInfo('My Application', '1.0.0', 'Description of my client')

‎docs/client/errors.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The client throws exceptions for various error conditions:
77
Thrown when connection or initialization fails:
88

99
```php
10-
use Mcp\Exception\ConnectionException;
10+
use Mcp\Client\Exception\ConnectionException;
1111

1212
try {
1313
$client->connect($transport);
@@ -21,7 +21,7 @@ try {
2121
Thrown when a request returns an error response:
2222

2323
```php
24-
use Mcp\Exception\RequestException;
24+
use Mcp\Client\Exception\RequestException;
2525

2626
try {
2727
$result = $client->callTool('unknown_tool', []);
@@ -38,12 +38,12 @@ Here's a comprehensive example demonstrating client usage:
3838
```php-file
3939
<?php
4040
41-
use Mcp\Client;
41+
use Mcp\Client\Client;
4242
use Mcp\Client\Handler\Notification\LoggingNotificationHandler;
4343
use Mcp\Client\Handler\Request\SamplingCallbackInterface;
4444
use Mcp\Client\Handler\Request\SamplingRequestHandler;
4545
use Mcp\Client\Transport\StdioTransport;
46-
use Mcp\Exception\SamplingException;
46+
use Mcp\Client\Exception\SamplingException;
4747
use Mcp\Schema\ClientCapabilities;
4848
use Mcp\Schema\Content\TextContent;
4949
use Mcp\Schema\Enum\LoggingLevel;

0 commit comments

Comments
 (0)