Skip to content

feat: Upgrade to php-mcp/server ^3.x with enhanced session management and streamable transport #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
987 changes: 773 additions & 214 deletions README.md

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
{
"name": "php-mcp/laravel",
"description": "The official Laravel integration for the PHP MCP Server package.",
"description": "Laravel SDK for building Model Context Protocol (MCP) servers - Seamlessly integrate MCP tools, resources, and prompts into Laravel applications",
"keywords": [
"laravel",
"mcp",
"model-context-protocol",
"ai",
"llm",
"tools"
"tools",
"laravel mcp",
"laravel mcp sdk",
"laravel mcp server",
"laravel mcp tools",
"laravel mcp resources",
"laravel mcp prompts",
"laravel model context protocol"
],
"homepage": "https://github.com/php-mcp/laravel",
"license": "MIT",
Expand All @@ -21,7 +28,7 @@
"require": {
"php": "^8.1",
"laravel/framework": "^9.46 || ^10.34 || ^11.29 || ^12.0",
"php-mcp/server": "^2.3"
"php-mcp/server": "^3.1"
},
"require-dev": {
"laravel/pint": "^1.13",
Expand Down Expand Up @@ -62,4 +69,4 @@
},
"minimum-stability": "dev",
"prefer-stable": true
}
}
95 changes: 70 additions & 25 deletions config/mcp.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,28 @@
| MCP Cache Configuration
|--------------------------------------------------------------------------
|
| Configure how the MCP server caches discovered elements and transport
| state using Laravel's cache system. You can specify which store to use
| and how long items should be cached.
| Configure how the MCP server caches discovered elements using Laravel's cache system.
| You can specify which store to use and how long items should be cached.
|
*/
'cache' => [
'store' => env('MCP_CACHE_STORE', config('cache.default')),
'ttl' => env('MCP_CACHE_TTL', 3600),
],

/*
|--------------------------------------------------------------------------
| MCP Transport Configuration
|--------------------------------------------------------------------------
|
| Configure the available transports for MCP communication. Three types are
| supported: stdio for CLI clients, http_dedicated for a standalone server,
| and http_integrated for serving through Laravel's routing system.
| Configure the available transports for MCP communication.
|
| Supported Transports:
| - `stdio`: for CLI clients.
| - `http_dedicated`: for a standalone server running on a process.
| - `http_integrated`: for serving through Laravel's routing system.
|
| The 'legacy' option is used to enable the deprecated HTTP+SSE transport.
| It is not recommended to use this option.
*/
'transports' => [
'stdio' => [
Expand All @@ -80,21 +83,56 @@

'http_dedicated' => [
'enabled' => (bool) env('MCP_HTTP_DEDICATED_ENABLED', true),
'legacy' => (bool) env('MCP_HTTP_DEDICATED_LEGACY', false),
'host' => env('MCP_HTTP_DEDICATED_HOST', '127.0.0.1'),
'port' => (int) env('MCP_HTTP_DEDICATED_PORT', 8090),
'path_prefix' => env('MCP_HTTP_DEDICATED_PATH_PREFIX', 'mcp'),
'ssl_context_options' => [],
'enable_json_response' => (bool) env('MCP_HTTP_DEDICATED_JSON_RESPONSE', true),
'event_store' => null, // FQCN or null
],

'http_integrated' => [
'enabled' => (bool) env('MCP_HTTP_INTEGRATED_ENABLED', true),
'legacy' => (bool) env('MCP_HTTP_INTEGRATED_LEGACY', false),
'route_prefix' => env('MCP_HTTP_INTEGRATED_ROUTE_PREFIX', 'mcp'),
'middleware' => explode(',', env('MCP_HTTP_INTEGRATED_MIDDLEWARE', 'web')),
'middleware' => ['api'],
'domain' => env('MCP_HTTP_INTEGRATED_DOMAIN'),
'sse_poll_interval' => (int) env('MCP_HTTP_INTEGRATED_SSE_POLL_SECONDS', 1),
'cors_origin' => env('MCP_HTTP_INTEGRATED_CORS_ORIGIN', '*'),
'enable_json_response' => (bool) env('MCP_HTTP_INTEGRATED_JSON_RESPONSE', true),
'event_store' => null, // FQCN or null
],
],

/*
|--------------------------------------------------------------------------
| Session Management Configuration
|--------------------------------------------------------------------------
|
| Configure how the MCP server manages client sessions. Sessions store
| client state, message queues, and subscriptions. Supports Laravel's
| native session drivers for seamless integration.
|
*/
'session' => [
'driver' => env('MCP_SESSION_DRIVER', 'cache'), // 'file', 'cache', 'database', 'redis', 'memcached', 'dynamodb', 'array'
'ttl' => (int) env('MCP_SESSION_TTL', 3600),

// For cache-based drivers (redis, memcached, etc.)
'store' => env('MCP_SESSION_CACHE_STORE', config('cache.default')),

// For file driver
'path' => env('MCP_SESSION_FILE_PATH', storage_path('framework/mcp_sessions')),

// For database driver
'connection' => env('MCP_SESSION_DB_CONNECTION', config('database.default')),
'table' => env('MCP_SESSION_DB_TABLE', 'mcp_sessions'),

// Session garbage collection probability. 2% chance that garbage collection will run on any given session operation.
'lottery' => [2, 100],
],

/*
|--------------------------------------------------------------------------
| Pagination Limit
Expand All @@ -115,28 +153,35 @@
| support for tools, resources, prompts, and their related functionality like
| subscriptions and change notifications.
|
| The following capabilities are supported:
| - tools - Whether the server offers tools.
| - toolsListChanged - Whether the server supports sending a notification when the list of tools changes.
| - resources - Whether the server offers resources.
| - resourcesSubscribe - Whether the server supports resource subscriptions.
| - resourcesListChanged - Whether the server supports sending a notification when the list of resources changes.
| - prompts - Whether the server offers prompts.
| - promptsListChanged - Whether the server supports sending a notification when the list of prompts changes.
| - logging - Whether the server supports sending log messages to the client.
| - completions - Whether the server supports argument autocompletion suggestions.
| - experimental - Experimental, non-standard capabilities that the server supports.
|
*/
'capabilities' => [
'tools' => [
'enabled' => (bool) env('MCP_CAP_TOOLS_ENABLED', true),
'listChanged' => (bool) env('MCP_CAP_TOOLS_LIST_CHANGED', true),
],
'tools' => (bool) env('MCP_CAP_TOOLS_ENABLED', true),
'toolsListChanged' => (bool) env('MCP_CAP_TOOLS_LIST_CHANGED', true),

'resources' => [
'enabled' => (bool) env('MCP_CAP_RESOURCES_ENABLED', true),
'subscribe' => (bool) env('MCP_CAP_RESOURCES_SUBSCRIBE', true),
'listChanged' => (bool) env('MCP_CAP_RESOURCES_LIST_CHANGED', true),
],
'resources' => (bool) env('MCP_CAP_RESOURCES_ENABLED', true),
'resourcesSubscribe' => (bool) env('MCP_CAP_RESOURCES_SUBSCRIBE', true),
'resourcesListChanged' => (bool) env('MCP_CAP_RESOURCES_LIST_CHANGED', true),

'prompts' => [
'enabled' => (bool) env('MCP_CAP_PROMPTS_ENABLED', true),
'listChanged' => (bool) env('MCP_CAP_PROMPTS_LIST_CHANGED', true),
],
'prompts' => (bool) env('MCP_CAP_PROMPTS_ENABLED', true),
'promptsListChanged' => (bool) env('MCP_CAP_PROMPTS_LIST_CHANGED', true),

'logging' => [
'enabled' => (bool) env('MCP_CAP_LOGGING_ENABLED', true),
'setLevel' => (bool) env('MCP_CAP_LOGGING_SET_LEVEL', false),
],
'logging' => (bool) env('MCP_CAP_LOGGING_ENABLED', true),

'completions' => (bool) env('MCP_CAP_COMPLETIONS_ENABLED', true),

'experimental' => null,
],

/*
Expand Down
28 changes: 28 additions & 0 deletions database/migrations/create_mcp_sessions_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('mcp_sessions', function (Blueprint $table) {
$table->string('id')->primary();
$table->longText('payload');
$table->integer('last_activity')->index();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('mcp_sessions');
}
};
25 changes: 0 additions & 25 deletions routes/mcp_http_integrated.php

This file was deleted.

22 changes: 22 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Illuminate\Support\Facades\Route;
use PhpMcp\Laravel\Http\Controllers\StreamableTransportController;
use PhpMcp\Laravel\Http\Controllers\SseTransportController;

if (config('mcp.transports.http_integrated.legacy', false)) {
Route::get('/sse', [SseTransportController::class, 'handleSse'])
->name('mcp.sse');

Route::post('/message', [SseTransportController::class, 'handleMessage'])
->name('mcp.message');
} else {
Route::get('/', [StreamableTransportController::class, 'handleGet'])
->name('mcp.streamable.get');

Route::post('/', [StreamableTransportController::class, 'handlePost'])
->name('mcp.streamable.post');

Route::delete('/', [StreamableTransportController::class, 'handleDelete'])
->name('mcp.streamable.delete');
}
6 changes: 3 additions & 3 deletions samples/basic/bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
web: __DIR__ . '/../routes/web.php',
commands: __DIR__ . '/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
//
$middleware->validateCsrfTokens(except: [
'mcp',
'mcp/*',
]);
})
Expand Down
Loading