PHPackages                             redberry/mcp-client-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. redberry/mcp-client-laravel

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

redberry/mcp-client-laravel
===========================

Package that enables you access to any mcp server that you define in the config

v1.1.1(1mo ago)1388.1k—2.4%3[2 issues](https://github.com/RedberryProducts/mcp-client-laravel/issues)1MITPHPPHP ^8.3||^8.4||^8.5CI passing

Since Sep 29Pushed 1mo agoCompare

[ Source](https://github.com/RedberryProducts/mcp-client-laravel)[ Packagist](https://packagist.org/packages/redberry/mcp-client-laravel)[ Docs](https://github.com/redberryproducts/mcp-client-laravel)[ GitHub Sponsors](https://github.com/Redberry)[ RSS](/packages/redberry-mcp-client-laravel/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (3)Dependencies (25)Versions (17)Used By (1)

MCP Client for Laravel
======================

[](#mcp-client-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e9ab87b8349d2c69d216cfc3e9c2fe5674a1b47f23014747b2e70a9f11d4dff3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72656462657272792f6d63702d636c69656e742d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/redberry/mcp-client-laravel)[![GitHub Tests Action Status](https://camo.githubusercontent.com/c72b862d20e515b61c208454a6803c5ea45735faa50c7d19026ed84eb38af42c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f726564626572727970726f64756374732f6d63702d636c69656e742d6c61726176656c2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/redberryproducts/mcp-client-laravel/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/3048793253ddc8bfd5c9aeedd2c3577d01ab0aa3c35543702456074ecdd225ff/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f726564626572727970726f64756374732f6d63702d636c69656e742d6c61726176656c2f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/redberryproducts/mcp-client-laravel/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/56d2969a1c2f9b51a6f91f9132bc7bd43049806dafbfe963aa4cf40b94936ddf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72656462657272792f6d63702d636c69656e742d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/redberry/mcp-client-laravel)

A Laravel client for the [Model Context Protocol](https://modelcontextprotocol.io/). It speaks JSON-RPC 2.0 over both [Streamable HTTP](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http) (`2025-03-26`) and STDIO, and exposes a single facade for listing and calling tools and reading resources. The HTTP transport content-negotiates with the server on every request, so you receive the final result whether the server replies with one JSON object or a stream of server-sent events.

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require redberry/mcp-client-laravel
```

Then publish the configuration file:

```
php artisan vendor:publish --tag="mcp-client-config"
```

This will create a `config/mcp-client.php` file in your application.

Configuration
-------------

[](#configuration)

The `mcp-client.servers` array maps a server name to its connection details. Each server uses one of two transports — `HTTP` for remote servers, `STDIO` for local subprocesses:

```
use Redberry\MCPClient\Enums\Transporters;

return [
    'servers' => [
        'github' => [
            'type'     => Transporters::HTTP,
            'base_url' => 'https://api.githubcopilot.com/mcp',
            'token'    => env('GITHUB_API_TOKEN'),
            'timeout'  => 30,
        ],

        'memory' => [
            'type'    => Transporters::STDIO,
            'command' => ['npx', '-y', '@modelcontextprotocol/server-memory'],
            'cwd'     => base_path(),
        ],
    ],
];
```

### HTTP Transport

[](#http-transport)

The HTTP transport implements MCP's [Streamable HTTP transport](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http). On the first request, it performs the `initialize` handshake and captures the `mcp-session-id` for the rest of the session. If the server later signals that the session has expired with an HTTP `404`, the client clears its session, re-handshakes, and retries the call once.

KeyDefaultDescription`base_url`—The MCP endpoint URL.`token``null`Bearer token; sent as `Authorization: Bearer {token}` when present.`timeout``30`Connection timeout in seconds.`read_timeout``60`Maximum gap between SSE chunks before the parser aborts a wedged stream. The clock resets on every chunk. Set to `null` to disable.`max_session_retries``1`Automatic retries after a session-loss `404`. Set to `0` to disable.`headers``[]`Additional headers merged into every request.`id_type``'int'``'int'` or `'string'`; controls how JSON-RPC ids are cast.### STDIO Transport

[](#stdio-transport)

The STDIO transport launches the configured command as a subprocess and exchanges newline-delimited JSON-RPC over its standard streams. The subprocess starts lazily on the first call and is reused for every subsequent request.

KeyDefaultDescription`command`—Array of command parts to launch.`cwd``null`Working directory for the subprocess.`env``null`Environment variables, merged on top of the parent environment.`inherit_env``true`When `false`, the subprocess receives only the keys listed in `env`.`request_timeout``30`Per-call wait for a JSON-RPC response, in seconds. Falls back to the legacy `timeout` key when only that is set.`process_timeout``null`Symfony Process kill timer, in seconds. Set this only if you need a hard upper bound on the subprocess lifetime.`startup_delay``100`Milliseconds to wait after `Process::start()` before sending the `initialize` handshake. Increase if a cold-start `npx -y …` is still booting when the handshake fires.`poll_interval``20`Milliseconds between reads of the subprocess output buffer.> **Note.** The STDIO transport does not work under `php artisan serve`. The built-in PHP development server tears down its worker between requests, which kills the long-running subprocess. Run your application via Octane, a queue worker, Sail, or Valet to use STDIO servers.

Connecting to a Server
----------------------

[](#connecting-to-a-server)

Resolve the client and call `connect` with a server name from your configuration:

```
use Redberry\MCPClient\Facades\MCPClient;

$github = MCPClient::connect('github');
```

The container binds the client as a singleton and aliases the `Redberry\MCPClient\Contracts\MCPClient` interface to it, so the facade and dependency injection on the contract resolve the same instance:

```
use Redberry\MCPClient\Contracts\MCPClient;

class GithubToolService
{
    public function __construct(private MCPClient $client) {}

    public function tools()
    {
        return $this->client->connect('github')->tools();
    }
}
```

`connect` returns a per-server clone of the client, so you may hold handles to multiple servers at once without one routing through another:

```
$github = MCPClient::connect('github');
$memory = MCPClient::connect('memory');

$github->tools();
$memory->tools();
```

Repeated `connect` calls for the same server reuse a cached transporter, so the `initialize` handshake is paid once per server per root instance.

Listing Tools and Resources
---------------------------

[](#listing-tools-and-resources)

The `tools` and `resources` methods return a `Collection` of associative arrays:

```
$tools = $github->tools();

$tools->all();                          // raw array
$tools->only('search', 'create_issue'); // by name
$tools->except('delete_repository');    // by name
$tools->map(fn ($tool) => $tool['name']);
```

The same `Collection` wraps both lists, but `only` and `except` know which key to filter on — `name` for tools and `uri` for resources.

Calling a Tool
--------------

[](#calling-a-tool)

Pass the tool name and an associative array of arguments. The method returns the decoded JSON-RPC `result` array:

```
$result = $github->callTool('create_issue', [
    'owner' => 'laravel',
    'repo'  => 'framework',
    'title' => 'Documentation feedback',
    'body'  => '…',
]);
```

Reading a Resource
------------------

[](#reading-a-resource)

Pass the URI of the resource. The method returns the decoded JSON-RPC `result` array:

```
$result = $github->readResource('file:///project/src/main.rs');
```

Streaming Events
----------------

[](#streaming-events)

Both `callTool` and `readResource` accept an optional callback as the last argument. When the server replies with an SSE stream, the callback is invoked for every decoded JSON-RPC message — progress notifications, log entries, partial results, and the final result-bearing one — as each arrives. The call still blocks until the final result is returned:

```
$result = $github->callTool('long_running_task', $args, function (array $event) {
    Log::info('mcp event', $event);
});
```

The callback is invoked zero times when the server replies with a single JSON object, so it is safe to pass unconditionally. Streaming is an HTTP-only concept; the callback is a no-op under the STDIO transport.

Custom Transports
-----------------

[](#custom-transports)

The package ships with HTTP and STDIO transports, and the IO seam is a single interface — `Redberry\MCPClient\Core\Transporters\Transporter`. To add another, implement the interface, register a case on `Redberry\MCPClient\Enums\Transporters`, and add a `match` arm to `TransporterFactory::make`. See [`ARCHITECTURE.md`](ARCHITECTURE.md) and [`.claude/rules/transporters.md`](.claude/rules/transporters.md) for the full contract.

Testing
-------

[](#testing)

```
composer test
```

Upgrading
---------

[](#upgrading)

Upgrading from `1.x` to `2.x`? See [`UPGRADE.md`](UPGRADE.md) for the migration guide.

Changelog
---------

[](#changelog)

See [`CHANGELOG.md`](CHANGELOG.md) for the list of changes.

Contributing
------------

[](#contributing)

See [`CONTRIBUTING.md`](CONTRIBUTING.md) for guidelines.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) before reporting a vulnerability.

Credits
-------

[](#credits)

- [Nika Jorjoliani](https://github.com/nikajorjika)
- [All Contributors](../../contributors)

Built and maintained by [Redberry](https://redberry.international/?utm_source=github&utm_medium=github_mcp_readme&utm_campaign=AI+service+campaign), a Diamond-tier Laravel partner. We also run a [5-week AI agent PoC sprint](https://redberry.international/ai-agent-development/?utm_source=github&utm_medium=github_mcp_readme&utm_campaign=AI+service+campaign) for teams exploring agentic features in Laravel.

License
-------

[](#license)

The MIT License (MIT). Please see [`LICENSE.md`](LICENSE.md) for more information.

###  Health Score

54

—

FairBetter than 96% of packages

Maintenance86

Actively maintained with recent releases

Popularity41

Moderate usage in the ecosystem

Community15

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 88.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~55 days

Total

5

Last Release

56d ago

Major Versions

v1.1.0 → v2.0.0-rc.12026-05-05

PHP version history (2 changes)v1.0.0PHP ^8.3||^8.4

v2.0.0-rc.1PHP ^8.3||^8.4||^8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/d2ceddc163a8c821d012238fe8f5439bd018bcd3036368c373eb397a19acfe7b?d=identicon)[Redberry LTD](/maintainers/Redberry%20LTD)

---

Top Contributors

[![nikajorjika](https://avatars.githubusercontent.com/u/4212052?v=4)](https://github.com/nikajorjika "nikajorjika (156 commits)")[![MaestroError](https://avatars.githubusercontent.com/u/46760939?v=4)](https://github.com/MaestroError "MaestroError (14 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (6 commits)")

---

Tags

agent-integrationai-agentsai-frameworkchatbotcontextlaravellaravel-ailaravel-packagellmmcpmcp-clientmemoryopenaiphpprompt-engineeringredberrytoolslaravelredberrymcp-client-laravel

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/redberry-mcp-client-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/redberry-mcp-client-laravel/health.svg)](https://phpackages.com/packages/redberry-mcp-client-laravel)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

329530.5k29](/packages/codewithdennis-filament-select-tree)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

124603.0k](/packages/worksome-exchange)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[tarfin-labs/event-machine

Event-driven state machines for Laravel with event sourcing, type-safe context, and full audit trail.

199.4k](/packages/tarfin-labs-event-machine)[tapp/filament-form-builder

User facing form builder using Filament components

132.4k3](/packages/tapp-filament-form-builder)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
