Skip to content

[Feature Request] Support Automatic Resolution for DTOs and Form Requests in Tool Actions #40

@sebasvdonk

Description

@sebasvdonk

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');

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions