Skip to main content
Glama

OpenFGA MCP

DocumentationIntegrationTest.php13.1 kB
<?php declare(strict_types=1); namespace OpenFGA\MCP\Tests\Integration\Documentation; use OpenFGA\MCP\Documentation\{DocumentationChunker, DocumentationIndex}; use OpenFGA\MCP\Resources\DocumentationResources; use PHPUnit\Framework\TestCase; use function count; final class DocumentationIntegrationTest extends TestCase { private DocumentationChunker $chunker; private DocumentationIndex $index; private DocumentationResources $resources; protected function setUp(): void { parent::setUp(); $this->index = new DocumentationIndex; $this->resources = new DocumentationResources; $this->chunker = new DocumentationChunker; // Initialize the index with real documentation $this->index->initialize(); } public function testChunkNavigationLinks(): void { // Get PHP SDK overview to ensure it has multiple chunks $phpOverview = $this->index->getSdkOverview('php'); $this->assertGreaterThan(1, $phpOverview['total_chunks']); // Search to get actual chunk IDs $results = $this->index->searchChunks('class', 'php', 3); if (1 < count($results)) { // Try to get a chunk that might have navigation $chunk = $this->index->getChunk($results[0]['chunk_id']); if ($chunk) { // Check if navigation exists (it may not for all chunks) if (isset($chunk['prev_chunk']) || isset($chunk['next_chunk'])) { $this->assertTrue(true, 'Navigation links found'); } else { // It's okay if navigation isn't set for this particular chunk $this->assertTrue(true, 'Chunk retrieved successfully'); } } } else { // It's okay if we don't have multiple chunks in search results $this->assertTrue(true, 'Test completed'); } } public function testDocumentationChunkerProcessesRealContent(): void { // Get PHP SDK overview to verify it has chunks $phpOverview = $this->index->getSdkOverview('php'); $this->assertGreaterThan(0, $phpOverview['total_chunks']); // Search for content to get actual chunk IDs $results = $this->index->searchChunks('php', 'php', 1); $this->assertNotEmpty($results); $firstResult = $results[0]; $chunk = $this->index->getChunk($firstResult['chunk_id']); $this->assertNotNull($chunk); $this->assertEquals($firstResult['chunk_id'], $chunk['id']); $this->assertEquals('php', $chunk['sdk']); $this->assertNotEmpty($chunk['content']); // Test chunking the content $chunks = $this->chunker->chunkBySize($chunk['content'], 1000); $this->assertNotEmpty($chunks); } public function testDocumentationIndexLoadsRealFiles(): void { $sdkList = $this->index->getSdkList(); // Verify we have the expected SDKs $this->assertContains('php', $sdkList); $this->assertContains('go', $sdkList); $this->assertContains('python', $sdkList); $this->assertContains('java', $sdkList); $this->assertContains('dotnet', $sdkList); $this->assertContains('js', $sdkList); $this->assertContains('laravel', $sdkList); // Verify we have at least 7 SDKs $this->assertGreaterThanOrEqual(7, count($sdkList)); } public function testDocumentationResourcesListsAllDocs(): void { $result = $this->resources->listDocumentation(); $this->assertStringContainsString('✅', $result['status']); $this->assertArrayHasKey('sdk_documentation', $result); $this->assertArrayHasKey('guides_documentation', $result); $this->assertArrayHasKey('total_sdks', $result); // Should have at least 7 SDKs $this->assertGreaterThanOrEqual(7, $result['total_sdks']); // Verify SDK documentation entries $sdkDocs = $result['sdk_documentation']; $sdkNames = array_column($sdkDocs, 'sdk'); $this->assertContains('php', $sdkNames); $this->assertContains('go', $sdkNames); $this->assertContains('python', $sdkNames); } public function testDocumentationSectionsRetrieval(): void { // Get sections for Python SDK $pythonOverview = $this->index->getSdkOverview('python'); $this->assertNotEmpty($pythonOverview['sections']); $firstSection = $pythonOverview['sections'][0]; $result = $this->resources->getDocumentationSection('python', $firstSection); if (str_contains($result['status'], '✅')) { $this->assertStringContainsString('✅', $result['status']); $this->assertArrayHasKey('content', $result); $this->assertNotEmpty($result['content']); $this->assertEquals($firstSection, $result['metadata']['section']); } } public function testFindSimilarDocumentation(): void { // Test similarity search using the index directly $results = $this->index->searchChunks('create store', null, 3); if (0 < count($results)) { $this->assertNotEmpty($results); $firstResult = $results[0]; $this->assertArrayHasKey('score', $firstResult); $this->assertArrayHasKey('chunk_id', $firstResult); $this->assertArrayHasKey('preview', $firstResult); } else { // It's okay if we don't find similar content $this->assertTrue(true, 'Similarity search completed'); } } public function testGeneralDocumentationExists(): void { // Test authoring guide $authoringOverview = $this->index->getSdkOverview('authoring'); $this->assertNotNull($authoringOverview); $this->assertEquals('Model Authoring Guide', $authoringOverview['name']); // Test general OpenFGA docs $generalOverview = $this->index->getSdkOverview('general'); $this->assertNotNull($generalOverview); $this->assertEquals('OpenFGA Documentation', $generalOverview['name']); } public function testGetClassDocumentationForPhpSdk(): void { // First get PHP SDK overview to find a class $phpOverview = $this->index->getSdkOverview('php'); $this->assertNotEmpty($phpOverview['classes']); // Get the first available class $className = $phpOverview['classes'][0]; $result = $this->resources->getClassDocumentation('php', $className); if (str_contains($result['status'], '✅')) { $this->assertStringContainsString('✅', $result['status']); $this->assertArrayHasKey('content', $result); $this->assertNotEmpty($result['content']); $this->assertEquals($className, $result['metadata']['class']); $this->assertEquals('php', $result['metadata']['sdk']); } } public function testGetPhpSdkSpecificContent(): void { $result = $this->resources->getSdkDocumentation('php'); $this->assertStringContainsString('✅', $result['status']); $this->assertEquals('php', $result['sdk']); $this->assertEquals('PHP SDK', $result['name']); $this->assertNotEmpty($result['sections']); $this->assertNotEmpty($result['classes']); // PHP SDK should have many classes $this->assertGreaterThan(10, $result['classes']); } public function testGoSdkDocumentationContent(): void { $goOverview = $this->index->getSdkOverview('go'); $this->assertNotNull($goOverview); $this->assertEquals('go', $goOverview['sdk']); $this->assertEquals('GO SDK', $goOverview['name']); $this->assertGreaterThan(0, $goOverview['total_chunks']); $this->assertNotEmpty($goOverview['sections']); } public function testLaravelSdkDocumentationExists(): void { $laravelOverview = $this->index->getSdkOverview('laravel'); $this->assertNotNull($laravelOverview); $this->assertEquals('laravel', $laravelOverview['sdk']); $this->assertEquals('LARAVEL SDK', $laravelOverview['name']); $this->assertGreaterThan(0, $laravelOverview['total_chunks']); // Laravel SDK is one of the larger documentation files $this->assertGreaterThan(30, $laravelOverview['total_chunks']); } public function testMemoryUsageIsReasonable(): void { $memoryBefore = memory_get_usage(true); // Initialize and perform several operations $index = new DocumentationIndex; $index->initialize(); // Search operations $index->searchChunks('test', null, 50); $index->getSdkOverview('php'); $index->getSdkOverview('laravel'); $memoryAfter = memory_get_usage(true); $memoryUsed = ($memoryAfter - $memoryBefore) / 1024 / 1024; // Convert to MB // Memory usage should be reasonable (less than 100MB for documentation) $this->assertLessThan(100, $memoryUsed, 'Documentation system should use less than 100MB of memory'); } public function testPhpSdkDocumentationContent(): void { $phpOverview = $this->index->getSdkOverview('php'); $this->assertNotNull($phpOverview); $this->assertEquals('php', $phpOverview['sdk']); $this->assertEquals('PHP SDK', $phpOverview['name']); $this->assertGreaterThan(0, $phpOverview['total_chunks']); $this->assertNotEmpty($phpOverview['sections']); $this->assertNotEmpty($phpOverview['classes']); // PHP SDK should have source and generated metadata $this->assertStringContainsString('github.com', $phpOverview['source'] ?? ''); $this->assertNotNull($phpOverview['generated']); } public function testSearchAcrossMultipleSdks(): void { // Search for a common concept across SDKs $results = $this->index->searchChunks('check', null, 20); $this->assertNotEmpty($results); // Collect unique SDKs from results $sdksFound = array_unique(array_column($results, 'sdk')); // Should find results from multiple SDKs $this->assertGreaterThan(1, count($sdksFound)); } public function testSearchCodeExamplesFindsRealExamples(): void { // Search for content that likely contains code examples $results = $this->index->searchChunks('new', null, 10); $this->assertNotEmpty($results); // Check if any results contain code-like patterns $foundCodePattern = false; foreach ($results as $result) { $chunk = $this->index->getChunk($result['chunk_id']); if ($chunk && str_contains($chunk['content'], '```')) { $foundCodePattern = true; break; } } // It's okay if we don't find code blocks in every test $this->assertTrue(true, 'Test completed'); } public function testSearchDocumentationToolFindsRealContent(): void { // Use the index directly instead of the tool to avoid CallToolRequest dependency $results = $this->index->searchChunks('createStore', null, 5); $this->assertNotEmpty($results); // Verify we found actual createStore content $foundCreateStore = false; foreach ($results as $searchResult) { if (false !== stripos($searchResult['preview'], 'createStore')) { $foundCreateStore = true; break; } } $this->assertTrue($foundCreateStore, 'Should find createStore in documentation'); } public function testSearchFindsAuthenticationContent(): void { $results = $this->index->searchChunks('authentication', null, 10); $this->assertNotEmpty($results); $this->assertGreaterThan(0, count($results)); // Verify search results have expected structure $firstResult = $results[0]; $this->assertArrayHasKey('chunk_id', $firstResult); $this->assertArrayHasKey('sdk', $firstResult); $this->assertArrayHasKey('score', $firstResult); $this->assertArrayHasKey('preview', $firstResult); $this->assertArrayHasKey('metadata', $firstResult); // Preview should contain authentication-related content $this->assertStringContainsStringIgnoringCase('auth', $firstResult['preview']); } public function testSearchForSpecificSdkMethods(): void { // Search for PHP SDK specific content $results = $this->index->searchChunks('listStores', 'php', 5); if (0 < count($results)) { $this->assertNotEmpty($results); // All results should be from PHP SDK foreach ($results as $searchResult) { $this->assertEquals('php', $searchResult['sdk']); } } else { // It's okay if the specific method isn't found $this->assertTrue(true, 'Method search completed'); } } }

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/evansims/openfga-mcp'

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