# Getting started (laravel-rust-mcp-oauth)

> This page adds the crate to a Laravel for Rust application and connects an AI assistant to its MCP route.

- Package: laravel-rust-mcp-oauth (Laravel for Rust, alpha), crates: `laravel-rust-mcp-oauth`
- Maintenance: active; Latest release: 0.1.0 (2026-12-05); Framework: laravel-rust 0.2.x; MSRV: Rust 1.99 or later; Licence: MIT
- Links: [Repository](https://github.com/bowerbird-si/laravel-rust-mcp-oauth), [crates.io](https://crates.io/crates/laravel-rust-mcp-oauth/0.1.0), [docs.rs](https://docs.rs/laravel-rust-mcp-oauth/0.1.0), [Changelog](https://oss.bowerbird.si/mcp-oauth/docs/changelog/), [Contributing](https://github.com/bowerbird-si/laravel-rust-mcp-oauth/blob/8b1d066397c9f1a1cf02d444a910a1c65585c159/CONTRIBUTING.md), [Security policy](https://github.com/bowerbird-si/laravel-rust-mcp-oauth/blob/8b1d066397c9f1a1cf02d444a910a1c65585c159/SECURITY.md)
- Based on: [Laravel MCP](https://github.com/laravel/mcp): The public flow of Mcp::oauthRoutes(): discovery, client registration, an approval screen in your app and bearer tokens for the MCP server.; [Laravel Passport](https://github.com/laravel/passport): The authorization server Laravel MCP builds on. This crate needs no Passport, supports Client ID Metadata Documents and uses opaque, hashed tokens instead of JWTs.; [MCP authorization specification](https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization): The sign-in flow MCP clients expect, with Client ID Metadata Documents preferred over dynamic registration.
- Community package, not affiliated with Laravel.
- HTML version: https://oss.bowerbird.si/mcp-oauth/docs/getting-started/
- Source: https://github.com/bowerbird-si/laravel-rust-mcp-oauth/blob/8b1d066397c9f1a1cf02d444a910a1c65585c159/docs/getting-started.md

This page adds the crate to a Laravel for Rust application and connects an AI assistant to its MCP route.

## Requirements

- Laravel for Rust 0.2 with a database (PostgreSQL, MySQL or SQLite).
- Session sign-in for your users: the approval page uses it.
- `APP_URL` set to your public HTTPS address. Outside the `local` and `testing` environments the crate refuses to start without HTTPS, because every URL it advertises is built from `APP_URL`.

## Install

```toml
[dependencies]
laravel-rust-mcp-oauth = "0.1"
```

The crate enables the PostgreSQL driver by default, because Laravel for Rust 0.2 doesn't compile its database layer without one (laravel/rust-framework#419). With MySQL or SQLite, pick your driver instead:

```toml
[dependencies]
laravel-rust-mcp-oauth = { version = "0.1", default-features = false, features = ["mysql"] } # or "sqlite"
```

Register the service provider with your user provider, the same one your session guard uses:

```rust
use laravel_rust_mcp_oauth::McpOAuthServiceProvider;

Application::configure()
    .with_providers(|providers| {
        providers.add(McpOAuthServiceProvider::<model::Users<User>>::new());
    })
    .with_auth(|auth, _| {
        auth.session::<model::Users<User>>();
    })
```

Create the tables:

```shellscript
laravel migrate
```

The provider adds the discovery documents, the OAuth endpoints under `/oauth`, the approval page, the `mcp-oauth:prune` and `mcp-oauth:clients` commands and a daily prune.

## Protect the MCP route

Put `McpAuthenticate` on any route handler or on a route serving `rmcp`. The middleware is designed for [Laravel's first-party MCP server](https://github.com/laravel/rust-framework/pull/321), which is unreleased, and compatibility is still unverified. The following example shows the intended usage once the server ships.

```rust
use laravel_rust_mcp_oauth::McpAuthenticate;

servers
    .web("/mcp", app_server)
    .middleware(McpAuthenticate::<User>::new().allow_guest_methods(["server/discover"]));
```

With your own handler:

```rust
route.middleware(McpAuthenticate::<User>::new()).group(|route| {
    route.any("/mcp", mcp_endpoint);
});
```

A request without a token now gets this answer, which is how assistants find your sign-in:

```http
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://app.example/.well-known/oauth-protected-resource/mcp", scope="mcp offline_access"
Cache-Control: no-store
```

The challenge offers the first configured scope (`mcp` by default) and `offline_access`. If you set `require_scopes` on a route, the challenge offers those scopes and `offline_access`.

## Connect an assistant

Add `https://app.example/mcp` as a custom connector or remote MCP server in your assistant. It opens your approval page in the browser. Log in if you aren't already, click **Connect**, and the assistant is connected.

To check from the command line, use the MCP Inspector:

```shellscript
npx @modelcontextprotocol/inspector
```

## Next

- [Protecting routes](https://oss.bowerbird.si/mcp-oauth/docs/protecting-routes/): scopes, guest methods and using the grant in tools.
- [The approval page](https://oss.bowerbird.si/mcp-oauth/docs/approval-page/): your own design, names and wording.
- [Configuration](https://oss.bowerbird.si/mcp-oauth/docs/configuration/): every setting.
