#!/usr/bin/env php _`", not an * override — so every tool below is listed as `scribase_scribase_`, * doubled, since this package's own MCP tool names already start with * `scribase_`. Harmless (the agent calls whatever name is actually * listed), but real, hence checked here rather than assumed. * * Run it: * php scripts/toolbox-check.php * SCRIBASE_API_KEY=sbk_... php scripts/toolbox-check.php # skip provisioning */ require __DIR__.'/../vendor/autoload.php'; use Mcp\Client; use Mcp\Client\Transport\StdioTransport; use Symfony\AI\Agent\Bridge\Mcp\ClientToolset; use Symfony\AI\Agent\Bridge\Mcp\McpToolbox; use Symfony\Component\HttpClient\HttpClient; const API_BASE = 'https://api.scribase.com'; const UA = 'scribase-mcp-php/0.1.0 (+https://github.com/caelum0x/scribase-mcp-php)'; function solvePow(string $challenge, int $bits): int { $nonce = 0; $prefixZeroBytes = intdiv($bits, 8); $remainderBits = $bits % 8; while (true) { $hash = hash('sha256', "{$challenge}:{$nonce}", true); $ok = true; for ($i = 0; $i < $prefixZeroBytes; ++$i) { if ("\x00" !== $hash[$i]) { $ok = false; break; } } if ($ok && $remainderBits > 0 && (\ord($hash[$prefixZeroBytes]) >> (8 - $remainderBits)) !== 0) { $ok = false; } if ($ok) { return $nonce; } ++$nonce; } } $scribaseKey = getenv('SCRIBASE_API_KEY') ?: null; if (null === $scribaseKey) { echo "No SCRIBASE_API_KEY set — provisioning a real, free, no-login temporary project.\n"; $http = HttpClient::create(); $challengeResponse = $http->request('POST', API_BASE.'/v1/temporary-projects/challenge', [ 'headers' => ['User-Agent' => UA, 'Accept' => 'application/json'], ]); $challengeBody = $challengeResponse->toArray(false); $nonce = solvePow($challengeBody['challenge'], (int) $challengeBody['bits']); $createResponse = $http->request('POST', API_BASE.'/v1/temporary-projects', [ 'headers' => ['User-Agent' => UA, 'Accept' => 'application/json', 'Content-Type' => 'application/json'], 'json' => ['name' => 'scribase-mcp-php-toolbox-check', 'challenge' => $challengeBody['challenge'], 'nonce' => (string) $nonce], ]); if (201 !== $createResponse->getStatusCode()) { fwrite(STDERR, "Provisioning failed (HTTP {$createResponse->getStatusCode()}): {$createResponse->getContent(false)}\n"); fwrite(STDERR, "If this is a rate limit, run `php scripts/verify-live.php` instead (it has the throwaway-account fallback), then re-run this script with its SCRIBASE_API_KEY.\n"); exit(1); } $created = $createResponse->toArray(false); $tempId = $created['id']; $agentToken = $created['agent_token']; echo "Polling until the environment is ready...\n"; $ready = false; for ($i = 0; $i < 40; ++$i) { sleep(5); $statusResponse = $http->request('GET', API_BASE."/v1/temporary-projects/{$tempId}", [ 'headers' => ['User-Agent' => UA, 'Accept' => 'application/json', 'Authorization' => "Bearer {$agentToken}"], ]); $status = $statusResponse->toArray(false)['status'] ?? null; if ('ready' === $status) { $ready = true; break; } if ('failed' === $status) { break; } } if (!$ready) { fwrite(STDERR, "Temporary project never reached status=ready.\n"); exit(1); } $scribaseKey = $agentToken; echo "Provisioned. Temporary project self-deletes in 72h if never claimed.\n"; } echo "\n--- spawning the real MCP stdio server and listing its real tools, via the official Symfony AI MCP bridge ---\n"; $toolset = new ClientToolset( 'scribase', Client::builder()->setClientInfo('scribase-mcp-php-toolbox-check', '0.1.0')->build(), new StdioTransport( command: \PHP_BINARY, args: [__DIR__.'/../bin/scribase-mcp-server'], env: ['SCRIBASE_API_KEY' => $scribaseKey], ), ); $toolbox = new McpToolbox($toolset); $tools = $toolbox->getTools(); if ([] === $tools) { fwrite(STDERR, "McpToolbox listed zero tools — the stdio server did not start or did not respond.\n"); exit(1); } foreach ($tools as $tool) { echo $tool->getName(), "\n ", str_replace("\n", "\n ", trim($tool->getDescription())), "\n\n"; } echo \count($tools)." real tool(s) listed — confirms the bridge, the subprocess, and this package's MCP server all speak to each other correctly.\n";