PHPackages                             ronydebnath/mcp-sdk - 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. [API Development](/categories/api)
4. /
5. ronydebnath/mcp-sdk

ActiveLibrary[API Development](/categories/api)

ronydebnath/mcp-sdk
===================

A Laravel package for building AI-driven conversational applications with real-time streaming, secure authentication, and flexible memory management.

v1.0.4(11mo ago)02MITPHPPHP ^8.1

Since Jun 4Pushed 11mo agoCompare

[ Source](https://github.com/ronydebnath/laravel-mcp-server)[ Packagist](https://packagist.org/packages/ronydebnath/mcp-sdk)[ RSS](/packages/ronydebnath-mcp-sdk/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (12)Versions (6)Used By (0)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d185c5e90c79e76011602184c0df45930638d11edd77d267c9f5799f614d5378/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f6e796465626e6174682f6d63702d73646b2e737667)](https://packagist.org/packages/ronydebnath/mcp-sdk)

MCP SDK for Laravel
===================

[](#mcp-sdk-for-laravel)

A Laravel package for interacting with Model Context Protocol (MCP) servers and implementing MCP servers.

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

[](#installation)

You can install the package via composer:

```
composer require ronydebnath/mcp-sdk
```

The package will automatically register its service provider.

You can publish the config file with:

```
php artisan vendor:publish --provider="Ronydebnath\MCP\MCPServiceProvider" --tag="config"
```

This will create a `config/mcp.php` file in your config directory.

Configuration
-------------

[](#configuration)

The package configuration file includes settings for both client and server functionality:

```
return [
    'default' => env('MCP_CONNECTION', 'default'),

    'connections' => [
        'default' => [
            'host' => env('MCP_HOST', 'localhost'),
            'port' => env('MCP_PORT', 8000),
            'timeout' => env('MCP_TIMEOUT', 30),
            'verify' => env('MCP_VERIFY_SSL', true),
        ],
    ],

    'server' => [
        'session_expiry' => env('MCP_SESSION_EXPIRY', 60),
        'max_connections' => env('MCP_MAX_CONNECTIONS', 100),
        'allowed_origins' => explode(',', env('MCP_ALLOWED_ORIGINS', '*')),
    ],

    'auth' => [
        'token_expiry' => env('MCP_TOKEN_EXPIRY', 60),
        'token_length' => env('MCP_TOKEN_LENGTH', 32),
    ],

    'memory' => [
        'max_size' => env('MCP_MEMORY_MAX_SIZE', 100),
        'persist' => env('MCP_MEMORY_PERSIST', false),
        'storage_path' => env('MCP_MEMORY_STORAGE_PATH', storage_path('app/mcp/memory')),
    ],

    'message' => [
        'default_type' => 'text',
        'max_length' => env('MCP_MAX_MESSAGE_LENGTH', 4096),
    ],
];
```

Using the MCP Client
--------------------

[](#using-the-mcp-client)

### Using Dependency Injection

[](#using-dependency-injection)

```
use Ronydebnath\MCP\Client\MCPClient;
use Ronydebnath\MCP\Types\Message;
use Ronydebnath\MCP\Types\Role;

class YourController
{
    public function __construct(private MCPClient $client)
    {}

    public function handle()
    {
        $message = new Message(
            role: Role::USER,
            content: 'Hello, how are you?',
            type: 'text'
        );

        $response = $this->client->send($message);
    }
}
```

### Using the Facade

[](#using-the-facade)

```
use Ronydebnath\MCP\Facades\MCP;
use Ronydebnath\MCP\Types\Message;
use Ronydebnath\MCP\Types\Role;

$message = new Message(
    role: Role::USER,
    content: 'Hello, how are you?',
    type: 'text'
);

$response = MCP::send($message);
```

### Sending Multiple Messages

[](#sending-multiple-messages)

```
use Ronydebnath\MCP\Client\MCPClient;
use Ronydebnath\MCP\Types\Message;
use Ronydebnath\MCP\Types\Role;

$messages = [
    new Message(role: Role::USER, content: 'First message', type: 'text'),
    new Message(role: Role::USER, content: 'Second message', type: 'text'),
];

$responses = $client->sendMultiple($messages);
```

### Using Streaming

[](#using-streaming)

```
use Ronydebnath\MCP\Client\StreamingMCPClient;
use Ronydebnath\MCP\Types\Message;
use Ronydebnath\MCP\Types\Role;

// Using Dependency Injection
class YourController
{
    public function __construct(private StreamingMCPClient $client)
    {}

    public function handle()
    {
        $message = new Message(
            role: Role::USER,
            content: 'Hello, how are you?',
            type: 'text'
        );

        $this->client->stream($message, function ($chunk) {
            // Handle each chunk of the response
            echo $chunk['content'];
        });
    }
}

// Using the Facade
MCP::stream($message, function ($chunk) {
    echo $chunk['content'];
});

// Streaming multiple messages
$messages = [
    new Message(role: Role::USER, content: 'First message', type: 'text'),
    new Message(role: Role::USER, content: 'Second message', type: 'text'),
];

$client->streamMultiple($messages, function ($chunk) {
    echo $chunk['content'];
});
```

Using the MCP Server
--------------------

[](#using-the-mcp-server)

### Setting Up Routes

[](#setting-up-routes)

Add the following route to your `routes/api.php`:

```
use Ronydebnath\MCP\Server\MCPServer;

Route::post('/mcp', function (Request $request, MCPServer $server) {
    return $server->handle($request);
});
```

### Registering Message Handlers

[](#registering-message-handlers)

```
use Ronydebnath\MCP\Server\MCPServer;
use Ronydebnath\MCP\Types\Message;
use Ronydebnath\MCP\Types\Role;

$server->registerHandler('text', function (Message $message) {
    return [
        'role' => Role::ASSISTANT->value,
        'content' => 'This is a response to: ' . $message->content,
        'type' => 'text',
    ];
});
```

### Using Authentication

[](#using-authentication)

The package includes built-in authentication support:

```
use Ronydebnath\MCP\Server\Auth\AuthMiddleware;
use Ronydebnath\MCP\Server\Auth\AuthProvider;

// Generate a token
$token = $authProvider->generateToken();

// Register the authentication middleware
$server->registerMiddleware(function ($request) use ($authMiddleware) {
    return $authMiddleware->handle($request);
});
```

Clients can authenticate using either:

1. Bearer token in the Authorization header:

```
Authorization: Bearer your-token-here

```

2. Token as a query parameter:

```
/mcp?token=your-token-here

```

### Handling Streaming Requests

[](#handling-streaming-requests)

The server automatically handles streaming requests when the client sets the `Accept: text/event-stream` header. The server will:

1. Create a new session or use an existing one
2. Send an initial connection message
3. Stream response chunks as they become available
4. Maintain the session for the duration of the connection

Memory and Context Management
-----------------------------

[](#memory-and-context-management)

The package includes memory and context management for maintaining conversation state:

### Using Memory

[](#using-memory)

```
use Ronydebnath\MCP\Shared\Memory;
use Ronydebnath\MCP\Types\Message;
use Ronydebnath\MCP\Types\Role;

$memory = app(Memory::class);

// Add messages to memory
$memory->add(new Message(
    role: Role::USER,
    content: 'Hello',
    type: 'text'
));

// Get messages by role
$userMessages = $memory->getByRole(Role::USER);

// Get messages by type
$textMessages = $memory->getByType('text');

// Clear memory
$memory->clear();
```

### Using Context

[](#using-context)

```
use Ronydebnath\MCP\Shared\Context;
use Ronydebnath\MCP\Types\Message;
use Ronydebnath\MCP\Types\Role;

$context = app(Context::class);

// Set context data
$context->set('user_id', 123);
$context->set('preferences', ['theme' => 'dark']);

// Add messages to context
$context->addMessage(new Message(
    role: Role::USER,
    content: 'Hello',
    type: 'text'
));

// Get context data
$userId = $context->get('user_id');
$messages = $context->getMessages();

// Clear context
$context->clear();
```

### Using Progress Tracking

[](#using-progress-tracking)

```
use Ronydebnath\MCP\Shared\Progress;

$progress = app(Progress::class);

// Update progress
$progress->update(50, 'Processing...', ['step' => 'analysis']);

// Increment progress
$progress->increment(10, 'Moving to next step');

// Get progress information
$percentage = $progress->getPercentage();
$status = $progress->getStatus();
$metadata = $progress->getMetadata();

// Check if complete
if ($progress->isComplete()) {
    // Handle completion
}

// Reset progress
$progress->reset();
```

Testing
-------

[](#testing)

```
composer test
```

Security
--------

[](#security)

If you discover any security related issues, please email hello\[at\]ronydebnath.com instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance54

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

5

Last Release

339d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/97dc564feb745f4cf82f2ea1414ba4c1c6117c4f83877c6f5fb5f9ebb3fb9f42?d=identicon)[ronydebnath](/maintainers/ronydebnath)

---

Top Contributors

[![ronydebnath](https://avatars.githubusercontent.com/u/10370201?v=4)](https://github.com/ronydebnath "ronydebnath (10 commits)")

---

Tags

laravel-mcpmcp-servermodel-context-protocollaravelaistreamingchatronydebnathmcp-sdk

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ronydebnath-mcp-sdk/health.svg)

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

###  Alternatives

[laravel/boost

Laravel Boost accelerates AI-assisted development by providing the essential context and structure that AI needs to generate high-quality, Laravel-specific code.

3.4k10.6M272](/packages/laravel-boost)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[andreaselia/laravel-api-to-postman

Generate a Postman collection automatically from your Laravel API

1.0k586.2k3](/packages/andreaselia-laravel-api-to-postman)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)

PHPackages © 2026

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