[Server] Keep injectable parameters out of the published inputSchema (#482)

This commit is contained in:
Christopher Hertel 2026-08-25 01:12:29 +02:00 • committed by GitHub
commit e173367c5f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -16,6 +16,7 @@
use Mcp\Exception\ClientException;
use Mcp\Schema\Content\TextContent;
use Mcp\Server;
use Mcp\Server\ClientGateway;
use Mcp\Server\RequestContext;
use Mcp\Server\Transport\StdioTransport;
@ -38,5 +39,20 @@ Server::builder()
name: 'summarize',
description: 'Summarizes text by asking the client to sample.',
)
->addTool(
static function (ClientGateway $client, string $text): string {
try {
$result = $client->sample($text, maxTokens: 64);
} catch (ClientException $e) {
return $e->getMessage();
}
assert($result->content instanceof TextContent);
return sprintf('%s said: %s', $result->model, $result->content->text);
},
name: 'summarize_via_gateway',
description: 'Summarizes text through a directly injected gateway.',
)
->build()
->run(new StdioTransport());