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:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Guides;
|
||||
|
||||
use LIT\MCP\Integrations\Integration;
|
||||
use LIT\MCP\Integrations\IntegrationRegistry;
|
||||
|
||||
/**
|
||||
* Builds the short server instructions every MCP client loads on connect.
|
||||
* Keep this text short: it occupies context in every conversation.
|
||||
*/
|
||||
final class InstructionsBuilder
|
||||
{
|
||||
public function __construct(private IntegrationRegistry $registry)
|
||||
{
|
||||
}
|
||||
|
||||
public function build(): string
|
||||
{
|
||||
$active = implode(', ', array_map(
|
||||
static fn (Integration $integration): string => $integration->id(),
|
||||
$this->registry->available()
|
||||
));
|
||||
|
||||
return implode("\n", [
|
||||
'LIT MCP pflegt diese WordPress-Website (Inhalte, Medien, Divi 5, Pods).',
|
||||
'Aktive Integrationen: ' . $active . '.',
|
||||
'Regeln:',
|
||||
'- Vor dem ersten Arbeitsschritt lit-guide (ohne Topic) aufrufen; Details je Thema über lit-guide '
|
||||
. 'mit topic.',
|
||||
'- Änderungen erzeugen native Divi-Module; Variablen und Presets vor festen Werten; Code-Modul nur, '
|
||||
. 'wenn kein natives Modul passt.',
|
||||
'- Den Status (Entwurf/veröffentlicht) nie ändern, außer der Nutzer verlangt es ausdrücklich.',
|
||||
'- Schreib-Tools verlangen den aktuellen rev-Wert aus dem letzten Lesevorgang.',
|
||||
'- Fehler enthalten einen hint – ihm folgen, statt blind zu wiederholen.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user