Skip to content

Laravel MCP tool responses causes validation error due to Response::structured() returning a ResponseFactory instead of Response #788

@schaeferalex

Description

@schaeferalex

When defining a Laravel MCP tool using the laravel/mcp package, tool calls that return structured responses fail validation in Prism.

public function handle(Request $request): Response
{
    $user = new User;
    $user->firstname = $request->get('firstname');
    $user->lastname = $request->get('lastname');
    $user->save();

    return Response::structured([
        'id' => $user->id,
    ]);
}
public function schema(JsonSchema $schema): array
{
    return [
        'firstname' => $schema->string()
            ->description('The firstname of the user.'),

        'lastname' => $schema->string()
            ->description('The lastname of the user.'),
    ];
}

Prism throws the following error when the tool is invoked:

Parameter validation error: Type mismatch. Expected: [firstname (RawSchema), lastname (RawSchema). 
Received: {"firstname":"John","lastname":"Doe"}. Please provide correct parameter types and names.

It appears that Response::structured() returns a ResponseFactory, not a Response. Prism’s LaravelMcpTool adapter, however, expects a Response. As a result, the adapter fails to process the output correctly, leading Prism to misinterpret the input parameters and throw a type-mismatch validation error.

As a temporary fix, if you change the return value to Response::json(), the tool call will work as expected.

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