Skip to content

Commit 031068e

Browse files
committed
Introducing Capability Registry & Discovery
1 parent 64af4e7 commit 031068e

20 files changed

+4063
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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>|null $providerClass
25+
* @param class-string<ProviderInterface>|ProviderInterface|null $provider if a class-string, it will be
26+
* resolved from the container at the
27+
* point of use
28+
*/
29+
public function __construct(
30+
public ?string $providerClass = null,
31+
public string|ProviderInterface|null $provider = null,
32+
public ?array $values = null,
33+
public ?string $enum = null,
34+
) {
35+
if (1 !== \count(array_filter([$provider, $values, $enum]))) {
36+
throw new InvalidArgumentException('Only one of provider, values, or enum can be set.');
37+
}
38+
}
39+
}
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)