Download the PHP package projectsaturnstudios/laravel-vibes without Composer
On this page you can find all versions of the php package projectsaturnstudios/laravel-vibes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download projectsaturnstudios/laravel-vibes
More information about projectsaturnstudios/laravel-vibes
Files in projectsaturnstudios/laravel-vibes
Package laravel-vibes
Short Description A Laravel package for implementing the Machine Control Protocol (MCP) server
License MIT
Informations about the package laravel-vibes
๐ค Laravel Vibes
A powerful Laravel package for implementing the Machine Control Protocol (MCP) server, enabling seamless integration with AI agents in your applications. Build intelligent, interactive features with structured tool definitions and real-time communication.
๐ Table of Contents
- [๐ค Laravel Vibes](#-laravel-vibes) - [โจ Key Features](#-key-features) - [๐ฆ Implementation Status](#-implementation-status) - [Primitive Implementation Status](#primitive-implementation-status) - [Feature Availability Matrix](#feature-availability-matrix) - [๐ Documentation](#-documentation) - [Class Diagram](#class-diagram) - [๐ง Installation](#-installation) - [โ๏ธ Configuration](#๏ธ-configuration) - [๐ Usage](#-usage) - [Registering Tools](#registering-tools) - [Defining a Custom Tool](#defining-a-custom-tool) - [Using Server-Sent Events](#using-server-sent-events) - [Handling AI Agent Messages](#handling-ai-agent-messages) - [๐ Tool Discovery & Registration](#-tool-discovery--registration) - [Auto-Discovery](#auto-discovery) - [Manual Registration](#manual-registration) - [Caching Primitives](#caching-primitives) - [๐งช Comprehensive Testing Guide](#-comprehensive-testing-guide) - [Unit Testing Custom Tools](#unit-testing-custom-tools) - [Mocking External Services](#mocking-external-services) - [Integration Testing with TheAgency](#integration-testing-with-theagency) - [Testing SSE Connections](#testing-sse-connections) - [Mocking AI Agent Interactions](#mocking-ai-agent-interactions) - [PHPUnit Configuration Recommendations](#phpunit-configuration-recommendations) - [Testing Best Practices](#testing-best-practices) - [๐งฐ API Reference](#-api-reference) - [TheAgency Class](#theagency-class) - [VibeTool Class](#vibetool-class) - [PrimitiveHandler Interface](#primitivehandler-interface) - [Common Usage Patterns](#common-usage-patterns) - [๐ก๏ธ Middleware Components](#-middleware-components) - [mcp-agent Middleware Group](#mcp-agent-middleware-group) - [ScaffoldSSEConnection Middleware](#scaffoldssconnection-middleware) - [ValidAgentCorsHeaders Middleware](#validagentcorsheaders-middleware) - [Security Best Practices](#security-best-practices) - [Complete Middleware Stack Example](#complete-middleware-stack-example) - [๐ค MCP Protocol Integration](#-mcp-protocol-integration) - [What is the MCP Protocol?](#what-is-the-mcp-protocol) - [MCP Message Structure](#mcp-message-structure) - [Laravel Vibes MCP Implementation](#laravel-vibes-mcp-implementation) - [Supported MCP Methods](#supported-mcp-methods) - [Communication Flow](#communication-flow) - [Future Protocol Support](#future-protocol-support) - [Official Documentation](#official-documentation) - [๐ Advanced Usage Examples](#-advanced-usage-examples) - [Error Handling Patterns](#error-handling-patterns) - [Anthropic Claude Integration](#anthropic-claude-integration) - [Event-driven MCP Architecture](#event-driven-mcp-architecture) - [Database-backed Tool Implementation](#database-backed-tool-implementation) - [Complex Multi-step Agent Interaction](#complex-multi-step-agent-interaction) - [Custom Validation for Tool Parameters](#custom-validation-for-tool-parameters) - [๐ Laravel 12 Compatibility](#-laravel-12-compatibility) - [Version Compatibility Matrix](#version-compatibility-matrix) - [Laravel 12 Features Utilized](#laravel-12-features-utilized) - [Upgrading from Previous Laravel Versions](#upgrading-from-previous-laravel-versions) - [Known Issues & Limitations](#known-issues--limitations) - [Composer Requirements](#composer-requirements) - [๐ Deployment Considerations](#-deployment-considerations) - [Production Environment Configuration](#production-environment-configuration) - [Performance Optimization](#performance-optimization) - [Scaling Strategies](#scaling-strategies) - [Monitoring and Logging](#monitoring-and-logging) - [Resource Management](#resource-management) - [Security in Production](#security-in-production) - [Hosting Platform-Specific Guidelines](#hosting-platform-specific-guidelines) - [๐ Architecture](#-architecture) - [๐ Roadmap](#-roadmap) - [๐ฅ Credits](#-credits) - [๐ Security](#-security) - [๐ License](#-license) - [๐ค Contributing](#-contributing) - [๐ Flow Diagrams](#-flow-diagrams) - [๐ Real-World Examples](#-real-world-examples)โจ Key Features
- ๐ง Tool Registration System - Define, register, and expose tools for AI agents to use
- ๐ Server-Sent Events (SSE) - Real-time communication with AI agents via event streams
- ๐ฃ๏ธ API Endpoints - Ready-to-use endpoints for MCP protocol implementation
- ๐งฉ Primitive Handlers - Extensible system for various MCP primitives
- ๐ Auto-Discovery - Automatic discovery of tool implementations in your codebase
- ๐ฆบ Type Safety - Full PHP 8.2+ type hinting and return type declarations
- ๐ฎ Future-Ready - Foundation for upcoming MCP features (resources, prompts, samples, and roots) with framework in place
๐ฆ Implementation Status
This section provides a clear overview of which MCP primitives are currently implemented and which are planned for future releases.
Primitive Implementation Status
Primitive | Status | Version Introduced | Notes |
---|---|---|---|
Tools | โ Full | 0.1.0 | Complete implementation with repositories, data objects, and discovery |
Resources | ๐ง Partial | 0.4.0 | Framework in place, API not finalized |
Prompts | ๐ง Partial | 0.4.0 | Framework in place, API not finalized |
Samples | ๐ง Partial | 0.4.0 | Framework in place, API not finalized |
Roots | ๐ง Partial | 0.4.0 | Framework in place, API not finalized |
Feature Availability Matrix
Feature | v0.1.0 | v0.2.0 | v0.3.0 | v0.4.0 | Planned |
---|---|---|---|---|---|
Tool Registration | โ | โ | โ | โ | โ |
Server-Sent Events | โ | โ | โ | โ | โ |
Auto-Discovery | โ | โ | โ | โ | โ |
Primitive Caching | โ | โ | โ | โ | โ |
Resource Primitives | โ | โ | โ | ๐ง | โ |
Prompt Primitives | โ | โ | โ | ๐ง | โ |
Sample Primitives | โ | โ | โ | ๐ง | โ |
Root Primitives | โ | โ | โ | ๐ง | โ |
Legend:
- โ Full implementation
- ๐ง Partial implementation
- โ Not implemented
๐ Documentation
Comprehensive documentation for Laravel Vibes is available in the docs/
directory:
Documentation File | Description |
---|---|
TheAgency.md | Detailed documentation for TheAgency class, the central orchestrator for MCP primitives |
ClassDiagram.md | Structural diagram showing relationships between classes |
UsageExamples.md | Practical examples for using Laravel Vibes in your applications |
CONTRIBUTING.md | Guidelines for contributing to Laravel Vibes |
Flow-Diagrams.md | Visual diagrams of Laravel Vibes architecture and workflows |
Examples.md | Real-world examples of Laravel Vibes implementation |
index.md | Overview and core concepts documentation |
Class Diagram
Below is a simplified class diagram showing the main components of Laravel Vibes:
๐ง Installation
You can install the package via composer:
The package will automatically register its service provider with Laravel.
โ๏ธ Configuration
Publish the configuration files with:
This will publish the configuration file to config/vibes.php
and config/cors.vibes.php
.
Key configuration options:
๐ Learn more: For advanced configuration options, see the Configuration section in TheAgency.md.
๐ Usage
Registering Tools
Register AI tools in your service provider:
Or register via the config file:
Defining a Custom Tool
Create a tool that AI agents can use:
Using Server-Sent Events
Connect AI agents to your application using SSE:
Handling AI Agent Messages
Process incoming MCP messages from agents:
๐ Learn more: Detailed usage examples are available in the UsageExamples.md documentation.
๐ Tool Discovery & Registration
Laravel Vibes follows a similar approach to Laravel Event Sourcing for loading primitives, using automatic discovery and registration patterns. For more detailed examples, see the UsageExamples.md documentation.
Auto-Discovery
The package automatically discovers and registers tools and other MCP primitives in the configured directories:
During application bootstrapping, Laravel Vibes scans these directories for classes that implement the PrimitiveHandler
interface and automatically registers them with TheAgency:
Manual Registration
For manual registration, modify your AppServiceProvider
or create a dedicated service provider:
Then add your provider to config/app.php
:
Caching Primitives
For production environments, Laravel Vibes provides caching mechanisms to improve performance. The discovered primitives are cached at bootstrap/cache/vibes.php
.
To clear the cache during development:
You can also implement a dedicated command to manage the primitive cache (similar to Laravel Event Sourcing's event-sourcing:cache-event-handlers
):
๐งช Comprehensive Testing Guide
This section provides guidance and examples for testing Laravel Vibes components, focusing on custom tools and AI agent interactions.
Unit Testing Custom Tools
Test your custom tools to ensure they properly handle inputs and produce expected outputs:
Mocking External Services
Test tools that interact with external services by mocking the HTTP responses:
Integration Testing with TheAgency
Test the integration of tools with TheAgency:
Testing SSE Connections
Test Server-Sent Events (SSE) connections using the following approach:
Mocking AI Agent Interactions
Test components that interact with AI agents:
PHPUnit Configuration Recommendations
Here's a sample PHPUnit configuration for optimal testing of Laravel Vibes components:
Testing Best Practices
When testing Laravel Vibes components, follow these best practices:
- Isolate your tests: Ensure each test is independent and can run in any order.
- Use test doubles: Mock external dependencies like HTTP APIs, databases, and services.
- Test edge cases: Verify behavior with invalid inputs, error conditions, and boundary values.
- Emulate real-world scenarios: Create tests that mirror actual usage patterns.
- Test asynchronous behavior: Verify SSE connections and event listeners work correctly.
- Use data providers: Test tools with multiple input/output combinations.
- Check exception handling: Verify tools throw appropriate exceptions for invalid inputs.
- Test middleware independently: Isolate middleware functionality from controller logic.
For detailed example tests, check out the tests directory in the Laravel Vibes repository.
๐ Learn more: For more detailed testing examples and strategies, see the Testing section in UsageExamples.md.
๐ Laravel 12 Compatibility
Laravel Vibes is designed to be fully compatible with Laravel 12.x, leveraging many of its new features and improvements to provide optimal performance and developer experience.
Version Compatibility Matrix
The following table shows Laravel Vibes package version compatibility with Laravel framework versions:
Laravel Vibes Version | Laravel Version | PHP Version | Status |
---|---|---|---|
1.0.x | 12.x | โฅ 8.2 | Full Support |
0.9.x | 11.x | โฅ 8.1 | Maintained |
0.8.x | 10.x | โฅ 8.1 | Legacy Support |
0.7.x | 9.x | โฅ 8.0 | End of Support |
Laravel 12 Features Utilized
Laravel Vibes takes advantage of several new features introduced in Laravel 12:
Improved Rate Limiting
Laravel Vibes uses the enhanced rate limiting capabilities in Laravel 12 to manage AI agent connections and prevent resource abuse:
Route Grouping Improvements
The package uses Laravel 12's improved route group definitions for cleaner organization:
PHP 8.2 Readonly Classes
Laravel Vibes models use PHP 8.2 readonly classes for improved type safety and performance:
First-class Enum Support
Laravel 12's improved support for PHP enums is used throughout the package:
Upgrading from Previous Laravel Versions
If you're upgrading from a previous Laravel version, follow these steps to ensure compatibility with Laravel Vibes:
From Laravel 11.x
-
Update your dependencies in
composer.json
: -
Run Composer update:
-
Update configuration if needed:
- Update any custom tool implementations to use the new tool signature format:
From Laravel 10.x or Earlier
- First upgrade to Laravel 11.x following the official upgrade guide.
- Update to Laravel Vibes 0.9.x.
- Test thoroughly that all tools and functionality work correctly.
- Then follow the steps above to upgrade to Laravel 12 and Laravel Vibes 1.0.x.
Known Issues & Limitations
Session Handling in Laravel 12
Laravel 12 implements stricter session handling. When using SSE connections with Laravel Vibes, you must use the provided ScaffoldSSEConnection
middleware to avoid session conflicts:
Service Container Changes
Laravel 12's service container features improved dependency resolution. If you've extended Laravel Vibes core classes, ensure your bindings are properly registered:
Queue System Changes
If you're using Laravel Vibes with background jobs, note that Laravel 12 introduces changes to the queue system:
Composer Requirements
To use Laravel Vibes with Laravel 12, ensure your composer.json
includes the following requirements:
Specific extension requirements:
ext-json
: Required for JSON processingext-curl
: Required for HTTP client functionalityext-mbstring
: Required for string manipulation
For development environments, we recommend:
๐ Learn more: Check the compatibility documentation for detailed information about supported features and versions.
๐ Deployment Considerations
This section provides guidance for deploying Laravel Vibes in production environments, focusing on performance, scaling, and security considerations.
Production Environment Configuration
When preparing your Laravel Vibes application for production, ensure these environment-specific settings:
Enable production-optimized caching:
Performance Optimization
Optimize your Laravel Vibes application for high traffic and AI agent interactions:
Tool Execution Optimization
Queue Configuration for Tool Processing
Move long-running operations to background queues:
Compression and Response Optimization
Scaling Strategies
Laravel Vibes can be scaled horizontally or vertically depending on your needs:
Horizontal Scaling with Load Balancing
For handling many concurrent AI agent connections:
If implementing horizontal scaling, ensure:
- Session persistence via Redis/Memcached
- Sticky sessions for SSE connections
- Shared storage for file uploads/resources
Queue Workers for Tool Processing
Monitoring and Logging
Implement robust monitoring for AI agent interactions:
Log Configuration
Telemetry Integration
Key Metrics to Monitor
- Tool execution time and success rate: Track performance of individual tools
- SSE connection count and duration: Monitor active AI agent connections
- Queue processing rate: Ensure background tasks aren't backing up
- Memory usage: Watch for memory leaks during long-running SSE connections
- Redis/database connection saturation: Ensure sufficient pool for connections
Resource Management
AI interactions can be resource-intensive. Configure proper limits:
PHP-FPM configuration for SSE connections:
Security in Production
Implement additional security measures for production:
CORS Configuration
Input Validation
All tool parameters should be thoroughly validated:
Rate Limiting
Configure tiered rate limiting for different operations:
Hosting Platform-Specific Guidelines
Laravel Forge
Docker Deployment
AWS Elastic Beanstalk
For .ebextensions/01-laravel-vibes.config
:
These deployment considerations will help ensure your Laravel Vibes application is robust, performant, and secure in production environments. Always test thoroughly in a staging environment that mirrors your production configuration before deploying updates.
๐ Learn more: For detailed performance benchmarks and advanced scaling strategies, see the Deployment section in UsageExamples.md.
๐ Architecture
Laravel Vibes is built with a modular architecture focusing on these components:
- TheAgency: Central manager for all MCP primitives
- VibeTool: Base class for implementing tools
- Primitive Handlers: Extensible system for different primitive types
- MCPAgentEntryController: Handles SSE and agent message endpoints
- ServiceProvider: Auto-registration and configuration
The package uses these Laravel packages:
spatie/laravel-package-tools
for package configurationspatie/laravel-data
for data objectslorisleiva/laravel-actions
for single-responsibility actions
For a detailed overview of component implementation status, refer to the TheAgency.md documentation files.
๐ Learn more: View the complete class diagram and architectural details in ClassDiagram.md.
๐ Roadmap
Future development plans aligned with our implementation status:
Version | Focus Area | Planned Features |
---|---|---|
0.5.0 | Resources | - Complete Resources primitive implementation - Resource discovery and access - Resource validation and transformation |
0.6.0 | Prompts | - Full Prompts primitive support - Template system for AI interactions - Prompt chaining and composition |
0.7.0 | Samples | - Samples primitive for model configuration - Temperature and top-p controls - Example response generation |
0.8.0 | Roots | - Custom workflow entry points - Advanced routing for AI interactions - Contextual session management |
1.0.0 | Stability | - Complete test coverage for all components - Improved logging and monitoring - Performance optimizations - Comprehensive documentation |
The current focus is on completing the Resources primitive implementation for the upcoming 0.5.0 release. Contributions are welcome for any of the planned features.
๐ฅ Credits
- Project Saturn Studios - Package development and maintenance
๐ Security
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
๐ License
This package is licensed under the MIT License. See the LICENSE.md file for more information.
๐ค Contributing
We welcome contributions to Laravel Vibes! Please see our Contributing Guidelines for details on how to get started, coding standards, and our pull request process.
๐ Flow Diagrams
Visual diagrams of Laravel Vibes architecture and interaction flows are available in the Flow Diagrams documentation. These diagrams help developers understand how the components work together and implement the package effectively.
๐ Real-World Examples
For comprehensive real-world implementation examples, check out our Examples documentation. These examples demonstrate practical use cases and implementation patterns to help you get started quickly.
All versions of laravel-vibes with dependencies
spatie/laravel-package-tools Version ^1.14.0
spatie/laravel-data Version ^4.11
lorisleiva/laravel-actions Version ^2.6