Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ php artisan make:mcp-tool ExampleTool
Your tools can request arguments from the MCP client using a tool input schema:

```php
public function schema(ToolInputSchema $schema): ToolInputSchema
{
$schema->string('iso_country_code')
->description('2 character country code')
->required();
use Illuminate\JsonSchema\JsonSchema;

return $schema;
public function schema(JsonSchema $schema): array
{
return [
'name' => $schema->string()
->description('The name of the user')
->required(),
];
}
```

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"illuminate/http": "^10.0|^11.0|^12.0",
"illuminate/routing": "^10.0|^11.0|^12.0",
"illuminate/support": "^10.0|^11.0|^12.0",
"illuminate/validation": "^10.0|^11.0|^12.0"
"illuminate/validation": "^10.0|^11.0|^12.0",
"illuminate/json-schema": "^12.28"
},
"require-dev": {
"laravel/pint": "^1.20",
Expand Down
13 changes: 9 additions & 4 deletions src/Server/Tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use Generator;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\JsonSchema\JsonSchema;
use Illuminate\Support\Str;
use Laravel\Mcp\Server\Tools\ToolInputSchema;
use Laravel\Mcp\Server\Tools\ToolNotification;
use Laravel\Mcp\Server\Tools\ToolResult;
use ReflectionClass;
Expand All @@ -21,9 +21,12 @@ public function name(): string
return Str::kebab(class_basename($this));
}

public function schema(ToolInputSchema $schema): ToolInputSchema
/**
`* Get the tool input schema.
*/
public function schema(JsonSchema $schema): array
{
return $schema;
return [];
}

public function description(): string
Expand Down Expand Up @@ -53,7 +56,9 @@ public function toArray(): array
return [
'name' => $this->name(),
'description' => $this->description(),
'inputSchema' => $this->schema(new ToolInputSchema)->toArray(),
'inputSchema' => JsonSchema::object(
fn (JsonSchema $schema) => $this->schema($schema),
)->toArray(),
'annotations' => $this->annotations() ?: (object) [],
];
}
Expand Down
157 changes: 0 additions & 157 deletions src/Server/Tools/ToolInputSchema.php

This file was deleted.

14 changes: 7 additions & 7 deletions stubs/tool.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace {{ namespace }};

use Generator;
use Illuminate\JsonSchema\JsonSchema;
use Laravel\Mcp\Server\Tools\Annotations\Title;
use Laravel\Mcp\Server\Tool;
use Laravel\Mcp\Server\Tools\ToolInputSchema;
use Laravel\Mcp\Server\Tools\ToolResult;

#[Title('{{ title }}')]
Expand All @@ -27,12 +27,12 @@ class {{ class }} extends Tool
/**
* Get the tool's input schema.
*/
public function schema(ToolInputSchema $schema): ToolInputSchema
public function schema(JsonSchema $schema): array
{
$schema->string('example')
->description('An example input description.')
->required();

return $schema;
return [
'example' => $schema->string()
->description('An example input description.')
->required(),
];
}
}
10 changes: 7 additions & 3 deletions tests/Fixtures/ExampleTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@

use Generator;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\JsonSchema\JsonSchema;
use Illuminate\Support\MessageBag;
use Illuminate\Validation\ValidationException;
use Laravel\Mcp\Server\Tool;
use Laravel\Mcp\Server\Tools\ToolInputSchema;
use Laravel\Mcp\Server\Tools\ToolResult;
use Mockery;

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

public function schema(ToolInputSchema $schema): ToolInputSchema
public function schema(JsonSchema $schema): array
{
return $schema->string('name')->description('The name of the person to greet')->required();
return [
'name' => $schema->string()
->description('The name of the person to greet')
->required(),
];
}

public function handle(array $arguments): ToolResult|Generator
Expand Down
12 changes: 7 additions & 5 deletions tests/Fixtures/StreamingTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
namespace Tests\Fixtures;

use Generator;
use Illuminate\JsonSchema\JsonSchema;
use Laravel\Mcp\Server\Tool;
use Laravel\Mcp\Server\Tools\ToolInputSchema;
use Laravel\Mcp\Server\Tools\ToolNotification;
use Laravel\Mcp\Server\Tools\ToolResult;

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

public function schema(ToolInputSchema $schema): ToolInputSchema
public function schema(JsonSchema $schema): array
{
return $schema->integer('count')
->description('Number of messages to stream.')
->required();
return [
'count' => $schema->integer()
->description('Number of messages to stream.')
->required(),
];
}

public function handle(array $arguments): Generator
Expand Down
3 changes: 1 addition & 2 deletions tests/Unit/Methods/ListToolsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
eval("
namespace Tests\\Unit\\Methods;
use Generator;
use Illuminate\JsonSchema\JsonSchema;
use Laravel\\Mcp\\Server\\Tool;
use Laravel\\Mcp\\Server\\Tools\\ToolResult;
use Laravel\\Mcp\\Server\\Tools\\ToolInputSchema;
class DummyTool{$i} extends Tool {
public function description(): string { return 'Description for dummy tool {$i}'; }
public function schema(ToolInputSchema \$schema): ToolInputSchema { return \$schema; }
public function handle(array \$arguments): ToolResult|Generator { return []; }
}
");
Expand Down
Loading