| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Server\Exception; |
| 15: | |
| 16: | use Nexus\Mcp\Core\Exception\McpExceptionInterface; |
| 17: | use Nexus\Mcp\Server\Validation\SchemaViolation; |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | final class ToolOutputValidationException extends \RuntimeException implements McpExceptionInterface |
| 24: | { |
| 25: | |
| 26: | |
| 27: | |
| 28: | public function __construct(string $toolName, array $errors, ?\Throwable $previous = null) |
| 29: | { |
| 30: | parent::__construct( |
| 31: | [] === $errors |
| 32: | ? \sprintf('Tool "%s" declares an outputSchema but its result carries no structuredContent.', $toolName) |
| 33: | : \sprintf( |
| 34: | 'Tool "%s" returned structuredContent that does not conform to its outputSchema: %s', |
| 35: | $toolName, |
| 36: | implode(' ', array_map(static fn(SchemaViolation $violation): string => $violation->message, $errors)), |
| 37: | ), |
| 38: | previous: $previous, |
| 39: | ); |
| 40: | } |
| 41: | } |
| 42: | |