1. Go to this page and download the library: Download routewise/laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
routewise / laravel example snippets
use Routewise\DefinedTool as T;
use Routewise\Field as F;
class InvoiceTools
{
public function all(): array
{
return [
T::make('invoices_list', 'read', 'List invoices, newest first. Filter by status.', [
'status' => F::enum(['draft', 'sent', 'paid']),
'limit' => F::int('How many to return')->min(1)->max(100)->default(20),
], fn (array $a) => Invoice::when($a['status'] ?? null, fn ($q, $s) => $q->where('status', $s))->latest()->limit($a['limit'])->get()),
T::make('invoice_delete', 'delete', 'Delete an invoice permanently.', ['id' => F::id('The invoice')->
Routewise::register(InvoiceTools::class);
class AppServer extends \Laravel\Mcp\Server
{
protected array $resources = [\Routewise\ResultView::class];
public function __construct(\Laravel\Mcp\Server\Contracts\Transport $transport)
{
parent::__construct($transport);
$this->tools = \Routewise\Routewise::tools();
}
}
#[AgentTool(description: 'Publish a draft post so readers can see it.', fields: ['post' => 'The post id'])]
public function publish(Post $post) { ... }
#[AgentTool(hidden: true)] // never listed
public function export() { ... }
// routewise/invoices.php
use Routewise\Behaviour\Scenario;
return [
Scenario::prompt('Delete invoice 42')->expects('invoice_delete', ['id' => 42]),
Scenario::prompt('Which invoices are unpaid?')
->expects('invoices_list', ['status' => 'unpaid'])
->never('invoice_delete'),
// A closure accepts more than one right answer.
Scenario::prompt('Show me what is overdue')
->expects('invoices_list', ['status' => fn ($status) => in_array($status, ['unpaid', 'overdue'], true)]),
Scenario::prompt('Tell me a joke')->named('stays out of the tools')->expectsNoTool(),
];
bash
php artisan routewise:behaviour # exits 1 when a scenario fails, for CI
php artisan routewise:behaviour --filter=invoice
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.