Skip to main content
Glama
AbstractTool.php2.49 kB
<?php declare(strict_types=1); namespace GoldenPathDigital\LaravelAscend\Tools; abstract class AbstractTool implements ToolInterface { protected string $schemaVersion = '1.0.0'; public function getSchemaVersion(): string { return $this->schemaVersion; } /** * @param array<string, mixed> $data * @param array<int, string> $warnings * * @return array<string, mixed> */ protected function success(array $data, array $warnings = [], float $startedAt = null): array { $startedAt ??= microtime(true); return [ 'schema_version' => $this->getSchemaVersion(), 'ok' => true, 'data' => $data, 'warnings' => $warnings, 'timings' => [ 'ms' => $this->calculateElapsedMilliseconds($startedAt), ], ]; } /** * @param array<int, string> $warnings * * @return array<string, mixed> */ protected function error(string $message, array $warnings = [], float $startedAt = null, ?string $code = null): array { $startedAt ??= microtime(true); return [ 'schema_version' => $this->getSchemaVersion(), 'ok' => false, 'error' => [ 'message' => $message, 'code' => $code, ], 'warnings' => $warnings, 'timings' => [ 'ms' => $this->calculateElapsedMilliseconds($startedAt), ], ]; } private function calculateElapsedMilliseconds(float $startedAt): float { return round((microtime(true) - $startedAt) * 1000, 3); } public function getInputSchema(): array { return $this->buildSchema(); } public function getAnnotations(): array { return []; } /** * @param array<string, array<string, mixed>> $properties * @param array<int, string> $required * @return array<string, mixed> */ protected function buildSchema(array $properties = [], array $required = [], bool $allowAdditional = false): array { $schema = [ 'type' => 'object', 'properties' => $properties === [] ? new \stdClass() : $properties, ]; if ($required !== []) { $schema['required'] = $required; } if (!$allowAdditional) { $schema['additionalProperties'] = false; } return $schema; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aarongrtech/laravel-ascend'

If you have feedback or need assistance with the MCP directory API, please join our Discord server