This commit is contained in:
snipe
2026-05-09 12:20:45 +01:00
parent 256003b675
commit f697ef1d03
5 changed files with 41 additions and 40 deletions
+1 -1
View File
@@ -76,9 +76,9 @@ use App\Mcp\Tools\ListSuppliersTool;
use App\Mcp\Tools\ListUploadsTool;
use App\Mcp\Tools\ListUsersTool;
use App\Mcp\Tools\Reset2FATool;
use App\Mcp\Tools\SendPasswordResetTool;
use App\Mcp\Tools\RestoreAssetTool;
use App\Mcp\Tools\RestoreUserTool;
use App\Mcp\Tools\SendPasswordResetTool;
use App\Mcp\Tools\ShowAssetModelTool;
use App\Mcp\Tools\ShowAssetTool;
use App\Mcp\Tools\ShowCategoryTool;
+12 -12
View File
@@ -27,9 +27,9 @@ class CreateGroupTool extends Tool
try {
$request->validate([
'name' => 'required|string|max:255',
'name' => 'required|string|max:255',
'permissions' => 'nullable|string',
'notes' => 'nullable|string',
'notes' => 'nullable|string',
]);
} catch (ValidationException $e) {
return Response::make(Response::error($e->validator->errors()->first()));
@@ -58,10 +58,10 @@ class CreateGroupTool extends Tool
return Response::make(
Response::text(trans('mcp.group_created', ['name' => $group->name]))
)->withStructuredContent([
'success' => true,
'message' => trans('mcp.group_created', ['name' => $group->name]),
'id' => $group->id,
'name' => $group->name,
'success' => true,
'message' => trans('mcp.group_created', ['name' => $group->name]),
'id' => $group->id,
'name' => $group->name,
'permissions' => $group->decodePermissions(),
]);
}
@@ -101,7 +101,7 @@ class CreateGroupTool extends Tool
public function schema(JsonSchema $schema): array
{
return [
'name' => $schema->string()->description('Group name (required, must be unique)'),
'name' => $schema->string()->description('Group name (required, must be unique)'),
'permissions' => $schema->string()->description(
'JSON object mapping permission keys to 1 (grant) or -1 (deny). '.
'Valid keys include: superuser, admin, import, reports.view, '.
@@ -113,17 +113,17 @@ class CreateGroupTool extends Tool
'consumables.view, consumables.create, consumables.edit, consumables.delete, consumables.checkout, '.
'and many more. Example: {"assets.view":1,"assets.create":1,"assets.edit":-1}'
),
'notes' => $schema->string()->description('Notes about the group'),
'notes' => $schema->string()->description('Notes about the group'),
];
}
public function outputSchema(JsonSchema $schema): array
{
return [
'success' => $schema->boolean()->description('True if the group was created'),
'message' => $schema->string()->description('Human-readable result message')->required(),
'id' => $schema->number()->description('Numeric ID of the new group'),
'name' => $schema->string()->description('Name of the new group'),
'success' => $schema->boolean()->description('True if the group was created'),
'message' => $schema->string()->description('Human-readable result message')->required(),
'id' => $schema->number()->description('Numeric ID of the new group'),
'name' => $schema->string()->description('Name of the new group'),
'permissions' => $schema->object()->description('Permissions set on the group'),
];
}
+10 -10
View File
@@ -22,9 +22,9 @@ class SendPasswordResetTool extends Tool
public function handle(Request $request): ResponseFactory
{
$request->validate([
'id' => 'nullable|integer',
'id' => 'nullable|integer',
'username' => 'nullable|string|max:191',
'email' => 'nullable|string|max:191',
'email' => 'nullable|string|max:191',
]);
$user = $this->resolveUser($request);
@@ -59,10 +59,10 @@ class SendPasswordResetTool extends Tool
return Response::make(
Response::text(trans('mcp.password_reset_sent', ['email' => $user->email]))
)->withStructuredContent([
'success' => true,
'message' => trans('mcp.password_reset_sent', ['email' => $user->email]),
'success' => true,
'message' => trans('mcp.password_reset_sent', ['email' => $user->email]),
'username' => $user->username,
'email' => $user->email,
'email' => $user->email,
]);
}
@@ -87,19 +87,19 @@ class SendPasswordResetTool extends Tool
public function schema(JsonSchema $schema): array
{
return [
'id' => $schema->number()->description('Numeric ID of the user'),
'id' => $schema->number()->description('Numeric ID of the user'),
'username' => $schema->string()->description('Username of the user'),
'email' => $schema->string()->description('Email address of the user'),
'email' => $schema->string()->description('Email address of the user'),
];
}
public function outputSchema(JsonSchema $schema): array
{
return [
'success' => $schema->boolean()->description('True if the reset email was sent'),
'message' => $schema->string()->description('Human-readable result message')->required(),
'success' => $schema->boolean()->description('True if the reset email was sent'),
'message' => $schema->string()->description('Human-readable result message')->required(),
'username' => $schema->string()->description('Username of the user'),
'email' => $schema->string()->description('Email address the reset link was sent to'),
'email' => $schema->string()->description('Email address the reset link was sent to'),
];
}
}
+16 -16
View File
@@ -27,11 +27,11 @@ class UpdateGroupTool extends Tool
try {
$request->validate([
'id' => 'nullable|integer',
'name' => 'nullable|string|max:255',
'new_name' => 'nullable|string|max:255',
'id' => 'nullable|integer',
'name' => 'nullable|string|max:255',
'new_name' => 'nullable|string|max:255',
'permissions' => 'nullable|string',
'notes' => 'nullable|string',
'notes' => 'nullable|string',
]);
} catch (ValidationException $e) {
return Response::make(Response::error($e->validator->errors()->first()));
@@ -69,10 +69,10 @@ class UpdateGroupTool extends Tool
return Response::make(
Response::text(trans('mcp.group_updated', ['name' => $group->name]))
)->withStructuredContent([
'success' => true,
'message' => trans('mcp.group_updated', ['name' => $group->name]),
'id' => $group->id,
'name' => $group->name,
'success' => true,
'message' => trans('mcp.group_updated', ['name' => $group->name]),
'id' => $group->id,
'name' => $group->name,
'permissions' => $group->decodePermissions(),
]);
}
@@ -112,26 +112,26 @@ class UpdateGroupTool extends Tool
public function schema(JsonSchema $schema): array
{
return [
'id' => $schema->number()->description('Numeric group ID to update'),
'name' => $schema->string()->description('Group name to look up for updating'),
'new_name' => $schema->string()->description('New name to rename the group to'),
'id' => $schema->number()->description('Numeric group ID to update'),
'name' => $schema->string()->description('Group name to look up for updating'),
'new_name' => $schema->string()->description('New name to rename the group to'),
'permissions' => $schema->string()->description(
'JSON object replacing the group\'s entire permission set. '.
'Map permission keys to 1 (grant) or -1 (deny). '.
'Example: {"assets.view":1,"assets.create":1,"assets.edit":-1}. '.
'Omit to leave existing permissions unchanged.'
),
'notes' => $schema->string()->description('Updated notes for the group'),
'notes' => $schema->string()->description('Updated notes for the group'),
];
}
public function outputSchema(JsonSchema $schema): array
{
return [
'success' => $schema->boolean()->description('True if the update succeeded'),
'message' => $schema->string()->description('Human-readable result message')->required(),
'id' => $schema->number()->description('Numeric ID of the updated group'),
'name' => $schema->string()->description('Name of the updated group'),
'success' => $schema->boolean()->description('True if the update succeeded'),
'message' => $schema->string()->description('Human-readable result message')->required(),
'id' => $schema->number()->description('Numeric ID of the updated group'),
'name' => $schema->string()->description('Name of the updated group'),
'permissions' => $schema->object()->description('Permissions now set on the group'),
];
}
+2 -1
View File
@@ -3,6 +3,7 @@
namespace Tests\Feature\Mcp;
use App\Mcp\Tools\CreateGroupTool;
use App\Models\Group;
use App\Models\User;
use Laravel\Mcp\Request;
use Laravel\Mcp\ResponseFactory;
@@ -69,7 +70,7 @@ class CreateGroupToolTest extends TestCase
$this->assertTrue($content['success']);
$this->assertArrayHasKey('permissions', $content);
$group = \App\Models\Group::where('name', $name)->first();
$group = Group::where('name', $name)->first();
$this->assertNotNull($group);
$decoded = json_decode($group->permissions, true);
$this->assertEquals(1, $decoded['assets.view']);