adachsoft / mcp-client-lib
Model Context Protocol (MCP) client implementation over Streamable HTTP transport.
v0.1.0
2026-11-27 22:11 UTC
Requires
- php: >=8.3
- adachsoft/http-transport: ^0.2 || ^0.3
- adachsoft/mcp-contracts: ^0.1
- guzzlehttp/guzzle: ^7.9
Requires (Dev)
- adachsoft/php-code-style: ^0.7.4
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^12.4
- rector/rector: ^2.9
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
adachsoft/mcp-client-lib is a PHP 8.3+ client for the Model Context Protocol (MCP) over Streamable HTTP.
Main Features
- Initializes MCP sessions and caches them by server identifier.
- Lists server tools and calls a selected tool.
- Parses JSON and Server-Sent Events (SSE) responses.
- Re-establishes a session once when a request receives HTTP 404.
- Supports the default Guzzle-backed transport or an injected HTTP transport.
Requirements
- PHP 8.3 or newer.
- Composer for dependency installation.
Installation
composer require adachsoft/mcp-client-lib
Usage
Create a client with the default Guzzle-backed transport:
use AdachSoft\McpClientLib\Factory\McpStreamableHttpClientFactory;
use AdachSoft\McpContracts\Collection\McpHeaderCollection;
use AdachSoft\McpContracts\Dto\McpServerDto;
use AdachSoft\McpContracts\ValueObject\McpServerIdVo;
use AdachSoft\McpContracts\ValueObject\McpServerUrlVo;
$client = (new McpStreamableHttpClientFactory())->createDefault();
$server = new McpServerDto(
new McpServerIdVo('weather_server'),
new McpServerUrlVo('https://example.com/mcp'),
'Weather MCP server',
new McpHeaderCollection(),
30,
'2025-03-26',
);
$tools = $client->listTools($server);
$result = $client->callTool($server, 'get_weather', ['city' => 'London']);
The client negotiates and caches one MCP session per server identifier. A session is automatically re-established once when the server returns HTTP 404 for a request.
Testing
Run the package test suite from this directory:
vendor/bin/phpunit -c phpunit.xml
License
This library is released under the MIT License.