* Expose workspace webhooks through the API and MCP. The same create/update/test/rotate/replay/delete flow now lives in Actions so the web UI, REST API, and MCP tools stay in lockstep. * Keep webhook validation local to each web, API, and MCP entry point. * Extract MCP webhook rules into request classes and close remaining API/MCP review gaps. * Tighten webhook updates to a field whitelist and reset failures only on re-enable. * Treat a mismatched webhook replay as not found and mark secret rotation destructive.
38 lines
907 B
PHP
38 lines
907 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Mcp\Concerns;
|
|
|
|
use App\Models\Webhook;
|
|
use App\Models\WebhookLog;
|
|
use App\Models\Workspace;
|
|
use Laravel\Mcp\Response;
|
|
use Laravel\Mcp\ResponseFactory;
|
|
|
|
trait ResolvesWorkspaceWebhook
|
|
{
|
|
protected function webhookInWorkspace(Workspace $workspace, mixed $id): Webhook|Response|ResponseFactory
|
|
{
|
|
$webhook = Webhook::query()
|
|
->where('workspace_id', $workspace->id)
|
|
->find($id);
|
|
|
|
if (! $webhook instanceof Webhook) {
|
|
return Response::error('Webhook not found.');
|
|
}
|
|
|
|
return $webhook;
|
|
}
|
|
|
|
protected function webhookLogFor(Webhook $webhook, mixed $id): WebhookLog|Response|ResponseFactory
|
|
{
|
|
$log = $webhook->logs()->find($id);
|
|
|
|
if (! $log instanceof WebhookLog) {
|
|
return Response::error('Webhook log not found.');
|
|
}
|
|
|
|
return $log;
|
|
}
|
|
}
|