Skip to content

Commit 4e1389e

Browse files
Add Macroable and Conditionable traits to some core classes (#76)
* Add Macroable and Conditionable traits to core classes - Applied `Macroable` and `Conditionable` traits to: - `Request` - `Response` - `TestResponse` - Verified support via new tests for: - Custom macro methods (`->foo()`) - `when()` and `unless()` conditional method chaining - Added trait tests for prompt, resource, and tool responses in: - `TestResponseTraitsTest` for Prompts, Resources, Tools - `RequestTest` and `ResponseTest` unit coverage * Remove redundant tests
1 parent 2733c4c commit 4e1389e

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/Request.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@
88
use Illuminate\Contracts\Auth\Authenticatable;
99
use Illuminate\Contracts\Support\Arrayable;
1010
use Illuminate\Support\Facades\Validator;
11+
use Illuminate\Support\Traits\Conditionable;
1112
use Illuminate\Support\Traits\InteractsWithData;
13+
use Illuminate\Support\Traits\Macroable;
1214
use Illuminate\Validation\ValidationException;
1315

1416
/**
1517
* @implements Arrayable<string, mixed>
1618
*/
1719
class Request implements Arrayable
1820
{
21+
use Conditionable;
1922
use InteractsWithData;
23+
use Macroable;
2024

2125
/**
2226
* @param array<string, mixed> $arguments

src/Response.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Laravel\Mcp;
66

7+
use Illuminate\Support\Traits\Conditionable;
8+
use Illuminate\Support\Traits\Macroable;
79
use JsonException;
810
use Laravel\Mcp\Enums\Role;
911
use Laravel\Mcp\Exceptions\NotImplementedException;
@@ -14,6 +16,9 @@
1416

1517
class Response
1618
{
19+
use Conditionable;
20+
use Macroable;
21+
1722
protected function __construct(
1823
protected Content $content,
1924
protected Role $role = Role::USER,

src/Server/Testing/TestResponse.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use Illuminate\Container\Container;
88
use Illuminate\Contracts\Auth\Authenticatable;
9+
use Illuminate\Support\Traits\Conditionable;
10+
use Illuminate\Support\Traits\Macroable;
911
use Laravel\Mcp\Server\Primitive;
1012
use Laravel\Mcp\Server\Prompt;
1113
use Laravel\Mcp\Server\Resource;
@@ -16,6 +18,9 @@
1618

1719
class TestResponse
1820
{
21+
use Conditionable;
22+
use Macroable;
23+
1924
protected JsonRpcResponse $response;
2025

2126
/**

0 commit comments

Comments
 (0)