Skip to content

Commit 496e8cb

Browse files
authored
Merge branch 'modelcontextprotocol:main' into Server-pagination-of-fixed-requests
2 parents dc95211 + 20e789d commit 496e8cb

19 files changed

+102
-57
lines changed

.github/workflows/pipeline.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ jobs:
3030
with:
3131
dependency-versions: "${{ matrix.dependencies }}"
3232

33-
- name: Install PHP Dependencies
34-
run: composer install --no-scripts
35-
3633
- name: Tests
3734
run: vendor/bin/phpunit --exclude-group inspector
3835

@@ -54,9 +51,6 @@ jobs:
5451
- name: Install Composer
5552
uses: "ramsey/composer-install@v3"
5653

57-
- name: Install PHP Dependencies
58-
run: composer install --no-scripts
59-
6054
- name: Code Style PHP
6155
run: vendor/bin/php-cs-fixer fix --dry-run
6256

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ The official PHP SDK for Model Context Protocol (MCP). It provides a framework-a
44

55
> [!IMPORTANT]
66
> Currently, we are still in the process of merging [Symfony's MCP SDK](https://github.com/symfony/mcp-sdk) and
7-
> [PHP-MCP](https://github.com/php-mcp) components. Not all code paths are fully tested, complete, or this package
8-
> may contain duplicate functionality or dead code.
7+
> [PHP-MCP](https://github.com/php-mcp) components. Not all code paths are fully tested or complete, and this package
8+
> may still contain duplicate functionality or dead code.
99
>
1010
> If you want to help us stabilize the SDK, please see the
1111
> [issue tracker](https://github.com/modelcontextprotocol/php-sdk/issues).
@@ -21,15 +21,15 @@ Until the first major release, this SDK is considered
2121
## 🚧 Roadmap
2222

2323
Features
24-
- [x] bring back php-mcp examples
24+
- [x] Bring back PHP-MCP examples
2525
- [ ] Glue handler, registry and reference handlers
2626
- [ ] Revive `ServerBuilder`
2727
- [ ] Revive transports
2828
- [ ] Streamable Transport https://github.com/modelcontextprotocol/php-sdk/issues/7
2929
- [ ] Http/SSE-based Transport https://github.com/modelcontextprotocol/php-sdk/issues/8
3030
- [ ] Support pagination
3131
- [ ] Support Schema validation
32-
- [ ] Support Multiple Versions of MCP Specification https://github.com/modelcontextprotocol/php-sdk/issues/14
32+
- [ ] Support multiple versions of the MCP specification https://github.com/modelcontextprotocol/php-sdk/issues/14
3333
- [ ] (Re-)Implement missing Notification & Request Handlers https://github.com/modelcontextprotocol/php-sdk/issues/9
3434

3535
---
@@ -143,7 +143,7 @@ the project. See the [contributing guide](CONTRIBUTING.md) to get started before
143143
[send pull requests](https://github.com/modelcontextprotocol/php-sdk/pulls).
144144

145145
## Credits
146-
The starting point for this SDK was [PHP-MCP](https://github.com/php-mcp/server) project, initiated by [Kyrian Obikwelu](https://github.com/CodeWithKyrian). We are grateful for the work done by Kyrian and other contributors to that repository, which created a solid foundation for this SDK.
146+
The starting point for this SDK was the [PHP-MCP](https://github.com/php-mcp/server) project, initiated by [Kyrian Obikwelu](https://github.com/CodeWithKyrian). We are grateful for the work done by Kyrian and other contributors to that repository, which created a solid foundation for this SDK.
147147

148148
## License
149149

src/Schema/JsonRpc/Request.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ abstract public static function getMethod(): string;
3636
/**
3737
* @param RequestData $data
3838
*/
39-
public static function fromArray(array $data): self
39+
public static function fromArray(array $data): static
4040
{
4141
if (($data['jsonrpc'] ?? null) !== MessageInterface::JSONRPC_VERSION) {
4242
throw new InvalidArgumentException('Invalid or missing "jsonrpc" version for Request.');
@@ -68,7 +68,7 @@ public static function fromArray(array $data): self
6868
/**
6969
* @param array<string, mixed>|null $params
7070
*/
71-
abstract protected static function fromParams(?array $params): self;
71+
abstract protected static function fromParams(?array $params): static;
7272

7373
public function getId(): string|int
7474
{
@@ -97,7 +97,7 @@ public function jsonSerialize(): array
9797
}
9898

9999
/**
100-
* @return array<string, mixed>|null
100+
* @return array<non-empty-string, mixed>|null
101101
*/
102102
abstract protected function getParams(): ?array;
103103
}

src/Schema/Request/CallToolRequest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
* @author Kyrian Obikwelu <[email protected]>
2121
*/
22-
class CallToolRequest extends Request
22+
final class CallToolRequest extends Request
2323
{
2424
/**
2525
* @param string $name the name of the tool to invoke
@@ -36,7 +36,7 @@ public static function getMethod(): string
3636
return 'tools/call';
3737
}
3838

39-
protected static function fromParams(?array $params): Request
39+
protected static function fromParams(?array $params): static
4040
{
4141
if (!isset($params['name']) || !\is_string($params['name'])) {
4242
throw new InvalidArgumentException('Missing or invalid "name" parameter for tools/call.');
@@ -58,7 +58,10 @@ protected static function fromParams(?array $params): Request
5858
);
5959
}
6060

61-
protected function getParams(): ?array
61+
/**
62+
* @return array{name: string, arguments: array<string, mixed>}
63+
*/
64+
protected function getParams(): array
6265
{
6366
return [
6467
'name' => $this->name,

src/Schema/Request/CompletionCompleteRequest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @author Kyrian Obikwelu <[email protected]>
2323
*/
24-
class CompletionCompleteRequest extends Request
24+
final class CompletionCompleteRequest extends Request
2525
{
2626
/**
2727
* @param PromptReference|ResourceReference $ref the prompt or resource to complete
@@ -38,7 +38,7 @@ public static function getMethod(): string
3838
return 'completion/complete';
3939
}
4040

41-
protected static function fromParams(?array $params): Request
41+
protected static function fromParams(?array $params): static
4242
{
4343
if (!isset($params['ref']) || !\is_array($params['ref'])) {
4444
throw new InvalidArgumentException('Missing or invalid "ref" parameter for completion/complete.');
@@ -57,7 +57,13 @@ protected static function fromParams(?array $params): Request
5757
return new self($ref, $params['argument']);
5858
}
5959

60-
protected function getParams(): ?array
60+
/**
61+
* @return array{
62+
* ref: PromptReference|ResourceReference,
63+
* argument: array{ name: string, value: string }
64+
* }
65+
*/
66+
protected function getParams(): array
6167
{
6268
return [
6369
'ref' => $this->ref,

src/Schema/Request/CreateSamplingMessageRequest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* @author Kyrian Obikwelu <[email protected]>
2525
*/
26-
class CreateSamplingMessageRequest extends Request
26+
final class CreateSamplingMessageRequest extends Request
2727
{
2828
/**
2929
* @param SamplingMessage[] $messages the messages to send to the model
@@ -59,7 +59,7 @@ public static function getMethod(): string
5959
return 'sampling/createMessage';
6060
}
6161

62-
protected static function fromParams(?array $params): Request
62+
protected static function fromParams(?array $params): static
6363
{
6464
if (!isset($params['messages']) || !\is_array($params['messages'])) {
6565
throw new InvalidArgumentException('Missing or invalid "messages" parameter for sampling/createMessage.');
@@ -86,7 +86,19 @@ protected static function fromParams(?array $params): Request
8686
);
8787
}
8888

89-
protected function getParams(): ?array
89+
/**
90+
* @return array{
91+
* messages: SamplingMessage[],
92+
* maxTokens: int,
93+
* preferences?: ModelPreferences,
94+
* systemPrompt?: string,
95+
* includeContext?: string,
96+
* temperature?: float,
97+
* stopSequences?: string[],
98+
* metadata?: array<string, mixed>
99+
* }
100+
*/
101+
protected function getParams(): array
90102
{
91103
$params = [
92104
'messages' => $this->messages,

src/Schema/Request/GetPromptRequest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
* @author Kyrian Obikwelu <[email protected]>
2121
*/
22-
class GetPromptRequest extends Request
22+
final class GetPromptRequest extends Request
2323
{
2424
/**
2525
* @param string $name the name of the prompt to get
@@ -36,7 +36,7 @@ public static function getMethod(): string
3636
return 'prompts/get';
3737
}
3838

39-
protected static function fromParams(?array $params): Request
39+
protected static function fromParams(?array $params): static
4040
{
4141
if (!isset($params['name']) || !\is_string($params['name']) || empty($params['name'])) {
4242
throw new InvalidArgumentException('Missing or invalid "name" parameter for prompts/get.');
@@ -55,7 +55,10 @@ protected static function fromParams(?array $params): Request
5555
return new self($params['name'], $arguments);
5656
}
5757

58-
protected function getParams(): ?array
58+
/**
59+
* @return array{name: string, arguments?: array<string, mixed>}
60+
*/
61+
protected function getParams(): array
5962
{
6063
$params = ['name' => $this->name];
6164

src/Schema/Request/InitializeRequest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @author Kyrian Obikwelu <[email protected]>
2323
*/
24-
class InitializeRequest extends Request
24+
final class InitializeRequest extends Request
2525
{
2626
/**
2727
* @param string $protocolVersion The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
@@ -40,7 +40,7 @@ public static function getMethod(): string
4040
return 'initialize';
4141
}
4242

43-
protected static function fromParams(?array $params): Request
43+
protected static function fromParams(?array $params): static
4444
{
4545
if (!isset($params['protocolVersion'])) {
4646
throw new InvalidArgumentException('protocolVersion is required');
@@ -59,7 +59,10 @@ protected static function fromParams(?array $params): Request
5959
return new self($params['protocolVersion'], $capabilities, $clientInfo);
6060
}
6161

62-
protected function getParams(): ?array
62+
/**
63+
* @return array{protocolVersion: string, capabilities: ClientCapabilities, clientInfo: Implementation}
64+
*/
65+
protected function getParams(): array
6366
{
6467
return [
6568
'protocolVersion' => $this->protocolVersion,

src/Schema/Request/ListPromptsRequest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @author Kyrian Obikwelu <[email protected]>
2020
*/
21-
class ListPromptsRequest extends Request
21+
final class ListPromptsRequest extends Request
2222
{
2323
/**
2424
* If provided, the server should return results starting after this cursor.
@@ -35,11 +35,14 @@ public static function getMethod(): string
3535
return 'prompts/list';
3636
}
3737

38-
protected static function fromParams(?array $params): Request
38+
protected static function fromParams(?array $params): static
3939
{
4040
return new self($params['cursor'] ?? null);
4141
}
4242

43+
/**
44+
* @return array{cursor:string}|null
45+
*/
4346
protected function getParams(): ?array
4447
{
4548
$params = [];

src/Schema/Request/ListResourceTemplatesRequest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @author Kyrian Obikwelu <[email protected]>
2020
*/
21-
class ListResourceTemplatesRequest extends Request
21+
final class ListResourceTemplatesRequest extends Request
2222
{
2323
/**
2424
* @param string|null $cursor An opaque token representing the current pagination position.
@@ -35,11 +35,14 @@ public static function getMethod(): string
3535
return 'resources/templates/list';
3636
}
3737

38-
protected static function fromParams(?array $params): Request
38+
protected static function fromParams(?array $params): static
3939
{
4040
return new self($params['cursor'] ?? null);
4141
}
4242

43+
/**
44+
* @return array{cursor:string}|null
45+
*/
4346
protected function getParams(): ?array
4447
{
4548
$params = [];

0 commit comments

Comments
 (0)