PHP code example of ymwl / think8-mcp

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

    

ymwl / think8-mcp example snippets


return [
    // 内置工具开关
    'tools' => [
        'app_info'         => true,
        'routes'           => true,
        'schema'           => true,
        'db_connections'   => true,
        'commands'         => true,
        'logs'             => true,
        'last_error'       => true,
        'config'           => true,
        'execute_sql'      => true,
        'run_php'          => true,
        'format_code'      => true,
        'get_absolute_url' => true,
        'log_summary'      => true,
        'probe_http'       => true,
        'explain_url'      => true,
        'inspect_addon'    => true,
        'db_backup'        => true,
        'inspect_template' => true,
    ],

    // 自定义工具类(须实现 ymwl\think8mcp\MCP\Tools\ToolInterface)
    'custom_tools' => [],

    // HTTP 探测配置(probe_http 工具)
    'probe' => [
        'allowed_hosts' => [],   // 追加白名单 host(回环地址与解析到回环的本机域名始终放行)
        'timeout'       => 5,    // 请求总超时秒数
        'max_body'      => 3000, // 响应体最大展示字符数
    ],

    // 日志配置
    'logs' => [
        'path'      => runtime_path('log'),
        'max_lines' => 500,
    ],

    // 命令黑名单
    'commands' => [
        'forbidden' => ['serve', 'clear', 'optimize', 'build', 'mcp:serve'],
    ],

    // 高危工具开关(生产环境建议关闭)
    'security' => [
        'allow_execute_sql' => true,
        'allow_run_php'     => true,
    ],
];

'custom_tools' => [
    \app\mcp\AddonInfoTool::class,
],

namespace app\mcp;

use think\App;
use ymwl\think8mcp\MCP\Tools\ToolInterface;

class AddonInfoTool implements ToolInterface
{
    public function __construct(private App $app) {}

    public function getName(): string
    {
        return 'get_addon_info';
    }

    // ... 其余接口方法
}
bash
cp vendor/ymwl/think8-mcp/config/mcp.php config/mcp.php
bash
php think mcp:install