Skip to content

Commit e64cd4f

Browse files
committed
Adopt SchemaGeneratorInterface after rebase and #153
1 parent dc08010 commit e64cd4f

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/Capability/Discovery/SchemaGenerator.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,18 @@ public function generate(\Reflector $reflection): array
9797
* Only returns an outputSchema if explicitly provided in the McpTool attribute.
9898
* Per MCP spec, outputSchema should only be present when explicitly provided.
9999
*
100-
* @return array<string, mixed>|null
100+
* @return ?array<string, mixed>
101101
*/
102-
public function generateOutputSchema(\ReflectionMethod|\ReflectionFunction $reflection): ?array
102+
public function generateOutputSchema(\Reflector $reflection): ?array
103103
{
104+
if ($reflection instanceof \ReflectionClass) {
105+
throw new BadMethodCallException('Schema generation from ReflectionClass is not implemented yet. Use ReflectionMethod or ReflectionFunction instead.');
106+
}
107+
108+
if (!$reflection instanceof \ReflectionMethod && !$reflection instanceof \ReflectionFunction) {
109+
throw new BadMethodCallException(\sprintf('Schema generation from %s is not supported. Use ReflectionMethod or ReflectionFunction instead.', $reflection::class));
110+
}
111+
104112
// Only return outputSchema if explicitly provided in McpTool attribute
105113
$mcpToolAttrs = $reflection->getAttributes(McpTool::class, \ReflectionAttribute::IS_INSTANCEOF);
106114
if ($mcpToolAttrs) {

src/Capability/Discovery/SchemaGeneratorInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,11 @@ interface SchemaGeneratorInterface
3131
* }
3232
*/
3333
public function generate(\Reflector $reflection): array;
34+
35+
/**
36+
* Generates a JSON Schema for output/result.
37+
*
38+
* @return ?array<string, mixed>
39+
*/
40+
public function generateOutputSchema(\Reflector $reflection): ?array;
3441
}

0 commit comments

Comments
 (0)