Skip to content
LaravelBlog

laravel/mcp: OAuth transport limits rebuilt for Guzzle 8 compatibility

A Guzzle 8 compatibility fix for the OAuth client: native `protocols` and `progress` request options replace rejected cURL options, keeping HTTP/HTTPS restrictions and the 1 MB response cap intact on both Guzzle majors.

LaravelBlogBot
LaravelBlogBot , 4 mins read

Contributed by lazerg

Laravel MCP's OAuth client can complete its handshake again under Guzzle 8. In v1.2.0, every OAuth request — authorization server metadata discovery, dynamic client registration, token exchange, and token refresh — threw an exception before a single byte hit the wire when Guzzle 8 was installed, because Guzzle 8 rejects two cURL options the package used to constrain those requests. This release rebuilds those constraints using Guzzle's native request options on Guzzle 8, while leaving the existing cURL path untouched for Guzzle 7. The guarantees don't change: OAuth traffic is still restricted to HTTP and HTTPS, and responses are still capped at 1 MB.

What broke under Guzzle 8

Every outgoing OAuth request in the MCP client flows through a shared oAuthRequest() helper in InteractsWithOAuthEndpoints, which backs classes like AuthServerDiscovery and DynamicClientRegistration. To harden those requests against a misbehaving or malicious authorization server, the helper attached raw cURL options:

  • CURLOPT_PROTOCOLS — restrict transfers to CURLPROTO_HTTP | CURLPROTO_HTTPS
  • CURLOPT_MAXFILESIZE — abort responses larger than $this->maxOAuthResponseSize (1,048,576 bytes)

Both were passed through the Laravel HTTP client's withOptions(['curl' => ...]). Guzzle 8 takes a stricter stance on the curl escape hatch and refuses options that overlap with its own request options — and both of these are on that list. The rejection happens while assembling the request, so it fails before it is ever sent. Because every OAuth flow shares this helper, the entire client-side OAuth handshake was dead on Guzzle 8.

Version-aware transport options

The fix renames the internal helper oAuthCurlOptions() to oAuthTransportOptions() and branches on the installed Guzzle major version:

if (ClientInterface::MAJOR_VERSION >= 8) {
    return [
        'protocols' => ['http', 'https'],
        'progress' => fn (int $downloadTotal, int $downloaded): bool
            => max($downloadTotal, $downloaded) > $this->maxOAuthResponseSize,
    ];
}

return ['curl' => [
    CURLOPT_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS,
    CURLOPT_MAXFILESIZE => $this->maxOAuthResponseSize,
]];

On Guzzle 7, the returned options are identical to v1.2.0. On Guzzle 8 and newer, the curl bag is gone entirely: protocols is Guzzle's first-class request option for the same restriction, and the size cap moves to a progress callback. The guard for environments without the cURL constants (! defined('CURLOPT_PROTOCOLS')) is unchanged.

The 1 MB cap as a progress callback

Guzzle has no request option that maps to CURLOPT_MAXFILESIZE, so the cap is enforced by watching progress ticks. Guzzle invokes the progress callback as the transfer proceeds (the closure ignores Guzzle's upload counters); returning a truthy value aborts the transfer, which is exactly what the new closure does once either the advertised total or the received byte count passes the limit.

Using max() of the two counters covers both failure modes: a server advertising a huge Content-Length is cut off immediately, and one that quietly streams past the cap is cut off mid-transfer. Exactly 1 MB still succeeds; 1,048,577 bytes does not. The pull request author verified both Guzzle paths against a local server: small responses arrive intact, and a 2 MB response aborts.

Version-aware tests and static analysis

Because the correct assertions differ per Guzzle major version, the test suite is now version-aware. The two existing tests asserting on CURLOPT_PROTOCOLS and CURLOPT_MAXFILESIZE are skipped on Guzzle 8 (where those options are rejected), and a new Guzzle-8-only test asserts the opposite: no curl key in the options, protocols set to ['http', 'https'], and the progress callback returning false at exactly 1,048,576 bytes and true from 1,048,577 — whether that byte shows up as the declared total or as downloaded bytes.

Static analysis got a small companion change too: GuzzleHttp\ClientInterface::MAJOR_VERSION is registered as a dynamic constant name in phpstan.neon.dist, so PHPStan analyzes both the Guzzle 7 and Guzzle 8 branches instead of assuming one fixed version.

Upgrading from v1.2.0

For most apps this is a drop-in patch: run composer update and move on. There is no new configuration, no dependency requirement changes, and Guzzle 7 users keep the exact same code path as before.

Two notes worth checking:

  • Guzzle 8 users get working OAuth again. Discovery, registration, token exchange, and refresh now run instead of throwing. The protocol restriction and the 1 MB cap are still enforced, just through native request options.
  • Subclassers: one method was renamed. If you extended the OAuth internals and overrode oAuthCurlOptions(), override oAuthTransportOptions() instead. Its return type broadened from raw cURL options to array<string, mixed>, so returning Guzzle request options is now valid.

Takeaways

  • Fixes the Guzzle 8 hard failure where every OAuth request threw before being sent.
  • Guzzle 8 now uses native protocols and progress request options; Guzzle 7 keeps the original cURL options unchanged.
  • Security limits are preserved on both versions: HTTP/HTTPS only, responses capped at 1 MB, aborted mid-transfer once exceeded.
  • The internal rename from oAuthCurlOptions() to oAuthTransportOptions() only matters if you override it in a subclass.
  • No configuration or dependency changes needed — just update the package.

Sources

Related Articles