When I define a tool action, I'd love to be able to type-hint a custom Spatie\LaravelData\Data object or a FormRequest in the method signature and have Laravel automatically resolve it, just like it does in a controller.
Currently, it seems the handler is called directly with the raw input array, which bypasses Laravel's dependency injection and leads to a TypeError if you're not expecting an array.
A Quick Example
Here’s what I'm trying to do. I have a simple DTO:
// app/Data/ContactCreateData.php
class ContactCreateData extends \Spatie\LaravelData\Data
{
public function __construct(
public string $first_name,
public string $last_name,
) {}
}
And I want to use it directly in my tool action like this:
// app/Mcp/Actions/CreateContactAction.php
class CreateContactAction
{
// I expect Laravel to automatically create this object from the input
public function action(ContactCreateData $contactData)
{
// ... use the validated DTO
}
}
When I register this with Mcp::tool() and call it, the application throws a TypeError because my action method gets an array instead of the ContactCreateData object it expects.
// routes/mcp.php
use App\Mcp\Actions\CreateContactAction;
use PhpMcp\Laravel\Facades\Mcp;
Mcp::tool([CreateContactAction::class, 'action'])
->name('create_contact');
When I define a tool action, I'd love to be able to type-hint a custom
Spatie\LaravelData\Dataobject or aFormRequestin the method signature and have Laravel automatically resolve it, just like it does in a controller.Currently, it seems the handler is called directly with the raw input
array, which bypasses Laravel's dependency injection and leads to aTypeErrorif you're not expecting an array.A Quick Example
Here’s what I'm trying to do. I have a simple DTO:
And I want to use it directly in my tool action like this:
When I register this with
Mcp::tool()and call it, the application throws aTypeErrorbecause myactionmethod gets anarrayinstead of theContactCreateDataobject it expects.