Repository navigation
Support for laravel/mcp #1141
Radiergummi
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
We are about to add an MCP server to our platform, using
laravel/mcp. Without going into the details, the MCP protocol provides a standardised HTTP JSON API to AI models and has a concept of Tools, aka. RPC. The way the Laravel MCP package works, tools are implemented as classes in the application with a handle method that receives a Request object and returns a Response—only that these two objects are MCP-specific and entirely separate from the usualIlluminate\Httpinstances.This means that, assuming you have functionality accessible both via your existing HTTP endpoints and MCP tools, request validation and domain logic gets duplicated between them: Form Requests cannot be used for MCP tools, and thus validation will have to be handled manually.
Now this is a perfect use case for
spatie/laravel-data: If both a controller and an MCP tool could be injected with a Data object, validation and request body access could be unified for both. This would require extending thebeforeResolvinghook for data classes like so:The reason being that an MCP tool call can still be an HTTP request, so
requestis still bound to the HTTP request object in the container, but doesn't contain the tool call parameters.I know this feels like too tight of an integration with another library, but given that it's a first-party library, this is probably going to be a wide-spread use case, and the fact that it isn't easy to override the behaviour, I'd argue it's okay here.
All reactions