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.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

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

Build Status Total Downloads Latest Stable Version License

Official Website

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:

Deprecated Features:

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:

  1. New Method Added:

    • messageType(): ProcessMessageType
      • This method is crucial for the new HTTP stream support and determines the type of message being processed.
  2. Method Renames:
    • getName() is now name()
    • getDescription() is now description()
    • getInputSchema() is now inputSchema()
    • getAnnotations() is now annotations()

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:

  1. Identify old tools: It looks for classes implementing the ToolInterface with the old method signatures.
  2. 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.
  3. Refactor the Tool:
    • Rename methods:
      • getName() to name()
      • getDescription() to description()
      • getInputSchema() to inputSchema()
      • getAnnotations() to annotations()
    • Add the new messageType() method, which will default to returning ProcessMessageType::SSE.
    • Ensure the use OPGG\LaravelMcpServer\Enums\ProcessMessageType; statement is present.

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:

By implementing the MCP server with Streamable HTTP transport, enterprises can:

Key benefits:

Key Features

Transport Providers

The configuration option server_provider controls which transport is used. Available providers are:

  1. 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).
  2. 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

Installation

  1. Install the package via Composer:

  2. 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:

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:

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:

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:

Most tools should return false unless you specifically need real-time streaming capabilities like:

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:

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:

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:

  1. Template defines pattern: "database://users/{userId}/profile"
  2. Client requests: "database://users/123/profile"
  3. Template extracts {userId: "123"} and calls read() method
  4. 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:

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:

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:

  1. 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)
  2. 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).
  3. 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:

  1. Publisher (Server): When clients send requests to the /message endpoint, the server processes these requests and publishes responses through the configured adapter.

  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.

  3. 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:

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:

Example Migration:

Removed Features

Removed in v1.3.0:

Planning for v2.0.0:

License

This project is distributed under the MIT license.


All versions of laravel-mcp-server with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^10.0||^11.0||^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package opgginc/laravel-mcp-server contains the following files

Loading the files please wait ....