Skip to content

Commit c84322f

Browse files
chore: use a more explicit install command in docs to force latest version
[skip ci]
1 parent 840aa66 commit c84322f

File tree

10 files changed

+201
-5
lines changed

10 files changed

+201
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ This package supports the **2025-03-26** version of the Model Context Protocol.
3535
Install the package via Composer:
3636

3737
```bash
38-
composer require php-mcp/laravel
38+
composer require php-mcp/laravel:^3.0 -W
3939
```
4040

4141
Publish the configuration file:

samples/basic/app/Models/User.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
use Illuminate\Database\Eloquent\Factories\HasFactory;
77
use Illuminate\Foundation\Auth\User as Authenticatable;
88
use Illuminate\Notifications\Notifiable;
9+
use Laravel\Sanctum\HasApiTokens;
910

1011
class User extends Authenticatable
1112
{
1213
/** @use HasFactory<\Database\Factories\UserFactory> */
13-
use HasFactory, Notifiable;
14+
use HasFactory, Notifiable, HasApiTokens;
1415

1516
/**
1617
* The attributes that are mass assignable.

samples/basic/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"require": {
1212
"php": "^8.2",
1313
"laravel/framework": "^12.0",
14+
"laravel/sanctum": "^4.0",
1415
"laravel/tinker": "^2.10.1",
1516
"php-mcp/laravel": "dev-main"
1617
},

samples/basic/composer.lock

Lines changed: 66 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/basic/config/mcp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
'legacy' => (bool) env('MCP_HTTP_INTEGRATED_LEGACY', false),
9696
'route_prefix' => env('MCP_HTTP_INTEGRATED_ROUTE_PREFIX', 'mcp'),
9797
'stateless' => (bool) env('MCP_HTTP_INTEGRATED_STATELESS', true),
98-
'middleware' => explode(',', env('MCP_HTTP_INTEGRATED_MIDDLEWARE', 'api')),
98+
'middleware' => ['api', 'auth:sanctum'],
9999
'domain' => env('MCP_HTTP_INTEGRATED_DOMAIN'),
100100
'sse_poll_interval' => (int) env('MCP_HTTP_INTEGRATED_SSE_POLL_SECONDS', 1),
101101
'cors_origin' => env('MCP_HTTP_INTEGRATED_CORS_ORIGIN', '*'),

samples/basic/config/sanctum.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
use Laravel\Sanctum\Sanctum;
4+
5+
return [
6+
7+
/*
8+
|--------------------------------------------------------------------------
9+
| Stateful Domains
10+
|--------------------------------------------------------------------------
11+
|
12+
| Requests from the following domains / hosts will receive stateful API
13+
| authentication cookies. Typically, these should include your local
14+
| and production domains which access your API via a frontend SPA.
15+
|
16+
*/
17+
18+
'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf(
19+
'%s%s',
20+
'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1',
21+
Sanctum::currentApplicationUrlWithPort(),
22+
// Sanctum::currentRequestHost(),
23+
))),
24+
25+
/*
26+
|--------------------------------------------------------------------------
27+
| Sanctum Guards
28+
|--------------------------------------------------------------------------
29+
|
30+
| This array contains the authentication guards that will be checked when
31+
| Sanctum is trying to authenticate a request. If none of these guards
32+
| are able to authenticate the request, Sanctum will use the bearer
33+
| token that's present on an incoming request for authentication.
34+
|
35+
*/
36+
37+
'guard' => ['web'],
38+
39+
/*
40+
|--------------------------------------------------------------------------
41+
| Expiration Minutes
42+
|--------------------------------------------------------------------------
43+
|
44+
| This value controls the number of minutes until an issued token will be
45+
| considered expired. This will override any values set in the token's
46+
| "expires_at" attribute, but first-party sessions are not affected.
47+
|
48+
*/
49+
50+
'expiration' => null,
51+
52+
/*
53+
|--------------------------------------------------------------------------
54+
| Token Prefix
55+
|--------------------------------------------------------------------------
56+
|
57+
| Sanctum can prefix new tokens in order to take advantage of numerous
58+
| security scanning initiatives maintained by open source platforms
59+
| that notify developers if they commit tokens into repositories.
60+
|
61+
| See: https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning
62+
|
63+
*/
64+
65+
'token_prefix' => env('SANCTUM_TOKEN_PREFIX', ''),
66+
67+
/*
68+
|--------------------------------------------------------------------------
69+
| Sanctum Middleware
70+
|--------------------------------------------------------------------------
71+
|
72+
| When authenticating your first-party SPA with Sanctum you may need to
73+
| customize some of the middleware Sanctum uses while processing the
74+
| request. You may change the middleware listed below as required.
75+
|
76+
*/
77+
78+
'middleware' => [
79+
'authenticate_session' => Laravel\Sanctum\Http\Middleware\AuthenticateSession::class,
80+
'encrypt_cookies' => Illuminate\Cookie\Middleware\EncryptCookies::class,
81+
'validate_csrf_token' => Illuminate\Foundation\Http\Middleware\ValidateCsrfToken::class,
82+
],
83+
84+
];
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('personal_access_tokens', function (Blueprint $table) {
15+
$table->id();
16+
$table->morphs('tokenable');
17+
$table->text('name');
18+
$table->string('token', 64)->unique();
19+
$table->text('abilities')->nullable();
20+
$table->timestamp('last_used_at')->nullable();
21+
$table->timestamp('expires_at')->nullable()->index();
22+
$table->timestamps();
23+
});
24+
}
25+
26+
/**
27+
* Reverse the migrations.
28+
*/
29+
public function down(): void
30+
{
31+
Schema::dropIfExists('personal_access_tokens');
32+
}
33+
};

samples/basic/dump.rdb

1.12 KB
Binary file not shown.

samples/basic/routes/api.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
use Illuminate\Http\Request;
4+
use Illuminate\Support\Facades\Route;
5+
6+
Route::get('/user', function (Request $request) {
7+
return $request->user();
8+
})->middleware('auth:sanctum');

samples/basic/routes/mcp.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
use App\Mcp\GetArticleContent;
66
use App\Mcp\GetAppVersion;
77
use PhpMcp\Laravel\Facades\Mcp;
8+
use Illuminate\Support\Facades\Auth;
89

910
Mcp::tool('welcome_message', GenerateWelcomeMessage::class);
1011

1112
Mcp::resource('app://version', GetAppVersion::class)
1213
->name('laravel_app_version')
1314
->mimeType('text/plain');
1415

16+
Mcp::tool('get_me', function () {
17+
return Auth::user();
18+
});
19+
1520
Mcp::resourceTemplate('content://articles/{articleId}', GetArticleContent::class)
1621
->name('article_content')
1722
->mimeType('application/json');

0 commit comments

Comments
 (0)