PHPackages                             php-mcp/laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. php-mcp/laravel

ActiveLibrary[Framework](/categories/framework)

php-mcp/laravel
===============

Laravel SDK for building Model Context Protocol (MCP) servers - Seamlessly integrate MCP tools, resources, and prompts into Laravel applications

3.1.0(10mo ago)47283.1k↑19.8%29[2 PRs](https://github.com/php-mcp/laravel/pulls)1MITPHPPHP ^8.1CI passing

Since Apr 28Pushed 9mo ago9 watchersCompare

[ Source](https://github.com/php-mcp/laravel)[ Packagist](https://packagist.org/packages/php-mcp/laravel)[ Docs](https://github.com/php-mcp/laravel)[ RSS](/packages/php-mcp-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (9)Versions (10)Used By (1)

Laravel MCP Server SDK
======================

[](#laravel-mcp-server-sdk)

[![Latest Version on Packagist](https://camo.githubusercontent.com/981479a60268a0e684aa81e07094b4d1599b1f372fd308a938b232b65beb3294/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068702d6d63702f6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/php-mcp/laravel)[![Total Downloads](https://camo.githubusercontent.com/1fb43199526d587f162003f070d1121e9bd815ff26abedaaee40f198652b3b25/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068702d6d63702f6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/php-mcp/laravel)[![License](https://camo.githubusercontent.com/0c279b29894265e23857766883f9a4d85eb80060eca1fc91c6edd3b851dd2edc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7068702d6d63702f6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

**A comprehensive Laravel SDK for building [Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) servers with enterprise-grade features and Laravel-native integrations.**

This SDK provides a Laravel-optimized wrapper for the powerful [`php-mcp/server`](https://github.com/php-mcp/server) library, enabling you to expose your Laravel application's functionality as standardized MCP **Tools**, **Resources**, **Prompts**, and **Resource Templates** for AI assistants like Anthropic's Claude, Cursor IDE, OpenAI's ChatGPT, and others.

Key Features
------------

[](#key-features)

- **Laravel-Native Integration**: Deep integration with Laravel's service container, configuration, caching, logging, sessions, and Artisan console
- **Fluent Element Definition**: Define MCP elements with an elegant, Laravel-style API using the `Mcp` facade
- **Attribute-Based Discovery**: Use PHP 8 attributes (`#[McpTool]`, `#[McpResource]`, etc.) with automatic discovery and caching
- **Advanced Session Management**: Laravel-native session handlers (file, database, cache, redis) with automatic garbage collection
- **Flexible Transport Options**:
    - **Integrated HTTP**: Serve through Laravel routes with middleware support
    - **Dedicated HTTP Server**: High-performance standalone ReactPHP server
    - **STDIO**: Command-line interface for direct client integration
- **Streamable Transport**: Enhanced HTTP transport with resumability and event sourcing
- **Artisan Commands**: Commands for serving, discovery, and element management
- **Full Test Coverage**: Comprehensive test suite ensuring reliability

This package supports the **2025-03-26** version of the Model Context Protocol.

Requirements
------------

[](#requirements)

- **PHP** &gt;= 8.1
- **Laravel** &gt;= 10.0
- **Extensions**: `json`, `mbstring`, `pcre` (typically enabled by default)

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require php-mcp/laravel:^3.0 -W
```

Publish the configuration file:

```
php artisan vendor:publish --provider="PhpMcp\Laravel\McpServiceProvider" --tag="mcp-config"
```

For database session storage, publish the migration:

```
php artisan vendor:publish --provider="PhpMcp\Laravel\McpServiceProvider" --tag="mcp-migrations"
php artisan migrate
```

Configuration
-------------

[](#configuration)

All MCP server settings are managed through `config/mcp.php`, which contains comprehensive documentation for each option. The configuration covers server identity, capabilities, discovery settings, session management, transport options, caching, and logging. All settings support environment variables for easy deployment management.

Key configuration areas include:

- **Server Info**: Name, version, and basic identity
- **Capabilities**: Control which MCP features are enabled (tools, resources, prompts, etc.)
- **Discovery**: How elements are found and cached from your codebase
- **Session Management**: Multiple storage backends (file, database, cache, redis) with automatic garbage collection
- **Transports**: STDIO, integrated HTTP, and dedicated HTTP server options
- **Performance**: Caching strategies and pagination limits

Review the published `config/mcp.php` file for detailed documentation of all available options and their environment variable overrides.

Defining MCP Elements
---------------------

[](#defining-mcp-elements)

Laravel MCP provides two powerful approaches for defining MCP elements: **Manual Registration** (using the fluent `Mcp` facade) and **Attribute-Based Discovery** (using PHP 8 attributes). Both can be combined, with manual registrations taking precedence.

### Element Types

[](#element-types)

- **Tools**: Executable functions/actions (e.g., `calculate`, `send_email`, `query_database`)
- **Resources**: Static content/data accessible via URI (e.g., `config://settings`, `file://readme.txt`)
- **Resource Templates**: Dynamic resources with URI patterns (e.g., `user://{id}/profile`)
- **Prompts**: Conversation starters/templates (e.g., `summarize`, `translate`)

### 1. Manual Registration

[](#1-manual-registration)

Define your MCP elements using the elegant `Mcp` facade in `routes/mcp.php`:

```
