Skip to content

Conversation

nicobleiler
Copy link

@nicobleiler nicobleiler commented Sep 30, 2025

Adds a method validated similar to formRequest so you can simply define the rules, messages and attributes & call validated on the request instead of having to rewrite it.

Example MCP Request

<?php

namespace App\Mcp\Requests;

use Laravel\Mcp\Request;

class QueryMCPRequest extends Request
{
    public function rules()
    {
        return [
            'query' => 'required|string',
            'page' => 'nullable|page',
            'pageSize' => 'nullable|page_size',
        ];
    }
}

Example handling in a tool

    ...
    public function handle(QueryMCPRequest $request): Response
    {
        $validated = $request->validated();
    ...

nicobleiler and others added 8 commits September 30, 2025 09:34
Adds a method `validated` similar to formRequest so you can simply define the rules, messages and attributes.

```
<?php

namespace App\Mcp\Requests;

use Laravel\Mcp\Request;

class QueryMCPRequest extends Request
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'query' => 'required|string',
            'page' => 'nullable|page',
            'pageSize' => 'nullable|page_size',
        ];
    }
}
```

```
    ...
    public function handle(QueryMCPRequest $request): Response
    {
        $validated = $request->validated();
    ...
```
@nicobleiler
Copy link
Author

What am I missing to pass code coverage?

@taylorotwell
Copy link
Member

We would need to think through this more thoroughly regarding auto-validation like form requests, etc.

@nicobleiler
Copy link
Author

Alright, thanks for the quick response.

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