1818use Mcp \Capability \Attribute \McpTool ;
1919use Psr \Log \LoggerInterface ;
2020
21- class McpElements
21+ /**
22+ * @phpstan-type User array{name: string, email: string, role: string}
23+ */
24+ final class McpElements
2225{
23- // Simulate a simple user database
26+ /**
27+ * Simulate a simple user database.
28+ *
29+ * @var array<int, User>
30+ */
2431 private array $ users = [
2532 '101 ' => [
'name ' =>
'Alice ' ,
'email ' =>
'[email protected] ' ,
'role ' =>
'admin ' ],
2633 '102 ' => [
'name ' =>
'Bob ' ,
'email ' =>
'[email protected] ' ,
'role ' =>
'user ' ],
2734 '103 ' => [
'name ' =>
'Charlie ' ,
'email ' =>
'[email protected] ' ,
'role ' =>
'user ' ],
2835 ];
2936
3037 public function __construct (
31- private LoggerInterface $ logger ,
38+ private readonly LoggerInterface $ logger ,
3239 ) {
3340 $ this ->logger ->debug ('HttpUserProfileExample McpElements instantiated. ' );
3441 }
@@ -38,7 +45,7 @@ public function __construct(
3845 *
3946 * @param string $userId the ID of the user (from URI)
4047 *
41- * @return array user profile data
48+ * @return User user profile data
4249 *
4350 * @throws McpServerException if the user is not found
4451 */
@@ -64,7 +71,7 @@ public function getUserProfile(
6471 /**
6572 * Retrieves a list of all known user IDs.
6673 *
67- * @return array list of user IDs
74+ * @return int[] list of user IDs
6875 */
6976 #[McpResource(
7077 uri: 'user://list/ids ' ,
@@ -86,7 +93,7 @@ public function listUserIds(): array
8693 * @param string $userId the ID of the user to message
8794 * @param string|null $customMessage an optional custom message part
8895 *
89- * @return array status of the operation
96+ * @return array<string, bool|string> status of the operation
9097 */
9198 #[McpTool(name: 'send_welcome ' )]
9299 public function sendWelcomeMessage (string $ userId , ?string $ customMessage = null ): array
@@ -106,6 +113,9 @@ public function sendWelcomeMessage(string $userId, ?string $customMessage = null
106113 return ['success ' => true , 'message_sent ' => $ message ];
107114 }
108115
116+ /**
117+ * @return array<string, bool|string>
118+ */
109119 #[McpTool(name: 'test_tool_without_params ' )]
110120 public function testToolWithoutParams (): array
111121 {
@@ -118,7 +128,7 @@ public function testToolWithoutParams(): array
118128 * @param string $userId the user ID to generate the bio for
119129 * @param string $tone Desired tone (e.g., 'formal', 'casual').
120130 *
121- * @return array prompt messages
131+ * @return array<string, string>[] prompt messages
122132 *
123133 * @throws McpServerException if user not found
124134 */
0 commit comments