Additive-only — no existing files modified. - McpApiKeyAuth: validates Bearer or X-MCP-API-Key header, attaches workspace context - CheckMcpQuota: consumes via McpQuotaService, exposes MCP quota headers - ValidateWorkspaceContext: normalises + enforces authenticated workspace scope - ValidateToolDependencies: JSON-RPC + flat tool-call payload validation via ToolDependencyService - McpAuthenticate: combined auth gate chaining the full stack Pest Feature tests _Good/_Bad/_Ugly per AX-10 for each middleware. pest skipped (vendor binaries missing in sandbox). Co-authored-by: Codex <noreply@openai.com> Closes tasks.lthn.sh/view.php?id=852
38 lines
1.2 KiB
PHP
38 lines
1.2 KiB
PHP
<?php
|
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Core\Mod\Agentic\Website\Mcp\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class McpAuthenticate
|
|
{
|
|
public function __construct(
|
|
protected McpApiKeyAuth $apiKeyAuth,
|
|
protected CheckMcpQuota $checkMcpQuota,
|
|
protected ValidateWorkspaceContext $validateWorkspaceContext,
|
|
protected ValidateToolDependencies $validateToolDependencies,
|
|
) {}
|
|
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
return $this->apiKeyAuth->handle(
|
|
$request,
|
|
fn (Request $authenticatedRequest): Response => $this->checkMcpQuota->handle(
|
|
$authenticatedRequest,
|
|
fn (Request $quotaCheckedRequest): Response => $this->validateWorkspaceContext->handle(
|
|
$quotaCheckedRequest,
|
|
fn (Request $workspaceValidatedRequest): Response => $this->validateToolDependencies->handle(
|
|
$workspaceValidatedRequest,
|
|
$next,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|