feat: guide tool and server instructions

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
2026-09-25 15:32:26 +02:00
co-authored by Claude Opus 5.5
parent 3b7fabf17a
commit b54d55e5e1
9 changed files with 348 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
# Divi-Kurzform
Testinhalt Kurzform.
+2
View File
@@ -0,0 +1,2 @@
# Übersicht
Testinhalt Übersicht.
+55
View File
@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Guides;
use LIT\MCP\Guides\GuideRepository;
use LIT\MCP\Tests\Unit\TestCase;
final class GuideRepositoryTest extends TestCase
{
private GuideRepository $guides;
protected function setUp(): void
{
parent::setUp();
$this->guides = new GuideRepository(dirname(__DIR__, 2) . '/Fixtures/guides');
}
public function testListsTopicsSortedWithoutExtension(): void
{
self::assertSame(['divi-shortform', 'overview'], $this->guides->topics());
}
public function testReturnsMarkdownOfKnownTopic(): void
{
self::assertStringContainsString('Testinhalt Kurzform', (string) $this->guides->get('divi-shortform'));
}
/**
* @dataProvider maliciousTopics
*/
public function testRejectsAnythingThatIsNotAPlainTopicName(string $topic): void
{
self::assertNull($this->guides->get($topic));
}
/** @return array<string, array{string}> */
public static function maliciousTopics(): array
{
return [
'traversal' => ['../../wp-config'],
'with extension' => ['overview.md'],
'empty' => [''],
'absolute' => ['/etc/passwd'],
'unknown' => ['does-not-exist'],
'uppercase' => ['OVERVIEW'],
];
}
public function testMissingDirectoryYieldsNoTopics(): void
{
self::assertSame([], (new GuideRepository('/nonexistent/dir'))->topics());
}
}
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Guides;
use LIT\MCP\Guides\InstructionsBuilder;
use LIT\MCP\Integrations\Integration;
use LIT\MCP\Integrations\IntegrationRegistry;
use LIT\MCP\Tests\Unit\TestCase;
use Mockery;
final class InstructionsBuilderTest extends TestCase
{
public function testNamesActiveIntegrationsAndCoreRules(): void
{
$core = Mockery::mock(Integration::class);
$core->allows('id')->andReturn('core');
$core->allows('isAvailable')->andReturn(true);
$text = (new InstructionsBuilder(new IntegrationRegistry($core)))->build();
self::assertStringContainsString('Aktive Integrationen: core', $text);
self::assertStringContainsString('lit-guide', $text);
self::assertStringContainsString('Status', $text);
self::assertLessThan(2000, strlen($text), 'Instructions must stay short – they are loaded in every conversation.');
}
}
@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Integrations\Core;
use LIT\MCP\Guides\GuideRepository;
use LIT\MCP\Integrations\Core\GuideAbility;
use LIT\MCP\Tests\Unit\TestCase;
use WP_Error;
final class GuideAbilityTest extends TestCase
{
private GuideAbility $ability;
protected function setUp(): void
{
parent::setUp();
$this->ability = new GuideAbility(new GuideRepository(dirname(__DIR__, 3) . '/Fixtures/guides'));
}
public function testWithoutTopicReturnsOverviewAndTopicList(): void
{
$result = $this->ability->execute([]);
self::assertSame('overview', $result['topic']);
self::assertSame(['divi-shortform', 'overview'], $result['topics']);
self::assertStringContainsString('Testinhalt Übersicht', $result['content']);
}
public function testReturnsRequestedTopic(): void
{
$result = $this->ability->execute(['topic' => 'divi-shortform']);
self::assertStringContainsString('Testinhalt Kurzform', $result['content']);
}
public function testUnknownTopicIsNotFoundErrorListingTopics(): void
{
$result = $this->ability->execute(['topic' => '../../wp-config']);
self::assertInstanceOf(WP_Error::class, $result);
self::assertSame('lit_not_found', $result->get_error_code());
self::assertStringContainsString('divi-shortform', $result->get_error_message());
}
public function testIsDirectReadOnlyTool(): void
{
self::assertSame('lit/guide', $this->ability->name());
self::assertTrue($this->ability->isDirect());
self::assertTrue($this->ability->annotations()['readonly']);
}
}