45 lines
1.4 KiB
PHP
45 lines
1.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace App\Mcp\Tools\Post;
|
||
|
|
|
||
|
|
use App\Models\Post;
|
||
|
|
use App\Services\Post\PostPreviewer;
|
||
|
|
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
||
|
|
use Laravel\Mcp\Request;
|
||
|
|
use Laravel\Mcp\Response;
|
||
|
|
use Laravel\Mcp\ResponseFactory;
|
||
|
|
use Laravel\Mcp\Server\Attributes\Description;
|
||
|
|
use Laravel\Mcp\Server\Tool;
|
||
|
|
use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;
|
||
|
|
|
||
|
|
#[IsReadOnly]
|
||
|
|
#[Description('Preview how a post will render on each enabled platform — applies platform-specific content sanitization (length truncation, forbidden chars, etc.) without publishing. Returns the original content alongside per-platform sanitized versions and length stats.')]
|
||
|
|
class PreviewPostTool extends Tool
|
||
|
|
{
|
||
|
|
public function handle(Request $request): Response|ResponseFactory
|
||
|
|
{
|
||
|
|
$validated = $request->validate([
|
||
|
|
'post_id' => ['required', 'uuid'],
|
||
|
|
]);
|
||
|
|
|
||
|
|
$post = Post::where('workspace_id', $request->user()->current_workspace_id)
|
||
|
|
->with(['postPlatforms.socialAccount'])
|
||
|
|
->find(data_get($validated, 'post_id'));
|
||
|
|
|
||
|
|
if (! $post) {
|
||
|
|
return Response::error('Post not found.');
|
||
|
|
}
|
||
|
|
|
||
|
|
return Response::structured(app(PostPreviewer::class)->forPost($post));
|
||
|
|
}
|
||
|
|
|
||
|
|
public function schema(JsonSchema $schema): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'post_id' => $schema->string()->required()->description('UUID of the post to preview.'),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|