redberry/mcp-client-laravel
Laravel client for the Model Context Protocol (MCP). Supports JSON-RPC 2.0 over Streamable HTTP (including SSE) and STDIO. Configure multiple servers and use a single facade to list/call tools and read resources, with per-request content negotiation.
MCPClient), transports (HTTP, STDIO), and contracts (MCPClient interface). This aligns well with Laravel’s dependency injection and service container patterns.MCPClient) and contract (Contracts\MCPClient) enable seamless integration into Laravel’s service container, reducing boilerplate for dependency injection.illuminate/contracts, orchestra/testbench), with zero framework conflicts (MIT license).php artisan vendor:publish, reducing manual setup.tools() and resources() as Laravel Collections, enabling fluent chaining (e.g., ->only(['search'])).callTool()/readResource() allows real-time processing of intermediate results (e.g., logging, progress tracking).| Risk Area | Mitigation Strategy |
|---|---|
| Transport Failures | HTTP: Automatic session recovery on 404 (configurable retries). STDIO: Lazy subprocess initialization. |
| Version Compatibility | Supports Laravel 10–13 and PHP 8.3–8.5. Backward compatibility noted in UPGRADE.md. |
| Performance | STDIO subprocesses persist across calls (efficient for repeated use). HTTP uses Guzzle under the hood. |
| Security | Token-based auth (Bearer) for HTTP; subprocess isolation for STDIO. No exposed sensitive data in defaults. |
| Testing | CI includes PHP 8.3/8.4/8.5, Laravel 11/12/13, and Pest/Testbench. Local testing via composer test. |
HttpTransporter), compatible with Laravel’s HTTP stack.composer require redberry/mcp-client-laravel
php artisan vendor:publish --tag="mcp-client-config"
HTTP (remote) or STDIO (local) servers in config/mcp-client.php.'servers' => [
'github' => [
'type' => Transporters::HTTP,
'base_url' => 'https://api.githubcopilot.com/mcp',
'token' => env('GITHUB_TOKEN'),
],
'local_agent' => [
'type' => Transporters::STDIO,
'command' => ['npx', '@modelcontextprotocol/server-memory'],
],
],
Redberry\MCPClient\Contracts\MCPClient into services:
public function __construct(private MCPClient $client) {}
$tools = $client->connect('github')->tools()->only(['search']);
$result = $client->connect('github')->callTool('create_issue', ['title' => 'Fix bug']);
$client->connect('github')->callTool('long_task', [], function (array $event) {
Log::info('MCP Event', $event);
});
| Component | Compatibility Notes |
|---|---|
| Laravel | Tested on 10–13; uses illuminate/contracts. |
| PHP | 8.3–8.5 (PHP 8.2 may need adjustments for typed properties). |
| Transports | HTTP: Guzzle-compatible. STDIO: Requires non-PHP CLI (e.g., Octane, queues). |
| Streaming | SSE-only for HTTP; STDIO uses newline-delimited JSON-RPC. |
| Error Handling | JSON-RPC errors mapped to Laravel exceptions (e.g., RuntimeException). |
MCPClient.process_timeout).UPGRADE.md).Process::getOutput().RuntimeException with context.| Scenario | Considerations |
|---|---|
| High Concurrency | STDIO: Subprocesses are reused but may hit OS limits. Use process_timeout. |
| Long-Running Calls | HTTP: SSE read_timeout (default: 60s) prevents wedged streams. |
| Multiple Servers | Cached transporters per server; no cross-server leakage. |
| Queue Workers | STDIO works if processes persist (e.g., Laravel Horizon with process_timeout). |
| Failure Type | Impact | Mitigation |
|---|---|---|
| HTTP 404 (Session) | Lost session; auto-retry (configurable). | Monitor max_session_retries. |
| STDIO Process Crash | Subprocess dies; lazy restart on next call. | Set process_timeout to kill hung processes. |
| Network Timeout |
How can I help you explore Laravel packages today?