-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathRequestContext.php
More file actions
64 lines (53 loc) · 1.55 KB
/
RequestContext.php
File metadata and controls
64 lines (53 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mcp\Server;
use Mcp\Capability\Logger\ClientLogger;
use Mcp\Schema\JsonRpc\Request;
use Mcp\Server\Session\SessionInterface;
/**
* Context related to a single request. This includes information about the session and
* will build request-specific objects.
*
* This is a stateful object, it should not be reused between requests.
*
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
final class RequestContext
{
private ?ClientGateway $clientGateway = null;
private ?ClientLogger $clientLogger = null;
public function __construct(
private readonly SessionInterface $session,
private readonly Request $request,
) {
}
public function getRequest(): Request
{
return $this->request;
}
public function getSession(): SessionInterface
{
return $this->session;
}
public function getClientGateway(): ClientGateway
{
if (null == $this->clientGateway) {
$this->clientGateway = new ClientGateway($this->session);
}
return $this->clientGateway;
}
public function getClientLogger(): ClientLogger
{
if (null === $this->clientLogger) {
$this->clientLogger = new ClientLogger($this->getClientGateway(), $this->session);
}
return $this->clientLogger;
}
}