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
+51
View File
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace LIT\MCP\Guides;
/**
* Reads guide markdown files from one directory. Topic names are restricted to
* lowercase slugs, so no path outside the directory can ever be read.
*/
final class GuideRepository
{
private const TOPIC_PATTERN = '/^[a-z0-9]+(?:-[a-z0-9]+)*$/';
public function __construct(private string $directory)
{
}
/** @return list<string> */
public function topics(): array
{
$files = glob($this->directory . '/*.md');
if ($files === false) {
return [];
}
$topics = [];
foreach ($files as $file) {
$topic = basename($file, '.md');
if (preg_match(self::TOPIC_PATTERN, $topic) === 1) {
$topics[] = $topic;
}
}
sort($topics);
return $topics;
}
public function get(string $topic): ?string
{
if (preg_match(self::TOPIC_PATTERN, $topic) !== 1 || ! in_array($topic, $this->topics(), true)) {
return null;
}
$path = $this->directory . '/' . $topic . '.md';
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
$content = file_get_contents($path);
return $content === false ? null : $content;
}
}