|
1 | | -# Laravel MCP Server |
| 1 | +<h1 align="center">Laravel MCP Server by OP.GG</h1> |
2 | 2 |
|
3 | | -A base Laravel package for building Model Context Protocol (MCP) servers. |
| 3 | +<p align="center"> |
| 4 | + A powerful Laravel package to build a Model Context Protocol Server seamlessly |
| 5 | +</p> |
| 6 | + |
| 7 | +<p align="center"> |
| 8 | +<a href="https://github.com/opgginc/laravel-mcp-server/actions"><img src="https://github.com/opgginc/laravel-mcp-server/actions/workflows/tests.yml/badge.svg" alt="Build Status"></a> |
| 9 | +<a href="https://packagist.org/packages/opgginc/laravel-mcp-server"><img src="https://img.shields.io/packagist/dt/opgginc/laravel-mcp-server" alt="Total Downloads"></a> |
| 10 | +<a href="https://packagist.org/packages/opgginc/laravel-mcp-server"><img src="https://img.shields.io/packagist/v/opgginc/laravel-mcp-server" alt="Latest Stable Version"></a> |
| 11 | +<a href="https://packagist.org/packages/opgginc/laravel-mcp-server"><img src="https://img.shields.io/packagist/l/opgginc/laravel-mcp-server" alt="License"></a> |
| 12 | +</p> |
| 13 | + |
| 14 | +<p align="center"> |
| 15 | +<a href="https://op.gg/open-source/laravel-mcp-server">Official Website</a> |
| 16 | +</p> |
| 17 | + |
| 18 | +## Overview |
| 19 | + |
| 20 | +Laravel MCP Server is a powerful package designed to streamline the implementation of Model Context Protocol (MCP) servers in Laravel applications. **Unlike most Laravel MCP packages that use Standard Input/Output (stdio) transport**, this package **utilizes Server-Sent Events (SSE)** transport, providing a more secure and controlled integration method. |
| 21 | + |
| 22 | +### Why SSE instead of STDIO? |
| 23 | + |
| 24 | +While stdio is straightforward and widely used in MCP implementations, it has significant security implications for enterprise environments: |
| 25 | + |
| 26 | +- **Security Risk**: STDIO transport potentially exposes internal system details and API specifications |
| 27 | +- **Data Protection**: Organizations need to protect proprietary API endpoints and internal system architecture |
| 28 | +- **Control**: SSE offers better control over the communication channel between LLM clients and your application |
| 29 | + |
| 30 | +By implementing the MCP server with SSE transport, enterprises can: |
| 31 | + |
| 32 | +- Expose only the necessary tools and resources while keeping proprietary API details private |
| 33 | +- Maintain control over authentication and authorization processes |
| 34 | + |
| 35 | +Key benefits: |
| 36 | + |
| 37 | +- Seamless and rapid implementation of SSE in existing Laravel projects |
| 38 | +- Support for the latest Laravel and PHP versions |
| 39 | +- Efficient server communication and real-time data processing |
| 40 | +- Enhanced security for enterprise environments |
| 41 | + |
| 42 | +## Key Features |
| 43 | + |
| 44 | +- Real-time communication support through Server-Sent Events (SSE) integration |
| 45 | +- Implementation of tools and resources compliant with Model Context Protocol specifications |
| 46 | +- Adapter-based design architecture with Pub/Sub messaging pattern (starting with Redis, more adapters planned) |
| 47 | +- Simple routing and middleware configuration |
4 | 48 |
|
5 | 49 | ## Requirements |
6 | 50 |
|
7 | | -- PHP ^8.4 |
8 | | -- Laravel 10.x, 11.x, 12.x |
| 51 | +- PHP >=8.2 |
| 52 | +- Laravel >=10.x |
9 | 53 |
|
10 | 54 | ## Installation |
11 | 55 |
|
12 | | -```bash |
13 | | -composer require opgginc/laravel-mcp-server |
| 56 | +1. Install the package via Composer: |
| 57 | + |
| 58 | + ```bash |
| 59 | + composer require opgginc/laravel-mcp-server |
| 60 | + ``` |
| 61 | + |
| 62 | +2. Publish the configuration file: |
| 63 | + ```bash |
| 64 | + php artisan vendor:publish --provider="OPGG\LaravelMcpServer\LaravelMcpServerServiceProvider" |
| 65 | + ``` |
| 66 | + |
| 67 | +## Basic Usage |
| 68 | + |
| 69 | +### Adding Custom Tools |
| 70 | + |
| 71 | +To develop your own tools, create a new class and register it in `config/mcp-server.php`: |
| 72 | + |
| 73 | +```php |
| 74 | +use OPGG\LaravelMcpServer\Services\ToolService\BaseTool; |
| 75 | + |
| 76 | +class MyCustomTool extends BaseTool |
| 77 | +{ |
| 78 | + // Tool implementation |
| 79 | +} |
14 | 80 | ``` |
| 81 | + |
| 82 | +## Advanced Features |
| 83 | + |
| 84 | +### Pub/Sub Architecture with SSE Adapters |
| 85 | + |
| 86 | +The package implements a publish/subscribe (pub/sub) messaging pattern through its adapter system: |
| 87 | + |
| 88 | +1. **Publisher (Server)**: When clients send requests to the `/message` endpoint, the server processes these requests and publishes responses through the configured adapter. |
| 89 | + |
| 90 | +2. **Message Broker (Adapter)**: The adapter (e.g., Redis) maintains message queues for each client, identified by unique client IDs. This provides a reliable asynchronous communication layer. |
| 91 | + |
| 92 | +3. **Subscriber (SSE Connection)**: Long-lived SSE connections subscribe to messages for their respective clients and deliver them in real-time. |
| 93 | + |
| 94 | +This architecture enables: |
| 95 | +- Scalable real-time communication |
| 96 | +- Reliable message delivery even during temporary disconnections |
| 97 | +- Efficient handling of multiple concurrent client connections |
| 98 | +- Potential for distributed server deployments |
| 99 | + |
| 100 | +### Redis Adapter Configuration |
| 101 | + |
| 102 | +The default Redis adapter can be configured as follows: |
| 103 | + |
| 104 | +```php |
| 105 | +'sse_adapter' => 'redis', |
| 106 | +'adapters' => [ |
| 107 | + 'redis' => [ |
| 108 | + 'prefix' => 'mcp_sse_', // Prefix for Redis keys |
| 109 | + 'connection' => 'default', // Redis connection from database.php |
| 110 | + 'ttl' => 100, // Message TTL in seconds |
| 111 | + ], |
| 112 | +], |
| 113 | +``` |
| 114 | + |
| 115 | +## Contributing |
| 116 | + |
| 117 | +Bug reports and feature improvement suggestions can be submitted through the GitHub repository. For detailed information on how to contribute, please refer to the CONTRIBUTING.md file. |
| 118 | + |
| 119 | +## License |
| 120 | + |
| 121 | +This project is distributed under the MIT license. |
0 commit comments