
Laravel-MCP-Server
Un package Laravel pour implémenter les serveurs de protocole de contexte de modèle sécurisé utilisant le transport des événements de serveur (SSE), fournissant une communication en temps réel et un système d'outils évolutif pour les environnements d'entreprise.
3 years
Works with Finder
34
Github Watches
2
Github Forks
34
Github Stars
Laravel MCP Server by OP.GG
A powerful Laravel package to build a Model Context Protocol Server seamlessly
English | Português do Brasil | 한국어 | Русский | 简体中文 | 繁體中文 | Polski
Overview
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.
Why SSE instead of STDIO?
While stdio is straightforward and widely used in MCP implementations, it has significant security implications for enterprise environments:
- Security Risk: STDIO transport potentially exposes internal system details and API specifications
- Data Protection: Organizations need to protect proprietary API endpoints and internal system architecture
- Control: SSE offers better control over the communication channel between LLM clients and your application
By implementing the MCP server with SSE transport, enterprises can:
- Expose only the necessary tools and resources while keeping proprietary API details private
- Maintain control over authentication and authorization processes
Key benefits:
- Seamless and rapid implementation of SSE in existing Laravel projects
- Support for the latest Laravel and PHP versions
- Efficient server communication and real-time data processing
- Enhanced security for enterprise environments
Key Features
- Real-time communication support through Server-Sent Events (SSE) integration
- Implementation of tools and resources compliant with Model Context Protocol specifications
- Adapter-based design architecture with Pub/Sub messaging pattern (starting with Redis, more adapters planned)
- Simple routing and middleware configuration
Requirements
- PHP >=8.2
- Laravel >=10.x
Installation
-
Install the package via Composer:
composer require opgginc/laravel-mcp-server
-
Publish the configuration file:
php artisan vendor:publish --provider="OPGG\LaravelMcpServer\LaravelMcpServerServiceProvider"
Basic Usage
Creating and Adding Custom Tools
The package provides convenient Artisan commands to generate new tools:
php artisan make:mcp-tool MyCustomTool
This command:
- Handles various input formats (spaces, hyphens, mixed case)
- Automatically converts the name to proper case format
- Creates a properly structured tool class in
app/MCP/Tools
- Offers to automatically register the tool in your configuration
You can also manually create and register tools in config/mcp-server.php
:
use OPGG\LaravelMcpServer\Services\ToolService\ToolInterface;
class MyCustomTool implements ToolInterface
{
// Tool implementation
}
Testing MCP Tools
The package includes a special command for testing your MCP tools without needing a real MCP client:
# Test a specific tool interactively
php artisan mcp:test-tool MyCustomTool
# List all available tools
php artisan mcp:test-tool --list
# Test with specific JSON input
php artisan mcp:test-tool MyCustomTool --input='{"param":"value"}'
This helps you rapidly develop and debug tools by:
- Showing the tool's input schema and validating inputs
- Executing the tool with your provided input
- Displaying formatted results or detailed error information
- Supporting complex input types including objects and arrays
Visualizing MCP Tools with Inspector
You can also use the Model Context Protocol Inspector to visualize and test your MCP tools:
# Run the MCP Inspector without installation
npx @modelcontextprotocol/inspector node build/index.js
This will typically open a web interface at localhost:6274
. To test your MCP server:
-
Warning:
php artisan serve
CANNOT be used with this package because it cannot handle multiple PHP connections simultaneously. Since MCP SSE requires processing multiple connections concurrently, you must use one of these alternatives:-
Laravel Octane (Easiest option):
# Install and set up Laravel Octane with FrankenPHP (recommended) composer require laravel/octane php artisan octane:install --server=frankenphp # Start the Octane server php artisan octane:start
Important: When installing Laravel Octane, make sure to use FrankenPHP as the server. The package may not work properly with RoadRunner due to compatibility issues with SSE connections. If you can help fix this RoadRunner compatibility issue, please submit a Pull Request - your contribution would be greatly appreciated!
For details, see the Laravel Octane documentation
-
Production-grade options:
- Nginx + PHP-FPM
- Apache + PHP-FPM
- Custom Docker setup
- Any web server that properly supports SSE streaming
-
-
In the Inspector interface, enter your Laravel server's MCP SSE URL (e.g.,
http://localhost:8000/mcp/sse
) -
Connect and explore available tools visually
The SSE URL follows the pattern: http://[your-laravel-server]/[default_path]/sse
where default_path
is defined in your config/mcp-server.php
file.
Advanced Features
Pub/Sub Architecture with SSE Adapters
The package implements a publish/subscribe (pub/sub) messaging pattern through its adapter system:
-
Publisher (Server): When clients send requests to the
/message
endpoint, the server processes these requests and publishes responses through the configured adapter. -
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.
-
Subscriber (SSE Connection): Long-lived SSE connections subscribe to messages for their respective clients and deliver them in real-time.
This architecture enables:
- Scalable real-time communication
- Reliable message delivery even during temporary disconnections
- Efficient handling of multiple concurrent client connections
- Potential for distributed server deployments
Redis Adapter Configuration
The default Redis adapter can be configured as follows:
'sse_adapter' => 'redis',
'adapters' => [
'redis' => [
'prefix' => 'mcp_sse_', // Prefix for Redis keys
'connection' => 'default', // Redis connection from database.php
'ttl' => 100, // Message TTL in seconds
],
],
Environment Variables
The package supports the following environment variables to allow configuration without modifying the config files:
Variable | Description | Default |
---|---|---|
MCP_SERVER_ENABLED |
Enable or disable the MCP server | true |
MCP_REDIS_CONNECTION |
Redis connection name from database.php | default |
Example .env Configuration
# Disable MCP server in specific environments
MCP_SERVER_ENABLED=false
# Use a specific Redis connection for MCP
MCP_REDIS_CONNECTION=mcp
License
This project is distributed under the MIT license.
相关推荐
🔥 1Panel fournit une interface Web intuitive et un serveur MCP pour gérer des sites Web, des fichiers, des conteneurs, des bases de données et des LLM sur un serveur Linux.
⛓️RULEGO est un cadre de moteur de règle d'orchestration des composants de nouvelle génération légère, intégrée, intégrée et de nouvelle génération pour GO.
🧑🚀 全世界最好的 LLM 资料总结 (数据处理、模型训练、模型部署、 O1 模型、 MCP 、小语言模型、视觉语言模型) | Résumé des meilleures ressources LLM du monde.
Créez facilement des outils et des agents LLM à l'aide de fonctions Plain Bash / JavaScript / Python.
😎简单易用、🧩丰富生态 - 大模型原生即时通信机器人平台 | 适配 QQ / 微信 (企业微信、个人微信) / 飞书 / 钉钉 / Discord / Telegram / Slack 等平台 | 支持 Chatgpt 、 Deepseek 、 Dify 、 Claude 、 GEMINI 、 XAI 、 PPIO 、 OLLAMA 、 LM Studio 、阿里云百炼、火山方舟、 Siliconflow 、 Qwen 、 Moonshot 、 ChatGlm 、 Sillytraven 、 MCP 等 LLM 的机器人 / Agent | Plateforme de bots de messagerie instantanée basés sur LLM, prend en charge Discord, Telegram, WeChat, Lark, Dingtalk, QQ, Slack
Reviews

user_jlwRLDR1
As a dedicated user of laravel-mcp-server, I am thoroughly impressed with its seamless integration and performance. Developed by opgginc, this server application stands out in its reliability and ease of use. The welcoming interface and comprehensive documentation make it an excellent choice for developers looking to enhance their Laravel projects. Highly recommended!

user_AvQfE7GB
Laravel-mcp-server by opgginc is a fantastic tool for managing your Laravel applications efficiently. The streamlined interface and comprehensive features make server management a breeze. Highly recommend for anyone looking to improve their Laravel development workflow.

user_ARdBZVVp
I'm thoroughly impressed with Laravel-MCP-Server by opgginc! This tool seamlessly integrates with your Laravel project, enhancing your development experience significantly. The intuitive start URL and welcoming message make the setup a breeze, even for beginners. Every element is well-crafted, reflecting the high standards of the Laravel community. Highly recommended for anyone looking to streamline their Laravel application management!

user_PimiRjV7
Laravel-mcp-server by opgginc is a phenomenal tool for managing Laravel applications. Its user-friendly interface and robust features make monitoring and controlling servers seamless. Highly recommended for anyone looking to enhance their Laravel project management experience!

user_cKGQ6v3v
As a loyal user of mcp applications, I find the laravel-mcp-server by opgginc to be an exceptional tool. The seamless integration and user-friendly interface make it a delight to work with. Setting it up is straightforward, and the performance is outstanding. Highly recommend it to any developer looking for a robust server solution.

user_6mRjhl9X
As a dedicated user of laravel-mcp-server, I am truly impressed with its performance and reliability. Developed by opgginc, this server seamlessly integrates with Laravel, offering robust features and excellent support for modern web applications. It's user-friendly, making it easy to set up and manage. Highly recommended for anyone looking to enhance their Laravel projects!

user_0evNF0KS
As a loyal MCP application user, I must say the laravel-mcp-server by opgginc is an outstanding product. It seamlessly integrates with Laravel and offers robust server-side functionalities. The user-friendly nature and the well-documented features make development a breeze. Highly recommended for anyone looking to enhance their Laravel projects!

user_yoGvFnmR
As a dedicated user of the Laravel-MCP-Server developed by opgginc, I find this tool incredibly robust and efficient for managing my applications. Its seamless integration and user-friendly interface streamline our development process, making it an indispensable asset. Highly recommend it for any Laravel project!

user_IFORtueN
As a dedicated user of laravel-mcp-server by opgginc, I am consistently impressed by its robust functionality and seamless integration into my development workflow. This server solution simplifies complex tasks and boosts productivity remarkably. Highly recommended for any Laravel developer looking to enhance their project efficiency.