Skip to content

Commit 8b58f64

Browse files
committed
Introducing Capability Registry & Discovery
1 parent 64af4e7 commit 8b58f64

34 files changed

+4932
-8
lines changed

composer.json

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,34 @@
88
"name": "Christopher Hertel",
99
"email": "[email protected]"
1010
},
11-
{
12-
"name": "Tobias Nyholm",
13-
"email": "[email protected]"
14-
},
1511
{
1612
"name": "Kyrian Obikwelu",
1713
"email": "[email protected]"
14+
},
15+
{
16+
"name": "Tobias Nyholm",
17+
"email": "[email protected]"
1818
}
1919
],
2020
"require": {
2121
"php": "^8.1",
2222
"ext-fileinfo": "*",
23+
"opis/json-schema": "^2.4",
24+
"phpdocumentor/reflection-docblock": "^5.6",
25+
"psr/event-dispatcher": "^1.0",
2326
"psr/log": "^1.0 || ^2.0 || ^3.0",
24-
"symfony/uid": "^6.4 || ^7.0"
27+
"psr/simple-cache": "^3.0",
28+
"symfony/finder": "^6.4 || ^7.2",
29+
"symfony/uid": "^6.4 || ^7.2"
2530
},
2631
"require-dev": {
32+
"nyholm/nsa": "^1.3",
33+
"php-cs-fixer/shim": "^3.84",
2734
"phpstan/phpstan": "^2.1",
2835
"phpunit/phpunit": "^10.5",
29-
"symfony/console": "^6.4 || ^7.0",
3036
"psr/cache": "^3.0",
31-
"php-cs-fixer/shim": "^3.84",
32-
"nyholm/nsa": "^1.3"
37+
"symfony/console": "^6.4 || ^7.0",
38+
"symfony/event-dispatcher": "^6.4 || ^7.0"
3339
},
3440
"suggest": {
3541
"symfony/console": "To use SymfonyConsoleTransport for STDIO",
@@ -44,5 +50,8 @@
4450
"psr-4": {
4551
"Mcp\\Tests\\": "tests/"
4652
}
53+
},
54+
"config": {
55+
"sort-packages": true
4756
}
4857
}

phpstan.dist.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ parameters:
66
- tests/
77
excludePaths:
88
- examples/cli/vendor/* (?)
9+
- tests/Capability/Discovery/SchemaGeneratorFixture.php
910
treatPhpDocTypesAsCertain: false
1011
ignoreErrors:
1112
-
1213
message: "#^Method .*::test.*\\(\\) has no return type specified\\.$#"
14+
# This errors should actually be fixed, but are ignored for now
15+
-
16+
identifier: missingType.iterableValue
17+
path: src/Capability/Discovery/SchemaGenerator.php
18+
count: 12
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the official PHP MCP SDK.
5+
*
6+
* A collaboration between Symfony and the PHP Foundation.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Mcp\Capability\Attribute;
13+
14+
use Mcp\Capability\Prompt\Completion\ProviderInterface;
15+
use Mcp\Exception\InvalidArgumentException;
16+
17+
/**
18+
* @author Kyrian Obikwelu <[email protected]>
19+
*/
20+
#[\Attribute(\Attribute::TARGET_PARAMETER)]
21+
class CompletionProvider
22+
{
23+
/**
24+
* @param class-string<ProviderInterface>|ProviderInterface|null $provider if a class-string, it will be resolved
25+
* from the container at the point of use
26+
* @param ?array<int, int|float|string> $values a list of values to use for completion
27+
*/
28+
public function __construct(
29+
public ?string $providerClass = null,
30+
public string|ProviderInterface|null $provider = null,
31+
public ?array $values = null,
32+
public ?string $enum = null,
33+
) {
34+
if (1 !== \count(array_filter([$provider, $values, $enum]))) {
35+
throw new InvalidArgumentException('Only one of provider, values, or enum can be set.');
36+
}
37+
}
38+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the official PHP MCP SDK.
5+
*
6+
* A collaboration between Symfony and the PHP Foundation.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Mcp\Capability\Attribute;
13+
14+
/**
15+
* Marks a PHP method as an MCP Prompt generator.
16+
* The method should return the prompt messages, potentially using arguments for templating.
17+
*
18+
* @author Kyrian Obikwelu <[email protected]>
19+
*/
20+
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS)]
21+
final class McpPrompt
22+
{
23+
/**
24+
* @param ?string $name overrides the prompt name (defaults to method name)
25+
* @param ?string $description Optional description of the prompt. Defaults to method DocBlock summary.
26+
*/
27+
public function __construct(
28+
public ?string $name = null,
29+
public ?string $description = null,
30+
) {
31+
}
32+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the official PHP MCP SDK.
5+
*
6+
* A collaboration between Symfony and the PHP Foundation.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Mcp\Capability\Attribute;
13+
14+
use Mcp\Schema\Annotations;
15+
16+
/**
17+
* Marks a PHP class as representing or handling a specific MCP Resource instance.
18+
* Used primarily for the 'resources/list' discovery.
19+
*
20+
* @author Kyrian Obikwelu <[email protected]>
21+
*/
22+
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS)]
23+
final class McpResource
24+
{
25+
/**
26+
* @param string $uri The specific URI identifying this resource instance. Must be unique within the server.
27+
* @param ?string $name A human-readable name for this resource. If null, a default might be generated from the method name.
28+
* @param ?string $description An optional description of the resource. Defaults to class DocBlock summary.
29+
* @param ?string $mimeType the MIME type, if known and constant for this resource
30+
* @param ?int $size the size in bytes, if known and constant
31+
* @param Annotations|null $annotations optional annotations describing the resource
32+
*/
33+
public function __construct(
34+
public string $uri,
35+
public ?string $name = null,
36+
public ?string $description = null,
37+
public ?string $mimeType = null,
38+
public ?int $size = null,
39+
public ?Annotations $annotations = null,
40+
) {
41+
}
42+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the official PHP MCP SDK.
5+
*
6+
* A collaboration between Symfony and the PHP Foundation.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Mcp\Capability\Attribute;
13+
14+
use Mcp\Schema\Annotations;
15+
16+
/**
17+
* Marks a PHP class definition as representing an MCP Resource Template.
18+
* This is informational, used for 'resources/templates/list'.
19+
*
20+
* @author Kyrian Obikwelu <[email protected]>
21+
*/
22+
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS)]
23+
final class McpResourceTemplate
24+
{
25+
/**
26+
* @param string $uriTemplate the URI template string (RFC 6570)
27+
* @param ?string $name A human-readable name for the template type. If null, a default might be generated from the method name.
28+
* @param ?string $description Optional description. Defaults to class DocBlock summary.
29+
* @param ?string $mimeType optional default MIME type for matching resources
30+
* @param ?Annotations $annotations optional annotations describing the resource template
31+
*/
32+
public function __construct(
33+
public string $uriTemplate,
34+
public ?string $name = null,
35+
public ?string $description = null,
36+
public ?string $mimeType = null,
37+
public ?Annotations $annotations = null,
38+
) {
39+
}
40+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the official PHP MCP SDK.
5+
*
6+
* A collaboration between Symfony and the PHP Foundation.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Mcp\Capability\Attribute;
13+
14+
use Mcp\Schema\ToolAnnotations;
15+
16+
/**
17+
* @author Kyrian Obikwelu <[email protected]>
18+
*/
19+
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS)]
20+
class McpTool
21+
{
22+
/**
23+
* @param string|null $name The name of the tool (defaults to the method name)
24+
* @param string|null $description The description of the tool (defaults to the DocBlock/inferred)
25+
* @param ToolAnnotations|null $annotations Optional annotations describing tool behavior
26+
*/
27+
public function __construct(
28+
public ?string $name = null,
29+
public ?string $description = null,
30+
public ?ToolAnnotations $annotations = null,
31+
) {
32+
}
33+
}

0 commit comments

Comments
 (0)