1. Go to this page and download the library: Download organiseyou/mcp-server 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/ */
use OrganiseYou\McpServer\Facades\Mcp;
// Single tool
Mcp::tool('add_numbers')
->description('Add two numbers together and return the sum.')
->inputSchema([
'type' => 'object',
'properties' => [
'a' => ['type' => 'number', 'description' => 'First operand.'],
'b' => ['type' => 'number', 'description' => 'Second operand.'],
],
'
// In a tenant boot hook or middleware
foreach ($tenant->enabledDataSources() as $source) {
Mcp::tool("query_{$source->slug}")
->description("Query the {$source->name} dataset. " . $source->description)
->inputSchema($source->buildInputSchema())
->handle(fn (array $input) => $source->query($input));
}
namespace App\Mcp\Tools;
use App\Models\Order;
use OrganiseYou\McpServer\Contracts\McpTool;
class GetOrderTool implements McpTool
{
public function __construct(private OrderRepository $orders) {}
public function name(): string
{
return 'get_order';
}
public function description(): string
{
return 'Retrieve an order by its ID, including line items and shipping status.';
}
public function inputSchema(): array
{
return [
'type' => 'object',
'properties' => [
'order_id' => [
'type' => 'integer',
'description' => 'The ID of the order to retrieve.',
],
],
'
use OrganiseYou\McpServer\ToolContext;
Mcp::tool('list_fields')
->handle(function (array $input, ToolContext $context) {
// $context->requestId — the JSON-RPC id of this call
// $context->actor — whatever your app put there (a user, a tenant, …)
// $context->scopes — string[]
// $context->attributes — anything else, opaque to the package
return $context->hasScope('metadata:read') ? $this->fields() : [];
});
use OrganiseYou\McpServer\Exceptions\ToolError;
throw new ToolError('forbidden', 'You cannot edit this model.');
// → {"content":[{"type":"text","text":"{\"reason\":\"forbidden\",\"message\":\"You cannot edit this model.\"}"}],"isError":true}