mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2026-06-11 02:50:29 +00:00
8c68b19138
- 🛠️ Introduced generic Super-Admin MCP tools, including `list-models`, `describe-model`, `list-records`, `show-record`, `create-record`, and `update-record`. - 🛡️ Restricted modification of critical fields (e.g., passwords, roles, tokens) to enhance security. - ✅ Added extensive feature tests for Super-Admin functionality and access control. - 📜 Increased pagination length to accommodate new tools on a single page. - 🔗 Registered Super-Admin tools in `EinundzwanzigServer`.
52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Mcp\Tools\SuperAdmin;
|
|
|
|
use App\Mcp\Tools\SuperAdmin\Concerns\AuthorizesSuperAdmin;
|
|
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
|
use Illuminate\JsonSchema\Types\Type;
|
|
use Laravel\Mcp\Request;
|
|
use Laravel\Mcp\Response;
|
|
use Laravel\Mcp\Server\Attributes\Description;
|
|
use Laravel\Mcp\Server\Tool;
|
|
use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;
|
|
|
|
#[IsReadOnly]
|
|
#[Description('NUR SUPER-ADMIN: Zeigt einen einzelnen Datensatz eines beliebigen Models per ID (alle Attribute).')]
|
|
class SuperAdminShowRecordTool extends Tool
|
|
{
|
|
use AuthorizesSuperAdmin;
|
|
|
|
public function handle(Request $request): Response
|
|
{
|
|
if ($denied = $this->denyUnlessSuperAdmin($request)) {
|
|
return $denied;
|
|
}
|
|
|
|
$class = $this->resolveModel($request);
|
|
|
|
if ($class instanceof Response) {
|
|
return $class;
|
|
}
|
|
|
|
$record = $class::query()->find($request->get('id'));
|
|
|
|
if ($record === null) {
|
|
return Response::error('Datensatz mit ID '.$request->get('id').' in '.class_basename($class).' nicht gefunden.');
|
|
}
|
|
|
|
return Response::json($record->toArray());
|
|
}
|
|
|
|
/**
|
|
* @return array<string, Type>
|
|
*/
|
|
public function schema(JsonSchema $schema): array
|
|
{
|
|
return [
|
|
'model' => $this->modelParameter($schema),
|
|
'id' => $schema->integer()->description('Primärschlüssel des Datensatzes.')->required(),
|
|
];
|
|
}
|
|
}
|