Skip to content

Add MCP Client#149

Draft
pushpak1300 wants to merge 7 commits into
mainfrom
add_mcp_client
Draft

Add MCP Client#149
pushpak1300 wants to merge 7 commits into
mainfrom
add_mcp_client

Conversation

@pushpak1300
Copy link
Copy Markdown
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
Copy Markdown

@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 ❤️

pushpak1300 and others added 2 commits April 20, 2026 16:26
# Conflicts:
#	config/mcp.php
#	src/Facades/Mcp.php
#	src/Server/Transport/JsonRpcResponse.php
@vinitkadam03
Copy link
Copy Markdown

will this help in integrating other MCPs in our mcp? like integrate some tools from some other mcp in our mcp tools ?

@SergkeiM
Copy link
Copy Markdown

@pushpak1300 thank you, this is the missing piece for MCP, do you plan to merge this soon?

How this integrates with Laravel ai sdk with agents?

@josephkerkhof
Copy link
Copy Markdown

josephkerkhof commented May 1, 2026

I'm getting an error when smoke testing this branch:

   TypeError 

  Laravel\Mcp\Client\Client::tools(): Return value must be of type Illuminate\Support\Collection, __PHP_Incomplete_Class returned

  at vendor/laravel/mcp/src/Client/Client.php:79
     75▕         $cacheKey = "mcp-client:{$this->name}:tools";
     76▕ 
     77▕         if ($this->cacheTtl !== null && Cache::has($cacheKey)) {
     78▕             /** @var Collection<int, ClientTool> */
  ➜  79▕             return Cache::get($cacheKey);
     80▕         }
     81▕ 
     82▕         $allTools = [];
     83▕         $cursor = null;

  1   app/Ai/Agents/FilesystemAgent.php:55
      Laravel\Mcp\Client\Client::tools()

  2   /Users/joseph/code/laravel/ai/src/Providers/Concerns/GeneratesText.php:63
      App\Ai\Agents\FilesystemAgent::tools()

I don't have this problem if I disable the cache, or the tool call is only used once (i.e., when the cache is filled). But if the tool call needs to be retrieved from the cache, I get this error.

Does it make sense to cache the raw tool definitions and rehydrate ClientTool on read?

# Conflicts:
#	src/Facades/Mcp.php
#	src/Server/McpServiceProvider.php
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.

5 participants