redberry / mcp-client-laravel
Package that enables you access to any mcp server that you define in the config
Fund package maintenance!
Redberry
Installs: 10 645
Dependents: 1
Suggesters: 0
Security: 0
Stars: 13
Watchers: 0
Forks: 0
Open Issues: 6
pkg:composer/redberry/mcp-client-laravel
Requires
- php: ^8.3||^8.4
- illuminate/contracts: ^10.0||^11.0||^12.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.0.0||^9.0.0||^8.22.0
- pestphp/pest: ^2.0||^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.3||^2.0
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
- spatie/laravel-ray: ^1.35
- dev-main
- v1.1.0
- v1.0.0
- dev-dependabot/github_actions/actions/checkout-6
- dev-copilot/add-connection-transporter-pooling
- dev-headers-url-and-fixes
- dev-feat/add-tool-call
- dev-codex/add-test-cases-for-stdio-and-httptransporter
- dev-codex/create-mcpclient-artisan-commands
- dev-feat/add-new-feat-request-template
This package is auto-updated.
Last update: 2025-12-02 12:13:14 UTC
README
Laravel-native client for Model Context Protocol (MCP) servers
Built and maintained by Redberry, a Diamond-tier official Laravel partner.
🚀 What is This?
This package provides a Laravel-native client for interacting with Model Context Protocol (MCP) servers — enabling your Laravel application to communicate with external tools, structured resources, and memory services in a standardized way.
It is framework-agnostic and can be used in any Laravel application. Agent frameworks like LarAgent use this package internally to enable tool use, memory management, and reasoning across distributed contexts.
Use it to:
- Connect to any MCP-compliant server over HTTP or STDIO
- Discover and call tools defined on MCP servers
- Access structured memory and contextual resources
- Extend your Laravel apps with AI-ready interfaces to external agents or toolchains
🚀 Looking to build an AI agent in Laravel? Talk to us about our 5-week PoC sprint — from idea to working prototype.
Installation
Note that while project is running with php artisan serve STDIO transporter doesn't work
You can install the package via composer:
composer require redberry/mcp-client-laravel
After installation, 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
The published configuration file contains settings for your MCP servers. Here's an example configuration:
return [ 'servers' => [ 'github' => [ 'type' => \Redberry\MCPClient\Enums\Transporters::HTTP, 'base_url' => 'https://api.githubcopilot.com/mcp', 'timeout' => 30, 'token' => env('GITHUB_API_TOKEN', null), ], 'npx_mcp_server' => [ 'type' => \Redberry\MCPClient\Enums\Transporters::STDIO, 'command' => [ 'npx', '-y', '@modelcontextprotocol/server-memory', ], 'timeout' => 30, 'cwd' => base_path(), ], ], ];
Configuration Options
HTTP Transporter
type: Set toRedberry\MCPClient\Enums\Transporters::HTTPfor HTTP connectionsbase_url: The base URL of the MCP servertimeout: Request timeout in secondstoken: Authentication token (if required)
STDIO Transporter
type: Set toRedberry\MCPClient\Enums\Transporters::STDIOfor STDIO connectionscommand: Array of command parts to execute the MCP servertimeout: Command timeout in secondscwd: Current working directory for the command
Usage
Basic Usage
use Redberry\MCPClient\Facades\MCPClient; // Connect to a specific MCP server defined in your config $client = MCPClient::connect('github'); // Get available tools from the MCP server $tools = $client->tools(); // Get available resources from the MCP server $resources = $client->resources();
Using Dependency Injection
use Redberry\MCPClient\MCPClient; class MyService { public function __construct(private MCPClient $mcpClient) { } public function getToolsFromGithub() { return $this->mcpClient->connect('github')->tools(); } }
Working with Collections
The tools() and resources() methods return a Collection object that provides helpful methods for working with the results:
// Get all tools as an array $allTools = $client->tools()->all(); // Get only specific tools by name $specificTools = $client->tools()->only('tool1', 'tool2'); // Exclude specific tools $filteredTools = $client->tools()->except('tool3'); // Map over tools $mappedTools = $client->tools()->map(function ($tool) { return $tool['name']; });
Call tools
The callTool method is used to execute specific tool. Here is the signature:
public function callTool(string $toolName, mixed $params = []): mixed;
Example:
$result = $client->callTool('create_entities', [ 'entities' => [ [ 'name' => 'John Doe', 'entityType' => 'PERSON', 'observations' => ['Test observation 1', 'Test observation 2'], ] ], ]);
Read Resources
The readResource method is used to retrieve the resource by the uri.
public function readResource(string $uri): mixed;
Example:
$result = $client->readResource("file:///project/src/main.rs");
Advanced Usage
Creating Custom Transporters
If you need to create a custom transporter, you can extend the Transporter interface and implement your own transport mechanism. Then register it in the TransporterFactory.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.