PHPackages                             swisnl/mcp-client - 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. swisnl/mcp-client

ActiveLibrary

swisnl/mcp-client
=================

Model Context Protocol client implementation in PHP

0.7.0(2mo ago)77.1k↑11.9%31MITPHPPHP ^8.2CI passing

Since Mar 31Pushed 1mo ago4 watchersCompare

[ Source](https://github.com/swisnl/mcp-client)[ Packagist](https://packagist.org/packages/swisnl/mcp-client)[ Docs](https://github.com/swisnl/mcp-client)[ GitHub Sponsors](https://github.com/swisnl)[ RSS](/packages/swisnl-mcp-client/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (18)Versions (18)Used By (1)

Model Context Protocol client implementation for PHP
====================================================

[](#model-context-protocol-client-implementation-for-php)

[![PHP from Packagist](https://camo.githubusercontent.com/6e81e758de2c82b087d0f15f1400d5cc03b8391b0e6ac53b83f42665ed399280/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f737769736e6c2f6d63702d636c69656e742e737667)](https://packagist.org/packages/swisnl/mcp-client)[![Latest Version on Packagist](https://camo.githubusercontent.com/3c478f96d645fec8ea82cb0502c0faec8fe796178366b1bc5cab32bb185313a6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737769736e6c2f6d63702d636c69656e742e737667)](https://packagist.org/packages/swisnl/mcp-client)[![Software License](https://camo.githubusercontent.com/602a2bd06276e1e182cc281783480fc353fb71727b03df282f999641ceddc45e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f737769736e6c2f6d63702d636c69656e742e737667)](LICENSE.md)[![Buy us a tree](https://camo.githubusercontent.com/195a3f79c3c2f91a69498ad26c1d8a7eeaf5771da0007200f409f5d438a515c4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54726565776172652d2546302539462538432542332d6c69676874677265656e2e737667)](https://plant.treeware.earth/swisnl/mcp-client)[![Build Status](https://camo.githubusercontent.com/85bc3a797b2a52724ef0743ea2515d837059f6549d931ec1239113b7e0313b5f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f737769736e6c2f6d63702d636c69656e742f72756e2d74657374732e796d6c3f6c6162656c3d7465737473266272616e63683d6d6173746572)](https://github.com/swisnl/mcp-client/actions/workflows/run-tests.yml)[![Made by SWIS](https://camo.githubusercontent.com/8c541545402619860a7346c32a176d63a2b75eb8ebb85590d06a26b62417d260/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2546302539462539412538302d6d6164652532306279253230535749532d2532333037333741392e737667)](https://www.swis.nl)

A PHP client library for interacting with Model Context Protocol (MCP) servers.

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

[](#installation)

You can install the package via composer:

```
composer require swisnl/mcp-client
```

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- [ReactPHP](https://reactphp.org/) packages

Features
--------

[](#features)

- Multiple transport mechanisms:
    - SSE (Server-Sent Events)
    - Stdio (Standard input/output)
    - Process (External process communication)
    - StreamableHttp (HTTP with session management)
- Promise-based API with ReactPHP
- PSR-3 Logger interface support
- Most of MCP protocol support (2025-03-26)
- Tool annotation support
- `_meta` support

Basic Usage
-----------

[](#basic-usage)

### SSE Transport

[](#sse-transport)

```
use Swis\McpClient\Client;

// Create client with SSE transporter
$endpoint = 'https://your-mcp-server.com/sse';
$client = Client::withSse(
    $endpoint,
    headers: ['Authorization' => 'Bearer your-token']
);

// Connect to the server
$client->connect(function($initResponse) {
    echo "Connected to server: " . json_encode($initResponse['serverInfo']) . "\n";
});

// List available tools
$tools = $client->listTools();
foreach ($tools->getTools() as $tool) {
    echo "- {$tool->getName()}: {$tool->getDescription()}\n";

    // Access tool annotations if available
    if ($annotations = $tool->getAnnotations()) {
        echo "  * Read-only: " . ($annotations->getReadOnlyHint() ? 'Yes' : 'No') . "\n";
        echo "  * Title: " . ($annotations->getTitle() ?? 'N/A') . "\n";
    }
}

// Call a tool
$result = $client->callTool('echo', ['message' => 'Hello World!']);
echo $result->getResult() . "\n";
```

### Process Transport

[](#process-transport)

```
use Swis\McpClient\Client;

// Create client with a process transporter
[$client, $process] = Client::withProcess('/path/to/mcp-server/binary');

// Connect to the server
$client->connect();

// Use the client...

// Disconnect when done
$client->disconnect();
```

### StreamableHttp Transport

[](#streamablehttp-transport)

```
use Swis\McpClient\Client;

// Create client with StreamableHttp transporter
$endpoint = 'https://your-mcp-server.com/';
$client = Client::withStreamableHttp(
    $endpoint,
    headers: ['Authorization' => 'Bearer your-token']
);

// Connect to the server
$client->connect();

// The transporter will automatically manage session IDs from the Mcp-Session-Id header

// Use the client...

// Disconnect when done
$client->disconnect();
```

Use in combination with Agents SDK
----------------------------------

[](#use-in-combination-with-agents-sdk)

First, install Agents SDK

```
composer require swisnl/agents-sdk
```

```
use Swis\Agents\Agent;
use Swis\Agents\Mcp\McpConnection;
use Swis\McpClient\Client;
use Swis\Agents\Orchestrator;

$agent = new Agent(
    name: 'Calculator Agent',
    description: 'This Agent can perform arithmetic operations.',
    mcpConnections: [
        new MathMcpConnection(),
    ]
);

$orchestrator = new Orchestrator($agent);
echo $orchestrator
        ->withUserInstruction('What\'s 5 + 5?')
        ->run($agent)

class MathMcpConnection extends McpConnection
{
    public function __construct()
    {
        [$client, $process] = Client::withProcess(
            command: 'node ' . realpath(__DIR__ . '/node_modules/math-mcp/build/index.js'),
        );

        parent::__construct(
            client: $client,
            name: 'Math MCP',
        );
    }
}
```

Advanced Usage
--------------

[](#advanced-usage)

### Metadata

[](#metadata)

You can send metadata using the `_meta` parameter:

```
use Swis\McpClient\Requests\CallToolRequest

$request = new CallToolRequest('search');
$request->withMeta(['traceparent' => '0000-0000-00-00x']);
```

### Custom Transporter

[](#custom-transporter)

You can implement your own transporter by implementing the `TransporterInterface`:

```
use Swis\McpClient\TransporterInterface;
use Swis\McpClient\EventDispatcher;

class CustomTransporter implements TransporterInterface
{
    // Implement required methods
}

// Create a client with your custom transporter
$transporter = new CustomTransporter();
$eventDispatcher = new EventDispatcher();
$client = new Client($transporter, $eventDispatcher);
```

### Async Operations

[](#async-operations)

The client supports async operations using ReactPHP promises:

```
$client->sendRequest(new ListToolsRequest())->then(...);
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

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

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Joris Meijer](https://github.com/jormeijer)
- [All Contributors](../../contributors)

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/swisnl/mcp-client) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

SWIS ❤️ Open Source
-------------------

[](#swis-heart-open-source)

[SWIS](https://www.swis.nl) is a web agency from Leiden, the Netherlands. We love working with open source software.

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance88

Actively maintained with recent releases

Popularity33

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 65.7% 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 ~33 days

Recently: every ~14 days

Total

11

Last Release

77d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8734305?v=4)[SWIS](/maintainers/swisnl)[@swisnl](https://github.com/swisnl)

---

Top Contributors

[![jormeijer](https://avatars.githubusercontent.com/u/8984962?v=4)](https://github.com/jormeijer "jormeijer (44 commits)")[![JaZo](https://avatars.githubusercontent.com/u/3475007?v=4)](https://github.com/JaZo "JaZo (10 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (7 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (2 commits)")[![ATLCTO](https://avatars.githubusercontent.com/u/13468480?v=4)](https://github.com/ATLCTO "ATLCTO (2 commits)")[![andrewbelcher](https://avatars.githubusercontent.com/u/7072329?v=4)](https://github.com/andrewbelcher "andrewbelcher (1 commits)")[![ppetermann](https://avatars.githubusercontent.com/u/69334?v=4)](https://github.com/ppetermann "ppetermann (1 commits)")

---

Tags

swisnlmcp-client

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[symfony/mailer

Helps sending emails

1.6k368.1M955](/packages/symfony-mailer)[ccxt/ccxt

A cryptocurrency trading API with more than 100 exchanges in JavaScript / TypeScript / Python / C# / PHP / Go

41.5k328.9k1](/packages/ccxt-ccxt)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[team-reflex/discord-php

An unofficial API to interact with the voice and text service Discord.

1.1k379.4k24](/packages/team-reflex-discord-php)[php-mcp/server

PHP SDK for building Model Context Protocol (MCP) servers - Create MCP tools, resources, and prompts

828280.5k25](/packages/php-mcp-server)[clue/docker-react

Async, event-driven access to the Docker Engine API, built on top of ReactPHP.

113154.9k1](/packages/clue-docker-react)

PHPackages © 2026

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