[Capability] Remove CompletionProvider's dead providerClass argument (#499)

* [Capability] Remove CompletionProvider's dead providerClass argument

It always threw on construction, so it never worked in any release. `provider:`
takes the same class-string and is now the first positional argument.

* Reword Changelog
This commit is contained in:
Christopher Hertel 2026-09-07 23:27:53 +02:00 • committed by GitHub
commit f39625b257
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 197 additions and 10 deletions

View file

@ -0,0 +1,38 @@
<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mcp\Tests\Integration\Fixture\Completion;
use Mcp\Capability\Attribute\CompletionProvider;
use Mcp\Capability\Attribute\McpPrompt;
/**
* @author Christopher Hertel <mail@christopher-hertel.de>
*/
final class BookingElements
{
/**
* Confirms a seat booking.
*
* @param string $seat the seat to book
*
* @return array the prompt messages
*/
#[McpPrompt(name: 'book_seat')]
public function bookSeat(
#[CompletionProvider(provider: SeatCompletionProvider::class)]
string $seat,
): array {
return [
['role' => 'user', 'content' => \sprintf('Book seat %s for me.', $seat)],
];
}
}

View file

@ -0,0 +1,42 @@
<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mcp\Tests\Integration\Fixture\Completion;
use Mcp\Capability\Completion\ProviderInterface;
/**
* A provider that cannot be built without its seat map.
*
* The constructor takes a scalar the auto-wiring container cannot supply, so a
* completion that comes back with seats in it proves the provider was taken
* from the container rather than instantiated on the spot.
*
* @author Christopher Hertel <mail@christopher-hertel.de>
*/
final class SeatCompletionProvider implements ProviderInterface
{
/**
* @param list<string> $seats
*/
public function __construct(
private readonly array $seats,
) {
}
public function getCompletions(string $currentValue): array
{
return array_values(array_filter(
$this->seats,
static fn (string $seat): bool => str_starts_with($seat, $currentValue),
));
}
}

View file

@ -0,0 +1,31 @@
<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*
* Server for {@see \Mcp\Tests\Integration\CompletionTest}.
*/
use Mcp\Capability\Registry\Container;
use Mcp\Server;
use Mcp\Server\Transport\StdioTransport;
use Mcp\Tests\Integration\Fixture\Completion\SeatCompletionProvider;
require_once dirname(__DIR__, 3).'/vendor/autoload.php';
$container = new Container();
$container->set(SeatCompletionProvider::class, new SeatCompletionProvider(['12A', '12B', '14C']));
Server::builder()
->setServerInfo('integration-server', '1.0.0')
->setContainer($container)
->setDiscovery(__DIR__, ['Completion'])
->build()
->run(new StdioTransport());