PHP code example of nixphp / mcp

1. Go to this page and download the library: Download nixphp/mcp 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/ */

    

nixphp / mcp example snippets


return [
    'mcp' => [
        'auth' => [
            'enabled' => true,
            'driver' => 'file',
            'token_file' => BASE_PATH . '/storage/mcp/tokens.json',
        ],
    ],
];

'mcp' => [
    'auth' => [
        'enabled' => false,
    ],
],

use function NixPHP\MCP\tokens;

$created = tokens()->create('Local AI client', ['*']);

echo $created->plainToken; // shown once, only the hash is stored

use NixPHP\MCP\Tools\ScopedToolInterface;
use NixPHP\MCP\Tools\ToolInterface;

final class ArticleSearchTool implements ToolInterface, ScopedToolInterface
{
    public function 

use NixPHP\MCP\Support\Schema;
use NixPHP\MCP\Tools\ToolInterface;

final class GetFolderSize implements ToolInterface
{
    public function name(): string
    {
        return 'get_folder_size';
    }

    public function description(): string
    {
        return 'Returns the size of a folder.';
    }

    public function inputSchema(): array
    {
        return Schema::object()
            ->description($this->description())
            ->additionalProperties(false)
            ->prop('path', Schema::string()->description('Relative folder path'))
            ->

$this->store->read('tools/get_folder_size/cache.json');
$this->store->write('tools/get_folder_size/cache.json', $json);

POST /mcp