Skip to content

SharedSecretMiddleware

Rasuvaeff\Yii3Mcp\SharedSecretMiddleware

ClassRasuvaeff\Yii3McpSource

Fail-closed shared-secret guard for the MCP endpoint: requests without a valid header value are rejected with 401. An unconfigured middleware (empty secret, no resolver) rejects every request with a clear 503 explanation — an unprotected endpoint must be an explicit decision (network ACL), never a silent default.

A SecretResolverInterface enables several clients and secret rotation; the resolved client id travels down the pipeline as the self::CLIENT_ID_ATTRIBUTE request attribute (the raw secret does not). The single $secret form stays as the backward-compatible adapter — it behaves as one client named self::DEFAULT_CLIENT_ID.

Methods

process()

php
process(
    Psr\Http\Message\ServerRequestInterface $request,
    Psr\Http\Server\RequestHandlerInterface $handler,
): Psr\Http\Message\ResponseInterface