Skip to content

Commit 7be319b

Browse files
authored
Merge pull request #26 from laravel/feat/essence
Refactors schema input
2 parents 8cf3c65 + 2722380 commit 7be319b

File tree

10 files changed

+41
-438
lines changed

10 files changed

+41
-438
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ php artisan make:mcp-tool ExampleTool
101101
Your tools can request arguments from the MCP client using a tool input schema:
102102

103103
```php
104-
public function schema(ToolInputSchema $schema): ToolInputSchema
105-
{
106-
$schema->string('iso_country_code')
107-
->description('2 character country code')
108-
->required();
104+
use Illuminate\JsonSchema\JsonSchema;
109105

110-
return $schema;
106+
public function schema(JsonSchema $schema): array
107+
{
108+
return [
109+
'name' => $schema->string()
110+
->description('The name of the user')
111+
->required(),
112+
];
111113
}
112114
```
113115

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"illuminate/http": "^10.0|^11.0|^12.0",
2525
"illuminate/routing": "^10.0|^11.0|^12.0",
2626
"illuminate/support": "^10.0|^11.0|^12.0",
27-
"illuminate/validation": "^10.0|^11.0|^12.0"
27+
"illuminate/validation": "^10.0|^11.0|^12.0",
28+
"illuminate/json-schema": "^12.28"
2829
},
2930
"require-dev": {
3031
"laravel/pint": "^1.20",

src/Server/Tool.php

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

77
use Generator;
88
use Illuminate\Contracts\Support\Arrayable;
9+
use Illuminate\JsonSchema\JsonSchema;
910
use Illuminate\Support\Str;
10-
use Laravel\Mcp\Server\Tools\ToolInputSchema;
1111
use Laravel\Mcp\Server\Tools\ToolNotification;
1212
use Laravel\Mcp\Server\Tools\ToolResult;
1313
use ReflectionClass;
@@ -21,9 +21,12 @@ public function name(): string
2121
return Str::kebab(class_basename($this));
2222
}
2323

24-
public function schema(ToolInputSchema $schema): ToolInputSchema
24+
/**
25+
`* Get the tool input schema.
26+
*/
27+
public function schema(JsonSchema $schema): array
2528
{
26-
return $schema;
29+
return [];
2730
}
2831

2932
public function description(): string
@@ -53,7 +56,9 @@ public function toArray(): array
5356
return [
5457
'name' => $this->name(),
5558
'description' => $this->description(),
56-
'inputSchema' => $this->schema(new ToolInputSchema)->toArray(),
59+
'inputSchema' => JsonSchema::object(
60+
fn (JsonSchema $schema) => $this->schema($schema),
61+
)->toArray(),
5762
'annotations' => $this->annotations() ?: (object) [],
5863
];
5964
}

src/Server/Tools/ToolInputSchema.php

Lines changed: 0 additions & 157 deletions
This file was deleted.

stubs/tool.stub

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace {{ namespace }};
44

55
use Generator;
6+
use Illuminate\JsonSchema\JsonSchema;
67
use Laravel\Mcp\Server\Tools\Annotations\Title;
78
use Laravel\Mcp\Server\Tool;
8-
use Laravel\Mcp\Server\Tools\ToolInputSchema;
99
use Laravel\Mcp\Server\Tools\ToolResult;
1010

1111
#[Title('{{ title }}')]
@@ -27,12 +27,12 @@ class {{ class }} extends Tool
2727
/**
2828
* Get the tool's input schema.
2929
*/
30-
public function schema(ToolInputSchema $schema): ToolInputSchema
30+
public function schema(JsonSchema $schema): array
3131
{
32-
$schema->string('example')
33-
->description('An example input description.')
34-
->required();
35-
36-
return $schema;
32+
return [
33+
'example' => $schema->string()
34+
->description('An example input description.')
35+
->required(),
36+
];
3737
}
3838
}

tests/Fixtures/ExampleTool.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@
44

55
use Generator;
66
use Illuminate\Contracts\Validation\Validator;
7+
use Illuminate\JsonSchema\JsonSchema;
78
use Illuminate\Support\MessageBag;
89
use Illuminate\Validation\ValidationException;
910
use Laravel\Mcp\Server\Tool;
10-
use Laravel\Mcp\Server\Tools\ToolInputSchema;
1111
use Laravel\Mcp\Server\Tools\ToolResult;
1212
use Mockery;
1313

1414
class ExampleTool extends Tool
1515
{
1616
protected string $description = 'This tool says hello to a person';
1717

18-
public function schema(ToolInputSchema $schema): ToolInputSchema
18+
public function schema(JsonSchema $schema): array
1919
{
20-
return $schema->string('name')->description('The name of the person to greet')->required();
20+
return [
21+
'name' => $schema->string()
22+
->description('The name of the person to greet')
23+
->required(),
24+
];
2125
}
2226

2327
public function handle(array $arguments): ToolResult|Generator

tests/Fixtures/StreamingTool.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
namespace Tests\Fixtures;
44

55
use Generator;
6+
use Illuminate\JsonSchema\JsonSchema;
67
use Laravel\Mcp\Server\Tool;
7-
use Laravel\Mcp\Server\Tools\ToolInputSchema;
88
use Laravel\Mcp\Server\Tools\ToolNotification;
99
use Laravel\Mcp\Server\Tools\ToolResult;
1010

1111
class StreamingTool extends Tool
1212
{
1313
protected string $description = 'A tool that streams multiple responses.';
1414

15-
public function schema(ToolInputSchema $schema): ToolInputSchema
15+
public function schema(JsonSchema $schema): array
1616
{
17-
return $schema->integer('count')
18-
->description('Number of messages to stream.')
19-
->required();
17+
return [
18+
'count' => $schema->integer()
19+
->description('Number of messages to stream.')
20+
->required(),
21+
];
2022
}
2123

2224
public function handle(array $arguments): Generator

tests/Unit/Methods/ListToolsTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
eval("
1212
namespace Tests\\Unit\\Methods;
1313
use Generator;
14+
use Illuminate\JsonSchema\JsonSchema;
1415
use Laravel\\Mcp\\Server\\Tool;
1516
use Laravel\\Mcp\\Server\\Tools\\ToolResult;
16-
use Laravel\\Mcp\\Server\\Tools\\ToolInputSchema;
1717
class DummyTool{$i} extends Tool {
1818
public function description(): string { return 'Description for dummy tool {$i}'; }
19-
public function schema(ToolInputSchema \$schema): ToolInputSchema { return \$schema; }
2019
public function handle(array \$arguments): ToolResult|Generator { return []; }
2120
}
2221
");

0 commit comments

Comments
 (0)