-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserInfoTool.php
More file actions
31 lines (26 loc) · 996 Bytes
/
Copy pathUserInfoTool.php
File metadata and controls
31 lines (26 loc) · 996 Bytes
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
<?php
declare(strict_types=1);
namespace McpServer\Tools;
use McpServer\Attributes\McpFunction;
use McpServer\UserContext;
readonly class UserInfoTool {
/**
* Demonstrates the user scope: the server injects the current UserContext
* into any tool method that declares a `?UserContext` parameter (reflection
* at registration time). In CLI/stdio mode this is the trusted local user.
*/
#[McpFunction(
name: 'get_current_user',
description: 'Returns information about the currently authenticated user (username, name, roles, permissions).',
schema: ['type' => 'object', 'properties' => new \stdClass()]
)]
public function getCurrentUser(array $arguments, ?UserContext $user = null): array {
$user ??= UserContext::anonymous();
return [
[
'type' => 'text',
'text' => json_encode($user->toArray(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
]
];
}
}