Download the PHP package opgginc/laravel-mcp-server without Composer
On this page you can find all versions of the php package opgginc/laravel-mcp-server. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download opgginc/laravel-mcp-server
More information about opgginc/laravel-mcp-server
Files in opgginc/laravel-mcp-server
Package laravel-mcp-server
Short Description This is my package laravel-mcp-server
License MIT
Homepage https://github.com/opgginc/laravel-mcp-server
Informations about the package laravel-mcp-server
Laravel MCP Server by OP.GG
A powerful Laravel package to build a Model Context Protocol Server seamlessly
English | Português do Brasil | 한국어 | Русский | 简体中文 | 繁體中文 | Polski | Español
⚠️ Version Information & Breaking Changes
v1.3.0 Changes (Current)
Version 1.3.0 introduces improvements to the ToolInterface
for better communication control:
New Features:
- Added
isStreaming(): bool
method for clearer communication pattern selection - Improved migration tools supporting upgrades from v1.1.x, v1.2.x to v1.3.0
- Enhanced stub files with comprehensive v1.3.0 documentation
Deprecated Features:
messageType(): ProcessMessageType
method is now deprecated (will be removed in v2.0.0)- Use
isStreaming(): bool
instead for better clarity and simplicity
Breaking Changes in v1.1.0
Version 1.1.0 introduced a significant and breaking change to the ToolInterface
. If you are upgrading from v1.0.x, you must update your tool implementations to conform to the new interface.
Key Changes in ToolInterface
:
The OPGG\LaravelMcpServer\Services\ToolService\ToolInterface
has been updated as follows:
-
New Method Added:
messageType(): ProcessMessageType
- This method is crucial for the new HTTP stream support and determines the type of message being processed.
- Method Renames:
getName()
is nowname()
getDescription()
is nowdescription()
getInputSchema()
is nowinputSchema()
getAnnotations()
is nowannotations()
How to Update Your Tools:
Automated Tool Migration for v1.1.0
To assist with the transition to the new ToolInterface
introduced in v1.1.0, we've included an Artisan command that can help automate the refactoring of your existing tools:
What it does:
This command will scan PHP files in the specified directory (defaults to app/MCP/Tools/
) and attempt to:
- Identify old tools: It looks for classes implementing the
ToolInterface
with the old method signatures. - Create Backups: Before making any changes, it will create a backup of your original tool file with a
.backup
extension (e.g.,YourTool.php.backup
). If a backup file already exists, the original file will be skipped to prevent accidental data loss. - Refactor the Tool:
- Rename methods:
getName()
toname()
getDescription()
todescription()
getInputSchema()
toinputSchema()
getAnnotations()
toannotations()
- Add the new
messageType()
method, which will default to returningProcessMessageType::SSE
. - Ensure the
use OPGG\LaravelMcpServer\Enums\ProcessMessageType;
statement is present.
- Rename methods:
Usage:
After updating the opgginc/laravel-mcp-server
package to v1.1.0 or later, if you have existing tools written for v1.0.x, it is highly recommended to run this command:
If your tools are located in a directory other than app/MCP/Tools/
, you can specify the path:
The command will output its progress, indicating which files are being processed, backed up, and migrated. Always review the changes made by the tool. While it aims to be accurate, complex or unusually formatted tool files might require manual adjustments.
This tool should significantly ease the migration process and help you adapt to the new interface structure quickly.
Manual Migration
If you prefer to migrate your tools manually, here's a comparison to help you adapt your existing tools:
v1.0.x ToolInterface
:
v1.1.0 ToolInterface
(New):
Example of an updated tool:
If your v1.0.x tool looked like this:
You need to update it for v1.1.0 as follows:
Overview of Laravel MCP Server
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 focuses on Streamable HTTP transport and still includes a legacy SSE provider for backwards compatibility, providing a secure and controlled integration method.
Why Streamable HTTP 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: Streamable HTTP offers better control over the communication channel between LLM clients and your application
By implementing the MCP server with Streamable HTTP 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 Streamable HTTP 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 Streamable HTTP with 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
Transport Providers
The configuration option server_provider
controls which transport is used. Available providers are:
- streamable_http – the recommended default. Uses standard HTTP requests and avoids issues with platforms that close SSE connections after about a minute (e.g. many serverless environments).
- sse – a legacy provider kept for backwards compatibility. It relies on long-lived SSE connections and may not work on platforms with short HTTP timeouts.
The MCP protocol also defines a "Streamable HTTP SSE" mode, but this package does not implement it and there are no plans to do so.
Requirements
- PHP >=8.2
- Laravel >=10.x
Installation
-
Install the package via Composer:
- Publish the configuration file:
Basic Usage
Domain Restriction
You can restrict MCP server routes to specific domain(s) for better security and organization:
When to use domain restriction:
- Running multiple applications on different subdomains
- Separating API endpoints from your main application
- Implementing multi-tenant architectures where each tenant has its own subdomain
- Providing the same MCP services across multiple domains
Example scenarios:
Note: When using multiple domains, the package automatically registers separate routes for each domain to ensure proper routing across all specified domains.
Creating and Adding Custom Tools
The package provides convenient Artisan commands to generate new tools:
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
:
Understanding Your Tool's Structure (ToolInterface)
When you create a tool by implementing OPGG\LaravelMcpServer\Services\ToolService\ToolInterface
, you'll need to define several methods. Here's a breakdown of each method and its purpose:
Let's dive deeper into some of these methods:
messageType(): ProcessMessageType
(Deprecated in v1.3.0)
⚠️ This method is deprecated since v1.3.0. Use isStreaming(): bool
instead for better clarity.
This method specifies the type of message processing for your tool. It returns a ProcessMessageType
enum value. The available types are:
ProcessMessageType::HTTP
: For tools interacting via standard HTTP request/response. Most common for new tools.ProcessMessageType::SSE
: For tools specifically designed to work with Server-Sent Events.
For most tools, especially those designed for the primary streamable_http
provider, you'll return ProcessMessageType::HTTP
.
isStreaming(): bool
(New in v1.3.0)
This is the new, more intuitive method for controlling communication patterns:
return false
: Use standard HTTP request/response (recommended for most tools)return true
: Use Server-Sent Events for real-time streaming
Most tools should return false
unless you specifically need real-time streaming capabilities like:
- Real-time progress updates for long-running operations
- Live data feeds or monitoring tools
- Interactive tools requiring bidirectional communication
name(): string
This is the identifier for your tool. It should be unique. Clients will use this name to request your tool. For example: get-weather
, calculate-sum
.
description(): string
A clear, concise description of your tool's functionality. This is used in documentation, and MCP client UIs (like the MCP Inspector) may display it to users.
inputSchema(): array
This method is crucial for defining your tool's expected input parameters. It should return an array that follows a structure similar to JSON Schema. This schema is used:
- By clients to understand what data to send.
- Potentially by the server or client for input validation.
- By tools like the MCP Inspector to generate forms for testing.
Example inputSchema()
:
In your execute
method, you can then validate the incoming arguments. The HelloWorldTool
example uses Illuminate\Support\Facades\Validator
for this:
annotations(): array
This method provides metadata about your tool's behavior and characteristics, following the official MCP Tool Annotations specification. Annotations help MCP clients categorize tools, make informed decisions about tool approval, and provide appropriate user interfaces.
Standard MCP Annotations:
The Model Context Protocol defines several standard annotations that clients understand:
title
(string): A human-readable title for the tool, displayed in client UIsreadOnlyHint
(boolean): Indicates if the tool only reads data without modifying the environment (default: false)destructiveHint
(boolean): Suggests if the tool may perform destructive operations like deleting data (default: true)idempotentHint
(boolean): Indicates if repeated calls with the same arguments have no additional effect (default: false)openWorldHint
(boolean): Signals if the tool interacts with external entities beyond the local environment (default: true)
Important: These are hints, not guarantees. They help clients provide better user experiences but should not be used for security-critical decisions.
Example with standard MCP annotations:
Real-world examples by tool type:
Custom annotations can also be added for your specific application needs:
Working with Resources
Resources expose data from your server that can be read by MCP clients. They are
application-controlled, meaning the client decides when and how to use them.
Create concrete resources or URI templates in app/MCP/Resources
and
app/MCP/ResourceTemplates
using the Artisan helpers:
Register the generated classes in config/mcp-server.php
under the resources
and resource_templates
arrays. Each resource class extends the base
Resource
class and implements a read()
method that returns either text
or
blob
content. Templates extend ResourceTemplate
and describe dynamic URI
patterns clients can use. A resource is identified by a URI such as
file:///logs/app.log
and may optionally define metadata like mimeType
or
size
.
Resource Templates with Dynamic Listing: Templates can optionally implement a list()
method to provide concrete resource instances that match the template pattern. This allows clients to discover available resources dynamically. The list()
method enables ResourceTemplate instances to generate a list of specific resources that can be read through the template's read()
method.
List available resources using the resources/list
endpoint and read their
contents with resources/read
. The resources/list
endpoint returns an array
of concrete resources, including both static resources and dynamically generated
resources from templates that implement the list()
method:
Dynamic Resource Reading: Resource templates support URI template patterns (RFC 6570) that allow clients to construct dynamic resource identifiers. When a client requests a resource URI that matches a template pattern, the template's read()
method is called with extracted parameters to generate the resource content.
Example workflow:
- Template defines pattern:
"database://users/{userId}/profile"
- Client requests:
"database://users/123/profile"
- Template extracts
{userId: "123"}
and callsread()
method - Template returns user profile data for user ID 123
You can also list templates separately using the resources/templates/list
endpoint:
When running your Laravel MCP server remotely, the HTTP transport works with
standard JSON-RPC requests. Here is a simple example using curl
to list and
read resources:
The server responds with JSON messages streamed over the HTTP connection, so
curl --no-buffer
can be used if you want to see incremental output.
Working with Prompts
Prompts provide reusable text snippets with argument support that your tools or users can request.
Create prompt classes in app/MCP/Prompts
using:
Register them in config/mcp-server.php
under prompts
. Each prompt class
extends the Prompt
base class and defines:
name
: Unique identifier (e.g., "welcome-user")description
: Optional human-readable descriptionarguments
: Array of argument definitions with name, description, and required fieldstext
: The prompt template with placeholders like{username}
List prompts via the prompts/list
endpoint and fetch them using
prompts/get
with arguments:
MCP Prompts
When crafting prompts that reference your tools or resources, consult the official prompt guidelines. Prompts are reusable templates that can accept arguments, include resource context and even describe multi-step workflows.
Prompt structure
Clients discover prompts via prompts/list
and request specific ones with prompts/get
:
Example Prompt Class
Prompts can embed resources and return sequences of messages to guide an LLM. See the official documentation for advanced examples and best practices.
Testing MCP Tools
The package includes a special command for testing your MCP tools without needing a real MCP client:
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:
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):
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 (required only for the legacy SSE provider)
-
- In the Inspector interface, enter your Laravel server's MCP endpoint URL (e.g.,
http://localhost:8000/mcp
). If you are using the legacy SSE provider, use the SSE URL instead (http://localhost:8000/mcp/sse
). - Connect and explore available tools visually
The MCP endpoint follows the pattern: http://[your-laravel-server]/[default_path]
where default_path
is defined in your config/mcp-server.php
file.
Advanced Features
Pub/Sub Architecture with SSE Adapters (legacy provider)
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 applies only when using the legacy SSE provider.
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:
Translation README.md
To translate this README to other languages using Claude API (Parallel processing):
You can also translate specific languages:
Deprecated Features for v2.0.0
The following features are deprecated and will be removed in v2.0.0. Please update your code accordingly:
ToolInterface Changes
Deprecated since v1.3.0:
messageType(): ProcessMessageType
method- Replacement: Use
isStreaming(): bool
instead - Migration Guide: Return
false
for HTTP tools,true
for streaming tools - Automatic Migration: Run
php artisan mcp:migrate-tools
to update your tools
Example Migration:
Removed Features
Removed in v1.3.0:
ProcessMessageType::PROTOCOL
enum case (consolidated intoProcessMessageType::HTTP
)
Planning for v2.0.0:
- Complete removal of
messageType()
method fromToolInterface
- All tools will be required to implement
isStreaming()
method only - Simplified tool configuration and reduced complexity
License
This project is distributed under the MIT license.
All versions of laravel-mcp-server with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^10.0||^11.0||^12.0