Clients

laravel-rust-mcp-oauth Alpha Laravel for Rust

Assistants identify themselves to your server in one of two ways, and the crate supports both, so the assistants people use today can connect.

Client ID Metadata Documents

The MCP specification's preferred way. The assistant's client_id is an HTTPS URL, such as https://claude.ai/oauth/mcp-oauth-client-metadata, that serves a JSON document with its name and callbacks. The crate fetches it, checks that the document names the same URL, and caches it for MCP_OAUTH_METADATA_CACHE_HOURS (24).

Anyone can start an authorization with any URL, so fetching is locked down:

  • HTTPS on port 443 only, without a user name or password in the URL;
  • the host must resolve to public addresses only, and the connection goes to an address that was checked, so DNS can't be switched in between;
  • local names such as localhost and *.internal are refused before any lookup;
  • no redirects, no proxy, no cookies, a 5-second timeout and at most 10 KB.

When a refresh fails temporarily (a timeout, a connection error or a 5xx), the server can use a cached copy that is still younger than MCP_OAUTH_METADATA_MAX_STALE_HOURS (7 days) at the point of fallback. A 4xx, an invalid document or a document that omits a callback registered before the fetch clears all cached callbacks. The server records this even on the first fetch and waits for MCP_OAUTH_METADATA_CACHE_HOURS to elapse before it can restore a registration with a successful fetch.

When two successful fetches overlap and one conflicts with the other’s write, the server keeps only callbacks that occur in both documents, using exact string matching and the stored order. It keeps the other stored metadata and starts a new cache period. If the lists share no callbacks, the server records an invalidation marker. An existing marker takes precedence over a fetch that started before the marker was written. A later refresh without a conflict can register new callbacks.

A 15-second cache lock reduces duplicate fetches. If another request holds the lock, the server uses a cached copy within the same stale limit or shows a temporarily_unavailable problem page. With the discard store, every request that needs a refresh fetches the document. The database enforces the same invalidation rules with any cache store.

Turn it off with MCP_OAUTH_CIMD=false.

Dynamic registration

Clients that don't publish a document register themselves with POST /oauth/register (RFC 7591) and get a client_id starting with mcp_c_. Turn it off with MCP_OAUTH_DCR=false; the registration endpoint then disappears from the metadata.

At most MCP_OAUTH_REGISTRATIONS_PER_HOUR registrations per address (30).

Public clients only

Every client is public (token_endpoint_auth_method: none) and proves itself with PKCE S256. A registration that asks for another method is answered as none.

Some published metadata documents declare private_key_jwt; this version doesn't support it. Those assistants connect through dynamic registration instead, as they do with other servers that accept only public clients.

Callbacks

A callback (redirect_uri) must be one of:

  • an HTTPS URL;
  • http://127.0.0.1, http://[::1] or http://localhost, on any port, for programs on the person's computer;
  • a private-use scheme, such as cursor://anysphere.cursor-retrieval/oauth/callback.

Refused: javascript:, data:, file: and similar schemes, plain HTTP to other hosts, fragments, user names in the URL, .. segments, encoded slashes, ports that aren't numbers, and a query that already carries code, state, iss or error. A callback must match a registered one exactly; a loopback callback may differ only in its port.

Known clients

The crate recognises Claude, Claude Code, ChatGPT, Codex, Cursor, VS Code, Gemini CLI and MCP Inspector, and shows them as verified on the approval page when the evidence holds (see The approval page). Add your own:

use laravel_rust_mcp_oauth::KnownClient;

McpOAuthServiceProvider::<model::Users<User>>::new()
    .known_client(KnownClient::cimd("https://assistant.example/oauth/client.json", "Example Assistant"))
    .known_client(
        KnownClient::redirect_based("Other Assistant", "other")
            .redirect("https://other.example/oauth/callback"),
    )

Verification requires a selected HTTPS callback tied to a known client. A known registration that uses a loopback or private-use callback appears as a local program and shows the claimed name.

The list mcp-oauth:clients prints shows every client that has registered or connected, with its grants and when it was last used.