mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2026-06-11 02:50:29 +00:00
b6f05bca41
- 🤖 Introduced `ResolvesEntities` trait to simplify entity resolution by name or ID across MCP tools. - 📚 Updated tools (Meetups, Cities, Venues, Courses, Lecturers) to use the concern for resolving related entities (e.g., courses, venues, lecturers). - 🎯 Enhanced tool descriptions and schemas for better name-based parameter handling with fallback support for IDs. - ✅ Added dedicated feature tests for name resolution logic, partial matches, and error handling scenarios.
73 lines
3.0 KiB
PHP
73 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Mcp\Tools\Meetup;
|
|
|
|
use App\Http\Requests\Api\UpdateMeetupRequest;
|
|
use App\Http\Resources\MeetupResource;
|
|
use App\Mcp\Tools\Concerns\ResolvesEntities;
|
|
use App\Models\City;
|
|
use App\Models\Meetup;
|
|
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
|
use Illuminate\JsonSchema\Types\Type;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Laravel\Mcp\Request;
|
|
use Laravel\Mcp\Response;
|
|
use Laravel\Mcp\Server\Attributes\Description;
|
|
use Laravel\Mcp\Server\Tool;
|
|
|
|
#[Description('Aktualisiert eines deiner Meetups (per Name angegeben). Nur der Ersteller oder ein Super-Admin darf es ändern.')]
|
|
class UpdateMeetupTool extends Tool
|
|
{
|
|
use ResolvesEntities;
|
|
|
|
public function handle(Request $request): Response
|
|
{
|
|
$meetup = $this->resolveOwnedByName($request, Meetup::class, 'Meetups', 'meetup');
|
|
|
|
if ($meetup instanceof Response) {
|
|
return $meetup;
|
|
}
|
|
|
|
$user = $request->user();
|
|
|
|
if ($user === null || Gate::forUser($user)->denies('update', $meetup)) {
|
|
return Response::error('Nur der Ersteller oder ein Super-Admin darf dieses Meetup ändern.');
|
|
}
|
|
|
|
if ($error = $this->mergeForeignKey($request, 'city', 'city_id', City::query(), 'Stadt', false)) {
|
|
return $error;
|
|
}
|
|
|
|
$validated = $request->validate((new UpdateMeetupRequest)->rules());
|
|
|
|
$meetup->update($validated);
|
|
|
|
return Response::json(MeetupResource::make($meetup->fresh())->resolve());
|
|
}
|
|
|
|
/**
|
|
* @return array<string, Type>
|
|
*/
|
|
public function schema(JsonSchema $schema): array
|
|
{
|
|
return [
|
|
'meetup' => $schema->string()->description('Name des zu ändernden Meetups (aus deinen Meetups, siehe list-my-meetups).'),
|
|
'id' => $schema->integer()->description('Optional: ID des Meetups, falls bereits bekannt (Alternative zu "meetup").'),
|
|
'name' => $schema->string()->description('Neuer Name des Meetups.'),
|
|
'city' => $schema->string()->description('Name der zugehörigen Stadt (wird automatisch aufgelöst).'),
|
|
'city_id' => $schema->integer()->description('Optional: ID der Stadt (Alternative zu "city").'),
|
|
'intro' => $schema->string()->description('Einleitungstext.'),
|
|
'telegram_link' => $schema->string()->description('Telegram-Gruppen-URL.'),
|
|
'webpage' => $schema->string()->description('Webseiten-URL.'),
|
|
'twitter_username' => $schema->string()->description('Twitter/X-Benutzername.'),
|
|
'matrix_group' => $schema->string()->description('Matrix-Gruppe.'),
|
|
'nostr' => $schema->string()->description('Nostr-Identifier.'),
|
|
'simplex' => $schema->string()->description('SimpleX-Link.'),
|
|
'signal' => $schema->string()->description('Signal-Gruppenlink.'),
|
|
'community' => $schema->string()->description('Community-Bezeichnung.'),
|
|
'visible_on_map' => $schema->boolean()->description('Auf der Karte sichtbar.'),
|
|
'is_active' => $schema->boolean()->description('Aktiv.'),
|
|
];
|
|
}
|
|
}
|