feat: Add output schema support to MCP tools (#153)

This commit is contained in:
Sule-Balogun Olanrewaju 2026-01-11 20:14:48 +00:00 • committed by GitHub
commit c0938a19bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -346,4 +346,45 @@ final class SchemaGeneratorTest extends TestCase
$this->expectException(InvalidArgumentException::class);
$this->schemaGenerator->generate($method);
}
public function testGenerateOutputSchemaReturnsNullForVoidReturnType(): void
{
$method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'noParams');
$schema = $this->schemaGenerator->generateOutputSchema($method);
$this->assertNull($schema);
}
public function testGenerateOutputSchemaWithReturnDescription(): void
{
$method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'returnWithExplicitOutputSchema');
$schema = $this->schemaGenerator->generateOutputSchema($method);
$this->assertEquals([
'type' => 'object',
'properties' => [
'message' => ['type' => 'string'],
],
'required' => ['message'],
'description' => 'The result of the operation',
], $schema);
}
public function testGenerateOutputSchemaForArrayReturnType(): void
{
$method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'noParamsWithSchema');
$schema = $this->schemaGenerator->generateOutputSchema($method);
$this->assertEquals([
'type' => 'object',
'additionalProperties' => true,
], $schema);
}
public function testGenerateOutputSchemaForComplexNestedSchema(): void
{
$method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'complexNestedSchema');
$schema = $this->schemaGenerator->generateOutputSchema($method);
$this->assertEquals([
'type' => 'object',
'additionalProperties' => true,
], $schema);
}
}