Skip to content

Add MCP Client#149

Draft
pushpak1300 wants to merge 3 commits intomainfrom
add_mcp_client
Draft

Add MCP Client#149
pushpak1300 wants to merge 3 commits intomainfrom
add_mcp_client

Conversation

@pushpak1300
Copy link
Member

@pushpak1300 pushpak1300 commented Feb 10, 2026

Usage

1. Configure a server connection

In config/mcp.php:

'servers' => [
    'example' => [
        'transport' => 'stdio',
        'command' => 'php',
        'args' => ['artisan', 'mcp:start', 'example'],
        'timeout' => 30,
        'cache_ttl' => 300,
    ],
    'remote' => [
        'transport' => 'http',
        'url' => 'https://example.com/mcp',
        'headers' => ['Authorization' => 'Bearer token'],
        'timeout' => 30,
    ],
],

2. Fetch tools

use Laravel\Mcp\Facades\Mcp;

$client = Mcp::client('example');

$tools = $client->tools(); // Collection<int, ClientTool>

foreach ($tools as $tool) {
    $tool->name();              // 'say-hi'
    $tool->description();       // 'Says hello'
    $tool->title();             // 'Say Hi'
    $tool->remoteInputSchema(); // input schema array
}

3. Call a tool

$result = $client->callTool('say-hi', ['name' => 'World']);
// ['content' => [['type' => 'text', 'text' => 'Hello, World!']], 'isError' => false]

4. Other client methods

$client->serverInfo();         // ['name' => '...', 'version' => '...']
$client->serverCapabilities(); // ['tools' => [...]]
$client->isConnected();        // bool
$client->clearCache();         // clears cached tool list
$client->disconnect();         // disconnect from server

5. Protocol version

The client sends protocol_version during the initialize handshake. Defaults to '2025-11-25'. Override in config:

'protocol_version' => '2025-06-18',

@stuartbrameld
Copy link

@pushpak1300 This is fantastic! We're in the marketing analytics space where GA, PostHog, Amplitude, MS Clarity etc all have first-party MCP servers and we need our Laravel app to be able to discover and call their tools directly. This opens up tonnes of potential for AI agent orchestration on Laravel ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments