forked from modelcontextprotocol/php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetadata.php
More file actions
53 lines (47 loc) · 1.31 KB
/
Metadata.php
File metadata and controls
53 lines (47 loc) · 1.31 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
<?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\Schema;
/**
* Lightweight value object to access request metadata in handlers.
*
* Example usage in a tool handler:
* function exampleAction(string $input, Metadata $meta): array {
* $schema = $meta->get('securitySchema');
* return ['result' => 'ok', 'securitySchema' => $schema];
* }
*
* The SDK will inject an instance automatically when the parameter is type-hinted
* with this class. If no metadata is present on the request and the parameter
* allows null, null will be passed; otherwise, an internal error will be thrown.
*/
final class Metadata
{
/**
* @param array<string, mixed> $data
*/
public function __construct(private array $data = [])
{
}
/**
* @return array<string, mixed>
*/
public function all(): array
{
return $this->data;
}
public function has(string $key): bool
{
return \array_key_exists($key, $this->data);
}
public function get(string $key, mixed $default = null): mixed
{
return $this->data[$key] ?? $default;
}
}