3838use Mcp \Schema \Tool ;
3939use Mcp \Schema \ToolAnnotations ;
4040use Mcp \Server ;
41+ use Mcp \Server \Session \SessionFactory ;
42+ use Mcp \Server \Session \InMemorySessionStore ;
43+ use Mcp \Server \Session \SessionFactoryInterface ;
44+ use Mcp \Server \Session \SessionStoreInterface ;
4145use Psr \Container \ContainerInterface ;
4246use Psr \EventDispatcher \EventDispatcherInterface ;
4347use Psr \Log \LoggerInterface ;
4448use Psr \Log \NullLogger ;
45- use Psr \SimpleCache \CacheInterface ;
4649
4750/**
4851 * @author Kyrian Obikwelu <[email protected] > @@ -65,6 +68,10 @@ final class ServerBuilder
6568
6669 private ?ContainerInterface $ container = null ;
6770
71+ private ?SessionFactoryInterface $ sessionFactory = null ;
72+ private ?SessionStoreInterface $ sessionStore = null ;
73+ private ?int $ sessionTtl = 3600 ;
74+
6875 private ?int $ paginationLimit = 50 ;
6976
7077 private ?string $ instructions = null ;
@@ -193,6 +200,18 @@ public function setContainer(ContainerInterface $container): self
193200 return $ this ;
194201 }
195202
203+ public function withSession (
204+ SessionFactoryInterface $ sessionFactory ,
205+ SessionStoreInterface $ sessionStore ,
206+ int $ ttl = 3600
207+ ): self {
208+ $ this ->sessionFactory = $ sessionFactory ;
209+ $ this ->sessionStore = $ sessionStore ;
210+ $ this ->sessionTtl = $ ttl ;
211+
212+ return $ this ;
213+ }
214+
196215 public function setDiscovery (
197216 string $ basePath ,
198217 array $ scanDirs = ['. ' , 'src ' ],
@@ -327,7 +346,7 @@ private function registerCapabilities(
327346 $ reflection = HandlerResolver::resolve ($ data ['handler ' ]);
328347
329348 if ($ reflection instanceof \ReflectionFunction) {
330- $ name = $ data ['name ' ] ?? 'closure_tool_ ' . spl_object_id ($ data ['handler ' ]);
349+ $ name = $ data ['name ' ] ?? 'closure_tool_ ' . spl_object_id ($ data ['handler ' ]);
331350 $ description = $ data ['description ' ] ?? null ;
332351 } else {
333352 $ classShortName = $ reflection ->getDeclaringClass ()->getShortName ();
@@ -362,7 +381,7 @@ private function registerCapabilities(
362381 $ reflection = HandlerResolver::resolve ($ data ['handler ' ]);
363382
364383 if ($ reflection instanceof \ReflectionFunction) {
365- $ name = $ data ['name ' ] ?? 'closure_resource_ ' . spl_object_id ($ data ['handler ' ]);
384+ $ name = $ data ['name ' ] ?? 'closure_resource_ ' . spl_object_id ($ data ['handler ' ]);
366385 $ description = $ data ['description ' ] ?? null ;
367386 } else {
368387 $ classShortName = $ reflection ->getDeclaringClass ()->getShortName ();
@@ -400,7 +419,7 @@ private function registerCapabilities(
400419 $ reflection = HandlerResolver::resolve ($ data ['handler ' ]);
401420
402421 if ($ reflection instanceof \ReflectionFunction) {
403- $ name = $ data ['name ' ] ?? 'closure_template_ ' . spl_object_id ($ data ['handler ' ]);
422+ $ name = $ data ['name ' ] ?? 'closure_template_ ' . spl_object_id ($ data ['handler ' ]);
404423 $ description = $ data ['description ' ] ?? null ;
405424 } else {
406425 $ classShortName = $ reflection ->getDeclaringClass ()->getShortName ();
@@ -438,7 +457,7 @@ private function registerCapabilities(
438457 $ reflection = HandlerResolver::resolve ($ data ['handler ' ]);
439458
440459 if ($ reflection instanceof \ReflectionFunction) {
441- $ name = $ data ['name ' ] ?? 'closure_prompt_ ' . spl_object_id ($ data ['handler ' ]);
460+ $ name = $ data ['name ' ] ?? 'closure_prompt_ ' . spl_object_id ($ data ['handler ' ]);
442461 $ description = $ data ['description ' ] ?? null ;
443462 } else {
444463 $ classShortName = $ reflection ->getDeclaringClass ()->getShortName ();
@@ -461,7 +480,7 @@ private function registerCapabilities(
461480 continue ;
462481 }
463482
464- $ paramTag = $ paramTags ['$ ' . $ param ->getName ()] ?? null ;
483+ $ paramTag = $ paramTags ['$ ' . $ param ->getName ()] ?? null ;
465484 $ arguments [] = new PromptArgument (
466485 $ param ->getName (),
467486 $ paramTag ? trim ((string ) $ paramTag ->getDescription ()) : null ,
0 commit comments