mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2026-06-11 02:50:29 +00:00
✨ Add ResolvesEntities concern for name-based ID resolution
- 🤖 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.
This commit is contained in:
@@ -4,6 +4,8 @@ namespace App\Mcp\Tools\MeetupEvent;
|
||||
|
||||
use App\Http\Requests\Api\StoreMeetupEventRequest;
|
||||
use App\Http\Resources\MeetupEventResource;
|
||||
use App\Mcp\Tools\Concerns\ResolvesEntities;
|
||||
use App\Models\Meetup;
|
||||
use App\Models\MeetupEvent;
|
||||
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
||||
use Illuminate\JsonSchema\Types\Type;
|
||||
@@ -13,9 +15,11 @@ use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Attributes\Description;
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
|
||||
#[Description('Legt einen neuen Meetup-Termin für den authentifizierten Nutzer an. Der Ersteller (created_by) wird automatisch gesetzt.')]
|
||||
#[Description('Legt einen neuen Meetup-Termin für eines der eigenen Meetups an. Das Meetup wird über seinen Namen angegeben; der Ersteller (created_by) wird automatisch gesetzt.')]
|
||||
class CreateMeetupEventTool extends Tool
|
||||
{
|
||||
use ResolvesEntities;
|
||||
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
@@ -24,6 +28,16 @@ class CreateMeetupEventTool extends Tool
|
||||
return Response::error('Nicht berechtigt, einen Meetup-Termin anzulegen.');
|
||||
}
|
||||
|
||||
if (! $this->present($request->get('meetup_id'))) {
|
||||
$meetup = $this->resolveOwnedByName($request, Meetup::class, 'Meetups', 'meetup');
|
||||
|
||||
if ($meetup instanceof Response) {
|
||||
return $meetup;
|
||||
}
|
||||
|
||||
$request->merge(['meetup_id' => $meetup->id]);
|
||||
}
|
||||
|
||||
$storeRequest = new StoreMeetupEventRequest;
|
||||
|
||||
$validated = $request->validate(
|
||||
@@ -42,7 +56,8 @@ class CreateMeetupEventTool extends Tool
|
||||
public function schema(JsonSchema $schema): array
|
||||
{
|
||||
return [
|
||||
'meetup_id' => $schema->integer()->description('ID des zugehörigen Meetups (vorher per search-meetups auflösen).')->required(),
|
||||
'meetup' => $schema->string()->description('Name deines Meetups, zu dem der Termin gehört (z. B. "Einundzwanzig Ansbach"). Wird automatisch aufgelöst – sonst zuerst list-my-meetups aufrufen und den Nutzer auswählen lassen.'),
|
||||
'meetup_id' => $schema->integer()->description('Optional: ID des Meetups, falls bereits bekannt (Alternative zu "meetup").'),
|
||||
'start' => $schema->string()->description('Startzeitpunkt als Datum/Uhrzeit (z. B. 2026-08-01 18:00:00).')->required(),
|
||||
'location' => $schema->string()->description('Veranstaltungsort.'),
|
||||
'description' => $schema->string()->description('Beschreibung des Termins.'),
|
||||
|
||||
Reference in New Issue
Block a user