From 9619d187dfba8935701a5aacf631481fadbccdef Mon Sep 17 00:00:00 2001 From: Eduard Lupacescu Date: Sun, 24 Aug 2025 14:59:32 +0300 Subject: [PATCH 1/2] Add ProfileTool for getting authenticated user profile --- src/MCP/Tools/Operations/ProfileTool.php | 68 ++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/MCP/Tools/Operations/ProfileTool.php diff --git a/src/MCP/Tools/Operations/ProfileTool.php b/src/MCP/Tools/Operations/ProfileTool.php new file mode 100644 index 000000000..b2adc39a9 --- /dev/null +++ b/src/MCP/Tools/Operations/ProfileTool.php @@ -0,0 +1,68 @@ +repository = app($repositoryClass); + } + + public function name(): string + { + $uriKey = $this->repository->uriKey(); + + return "{$uriKey}-profile-tool"; + } + + public function description(): string + { + $modelName = class_basename($this->repository::$model); + + return "Get the current authenticated user profile including {$modelName} and relationship information."; + } + + public function schema(ToolInputSchema $schema): ToolInputSchema + { + $relatedOptions = $this->repository::collectRelated() + ->intoAssoc() + ->keys() + ->toArray(); + + $schema->string('include') + ->description('Comma-separated list of relationships to include in the response. Available options: ' . implode(', ', $relatedOptions) . ' (e.g., include=employee,roles.permissions)'); + + return $schema; + } + + public function handle(array $arguments): ToolResult|Generator + { + $user = auth()->user(); + + if (! $user) { + return ToolResult::json([ + 'error' => 'No authenticated user found', + ]); + } + + $arguments['id'] = $user->id; + + $this->repository->request = app(McpRequest::class); + + $result = $this->repository->indexTool($arguments, app(McpRequest::class)); + + return ToolResult::json($result); + } +} \ No newline at end of file From 5f3aca52ebbcdfc556cb18da4275f3bc43856837 Mon Sep 17 00:00:00 2001 From: binaryk Date: Sun, 24 Aug 2025 12:00:18 +0000 Subject: [PATCH 2/2] Fix styling --- src/MCP/Tools/Operations/ProfileTool.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MCP/Tools/Operations/ProfileTool.php b/src/MCP/Tools/Operations/ProfileTool.php index b2adc39a9..d50048365 100644 --- a/src/MCP/Tools/Operations/ProfileTool.php +++ b/src/MCP/Tools/Operations/ProfileTool.php @@ -42,7 +42,7 @@ public function schema(ToolInputSchema $schema): ToolInputSchema ->toArray(); $schema->string('include') - ->description('Comma-separated list of relationships to include in the response. Available options: ' . implode(', ', $relatedOptions) . ' (e.g., include=employee,roles.permissions)'); + ->description('Comma-separated list of relationships to include in the response. Available options: '.implode(', ', $relatedOptions).' (e.g., include=employee,roles.permissions)'); return $schema; } @@ -65,4 +65,4 @@ public function handle(array $arguments): ToolResult|Generator return ToolResult::json($result); } -} \ No newline at end of file +}