forked from EdouardCourty/mcp-server-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInitializeMethodHandler.php
More file actions
51 lines (44 loc) · 1.53 KB
/
Copy pathInitializeMethodHandler.php
File metadata and controls
51 lines (44 loc) · 1.53 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
<?php
declare(strict_types=1);
namespace Ecourty\McpServerBundle\MethodHandler;
use Ecourty\McpServerBundle\Attribute\AsMethodHandler;
use Ecourty\McpServerBundle\Contract\MethodHandlerInterface;
use Ecourty\McpServerBundle\Event\InitializeEvent;
use Ecourty\McpServerBundle\HttpFoundation\JsonRpcRequest;
use Psr\EventDispatcher\EventDispatcherInterface;
/**
* Handles the 'initialize' method for the MCP server.
*
* This method is called when a client initializes a connection to the MCP server.
* It returns the protocol version and capabilities of the server.
*/
#[AsMethodHandler(methodName: 'initialize')]
class InitializeMethodHandler implements MethodHandlerInterface
{
public const string PROTOCOL_VERSION = '2024-11-05';
public function __construct(
private readonly string $serverName,
private readonly string $serverVersion,
private readonly ?EventDispatcherInterface $eventDispatcher = null,
) {
}
public function handle(JsonRpcRequest $request): array
{
$this->eventDispatcher?->dispatch(new InitializeEvent($request));
return [
'protocolVersion' => self::PROTOCOL_VERSION,
'capabilities' => [
'prompts' => [
'listChanged' => false,
],
'tools' => [
'listChanged' => false,
],
],
'serverInfo' => [
'name' => $this->serverName,
'version' => $this->serverVersion,
],
];
}
}