[Server] Keep injectable parameters out of the published inputSchema (#482)
This commit is contained in:
parent
ff0b5fadc8
commit
e173367c5f
2 changed files with 156 additions and 18 deletions
|
|
@ -13,6 +13,8 @@ namespace Mcp\Tests\Unit\Capability\Discovery;
|
|||
|
||||
use Mcp\Capability\Attribute\McpTool;
|
||||
use Mcp\Capability\Attribute\Schema;
|
||||
use Mcp\Server\ClientGateway;
|
||||
use Mcp\Server\RequestContext;
|
||||
use Mcp\Tests\Unit\Fixtures\Enum\BackedIntEnum;
|
||||
use Mcp\Tests\Unit\Fixtures\Enum\BackedStringEnum;
|
||||
use Mcp\Tests\Unit\Fixtures\Enum\UnitEnum;
|
||||
|
|
@ -519,6 +521,13 @@ class SchemaGeneratorFixture
|
|||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query The search query
|
||||
*/
|
||||
public function withInjectableParameters(string $query, ClientGateway $gateway, RequestContext $context, int $limit = 10): void
|
||||
{
|
||||
}
|
||||
|
||||
// ===== OUTPUT SCHEMA FIXTURES =====
|
||||
#[McpTool(
|
||||
outputSchema: [
|
||||
|
|
|
|||
|
|
@ -413,6 +413,17 @@ final class SchemaGeneratorTest extends TestCase
|
|||
$this->assertEquals(['inferredParam'], $schema['required']);
|
||||
}
|
||||
|
||||
public function testExcludesInjectableParameterTypesFromSchema(): void
|
||||
{
|
||||
$method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'withInjectableParameters');
|
||||
$schema = $this->schemaGenerator->generate($method);
|
||||
$this->assertArrayNotHasKey('gateway', $schema['properties']);
|
||||
$this->assertArrayNotHasKey('context', $schema['properties']);
|
||||
$this->assertEquals(['type' => 'string', 'description' => 'The search query'], $schema['properties']['query']);
|
||||
$this->assertEquals(['type' => 'integer', 'default' => 10], $schema['properties']['limit']);
|
||||
$this->assertEquals(['query'], $schema['required']);
|
||||
}
|
||||
|
||||
public static function methodsWithForbiddenParameter(): array
|
||||
{
|
||||
return [
|
||||
|
|
|
|||
Loading…
Reference in a new issue