1515use PhpMcp \Laravel \Server \Events \ResourcesListChanged ;
1616use PhpMcp \Laravel \Server \Events \ToolsListChanged ;
1717use PhpMcp \Laravel \Server \Listeners \McpNotificationListener ;
18- use PhpMcp \Server \Processor ;
19- use PhpMcp \Server \Registry ;
18+ use PhpMcp \Server \Contracts \ConfigurationRepositoryInterface ;
2019use 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
2523class 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