Skip to content

Conversation

nunomaduro
Copy link
Member

<?php

namespace App\Mcp\Tools;

use Generator;
use Illuminate\JsonSchema\JsonSchema;
use Laravel\Mcp\Server\Tool;
use Laravel\Mcp\Server\Tools\ToolResult;

class HelloChatTool extends Tool
{
    /**
     * The tool's title.
     */
    protected string $title = 'Hello Chat Tool';

    /**
     * Get the tool's description.
     */
    protected string $description = 'A simple tool that greets a person by name in a chat message.';

    /**
     * Handle the tool call.
     */
    public function handle(array $arguments): ToolResult|Generator
    {
        return ToolResult::text('Welcome, '.$arguments['name'].' to Nuno Nation chat!');
    }

    /**
     * Get the tool's input schema.
     */
    public function schema(JsonSchema $schema): array
    {
        return [
            'name' => $schema->string()
                ->min(2)
                ->max(100)
                ->description('The of the person to greet')
                ->required(),
        ];
    }
}

@nunomaduro nunomaduro marked this pull request as draft September 3, 2025 19:23
Comment on lines +71 to 80
return collect([
'title' => 'title',
'readonly' => 'readOnlyHint',
'destructive' => 'destructiveHint',
'idempotent' => 'idempotentHint',
'openWorld' => 'openWorldHint',
])->filter(fn (string $annotation, string $property) => property_exists($this, $property))
->mapWithKeys(fn (string $annotation, string $property) => [$annotation => $this->$property])
->reject(fn ($value) => $value === '' || $value === false)
->all();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return collect([
'title' => 'title',
'readonly' => 'readOnlyHint',
'destructive' => 'destructiveHint',
'idempotent' => 'idempotentHint',
'openWorld' => 'openWorldHint',
])->filter(fn (string $annotation, string $property) => property_exists($this, $property))
->mapWithKeys(fn (string $annotation, string $property) => [$annotation => $this->$property])
->reject(fn ($value) => $value === '' || $value === false)
->all();
return collect([
'title' => 'title',
'readOnlyHint' => 'readonly',
'destructiveHint' => 'destructive',
'idempotentHint' => 'idempotent',
'openWorldHint' => 'openWorld',
])
->map(fn (string $property) => $this->$property)
->filter()
->all();

@nunomaduro
Copy link
Member Author

waiting for @taylorotwell's decision.

@nunomaduro nunomaduro changed the title Uses properties instead of annotations [0.x] Uses properties instead of annotations Sep 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants