Skip to content

Commit d125181

Browse files
refactor: Adapt to php-mcp/server v1.1.0 changes
1 parent dbc9787 commit d125181

File tree

5 files changed

+67
-87
lines changed

5 files changed

+67
-87
lines changed

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"require": {
2222
"php": "^8.1",
2323
"laravel/framework": "^9.46 || ^10.34 || ^11.29 || ^12.0",
24-
"php-mcp/server": "^1.0"
24+
"php-mcp/server": "^1.1.0"
2525
},
2626
"require-dev": {
2727
"laravel/pint": "^1.13",
@@ -30,8 +30,7 @@
3030
"pestphp/pest-plugin-laravel": "^2.0",
3131
"mockery/mockery": "^1.6",
3232
"phpunit/phpunit": "^10.0 || ^11.0",
33-
"react/http": "^1.11",
34-
"php-mcp/react-transport": "^0.1.0"
33+
"react/http": "^1.11"
3534
},
3635
"autoload": {
3736
"psr-4": {

samples/basic/composer.lock

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

src/Commands/ServeCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace PhpMcp\Laravel\Server\Commands;
66

77
use Illuminate\Console\Command;
8+
use PhpMcp\Server\Server;
89
use PhpMcp\Server\Transports\StdioTransportHandler;
910
use Psr\Log\LoggerInterface;
1011

@@ -30,14 +31,17 @@ class ServeCommand extends Command
3031
* The StdioTransportHandler's start() method contains the blocking loop
3132
* for reading STDIN and writing to STDOUT.
3233
*/
33-
public function handle(StdioTransportHandler $handler, LoggerInterface $logger): int
34+
public function handle(Server $server): int
3435
{
3536
if (! config('mcp.transports.stdio.enabled', false)) {
3637
$this->error('MCP STDIO transport is disabled. Cannot run mcp:serve.');
3738

3839
return Command::FAILURE;
3940
}
4041

42+
$handler = new StdioTransportHandler($server);
43+
$logger = app(LoggerInterface::class);
44+
4145
$logger->info('Starting MCP server via mcp:serve (STDIO)...');
4246
$this->info('MCP server starting via STDIO. Listening for requests...');
4347

src/Http/Controllers/McpController.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,28 @@
66

77
use Illuminate\Http\Request;
88
use Illuminate\Support\Str;
9-
use PhpMcp\Server\State\TransportState;
9+
use PhpMcp\Server\Server;
1010
use PhpMcp\Server\Transports\HttpTransportHandler;
1111
use Psr\Log\LoggerInterface;
1212
use Symfony\Component\HttpFoundation\Response;
1313
use Throwable;
1414

1515
class McpController
1616
{
17+
private HttpTransportHandler $handler;
18+
19+
private LoggerInterface $logger;
20+
1721
/**
1822
* MCP Controller Constructor
1923
*
2024
* Inject dependencies resolved by the service container.
2125
*/
22-
public function __construct(
23-
private readonly HttpTransportHandler $handler,
24-
private readonly TransportState $state,
25-
private readonly LoggerInterface $logger
26-
) {}
26+
public function __construct(Server $server)
27+
{
28+
$this->handler = new HttpTransportHandler($server);
29+
$this->logger = app(LoggerInterface::class);
30+
}
2731

2832
/**
2933
* Handle client message (HTTP POST endpoint).

src/McpServiceProvider.php

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515
use PhpMcp\Laravel\Server\Events\ResourcesListChanged;
1616
use PhpMcp\Laravel\Server\Events\ToolsListChanged;
1717
use PhpMcp\Laravel\Server\Listeners\McpNotificationListener;
18-
use PhpMcp\Server\Processor;
19-
use PhpMcp\Server\Registry;
18+
use PhpMcp\Server\Contracts\ConfigurationRepositoryInterface;
2019
use PhpMcp\Server\Server;
21-
use PhpMcp\Server\State\TransportState;
22-
use PhpMcp\Server\Transports\HttpTransportHandler;
23-
use PhpMcp\Server\Transports\StdioTransportHandler;
20+
use Psr\Log\LoggerInterface;
21+
use Psr\SimpleCache\CacheInterface;
2422

2523
class McpServiceProvider extends ServiceProvider
2624
{
@@ -46,51 +44,27 @@ public function register(): void
4644
$this->mergeConfigFrom(__DIR__.'/../config/mcp.php', 'mcp');
4745

4846
$this->app->singleton(Server::class, function (Application $app) {
49-
$config = $app['config'];
50-
51-
$mcpConfig = new ConfigAdapter($config);
52-
$cacheStore = $app['cache']->store($config->get('mcp.cache.store'));
53-
$logger = $app['log']->channel($config->get('mcp.logging.channel'));
54-
5547
$server = Server::make()
5648
->withContainer($app)
57-
->withConfig($mcpConfig)
5849
->withBasePath(base_path())
59-
->withLogger($logger)
60-
->withCache($cacheStore);
50+
->withScanDirectories($app['config']->get('mcp.discovery.directories', ['app/Mcp']));
6151

6252
if (! $this->app->environment('production')) {
6353
$server->discover();
6454
}
6555

66-
return $server;
67-
});
68-
69-
$this->app->bind(Processor::class, fn (Application $app) => $app->make(Server::class)->getProcessor());
70-
$this->app->bind(Registry::class, fn (Application $app) => $app->make(Server::class)->getRegistry());
71-
$this->app->bind(TransportState::class, fn (Application $app) => $app->make(Server::class)->getStateManager());
72-
73-
$this->app->bind(HttpTransportHandler::class, function (Application $app) {
74-
return new HttpTransportHandler(
75-
$app->make(Processor::class),
76-
$app->make(TransportState::class),
77-
$app['log']
78-
);
79-
});
80-
81-
$this->app->bind(StdioTransportHandler::class, function (Application $app) {
82-
return new StdioTransportHandler(
83-
$app->make(Processor::class),
84-
$app->make(TransportState::class),
85-
$app['log']
86-
);
87-
});
56+
$registry = $server->getRegistry();
8857

89-
$this->app->afterResolving(Registry::class, function (Registry $registry) {
9058
$registry->setToolsChangedNotifier(fn () => ToolsListChanged::dispatch());
9159
$registry->setResourcesChangedNotifier(fn () => ResourcesListChanged::dispatch());
9260
$registry->setPromptsChangedNotifier(fn () => PromptsListChanged::dispatch());
61+
62+
return $server;
9363
});
64+
65+
$this->app->bind(ConfigurationRepositoryInterface::class, fn (Application $app) => new ConfigAdapter($app['config']));
66+
$this->app->bind(LoggerInterface::class, fn (Application $app) => $app['log']->channel($app['config']->get('mcp.logging.channel')));
67+
$this->app->bind(CacheInterface::class, fn (Application $app) => $app['cache']->store($app['config']->get('mcp.cache.store')));
9468
}
9569

9670
public function boot(): void

0 commit comments

Comments
 (0)