Search by

adachsoft / mcp-client-lib

Arkadiusz Adach

Model Context Protocol (MCP) client implementation over Streamable HTTP transport.

Package info

gitlab.com/a.adach/mcp-client-lib

Issues

pkg:composer/adachsoft/mcp-client-lib

Statistics

Installs: 13

Dependents: 1

Suggesters: 0

Stars: 0

v0.1.0 2026-11-27 22:11 UTC

This package is auto-updated.

Last update: 2026-11-27 21:12:12 UTC


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.