Skip to main content
Glama

CTX: Context as Code (CaC) tool

by context-hub
MIT License
235
  • Apple
  • Linux
StringJsonReader.php1.53 kB
<?php declare(strict_types=1); namespace Butschster\ContextGenerator\Config\Reader; use Butschster\ContextGenerator\Config\Exception\ReaderException; use Psr\Log\LoggerInterface; /** * Reader for JSON configuration provided as a string */ final readonly class StringJsonReader implements ReaderInterface { public function __construct(private string $jsonContent, private ?LoggerInterface $logger = null) {} public function read(string $path): array { $this->logger?->debug('Reading JSON configuration from string', [ 'contentLength' => \strlen($this->jsonContent), ]); try { $config = \json_decode($this->jsonContent, true, flags: JSON_THROW_ON_ERROR); if (!\is_array($config)) { throw new ReaderException('JSON configuration must decode to an array'); } $this->logger?->debug('JSON string successfully parsed'); return $config; } catch (\JsonException $e) { $errorMessage = 'Invalid JSON in configuration string'; $this->logger?->error($errorMessage, [ 'error' => $e->getMessage(), ]); throw new ReaderException($errorMessage, previous: $e); } } public function supports(string $path): bool { // This reader doesn't care about the path - it always supports reading from its string return true; } public function getSupportedExtensions(): array { return []; } }

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/context-hub/generator'

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