laravel-mcp-server-demo

TapanDerasari/laravel-mcp-server-demo

3.2

If you are the rightful owner of laravel-mcp-server-demo and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

This project is a demonstration of a Laravel-based Model Context Protocol (MCP) server implementation, focusing on user management through the MCP interface.

Tools
  1. get_users

    Provides paginated user data with filtering and sorting capabilities.

Laravel MCP Server Demo (WIP)

A demonstration of a Laravel-based Model Context Protocol (MCP) server implementation. This project showcases how to create and expose a custom tool for user management through the MCP interface.

Features

  • User Management API: RESTful endpoints for user operations
  • MCP Tool Integration: Implements the get_users MCP tool
  • Advanced Filtering: Filter users by role, active status, and more
  • Pagination & Sorting: Built-in support for pagination and field-based sorting
  • Authentication: User authentication system with role-based access control

Prerequisites

  • PHP 8.4 or higher
  • Composer
  • MySQL/PostgreSQL/SQLite
  • Laravel 12.x

Installation

  1. Clone the repository:

    git clone https://github.com/TapanDerasari/laravel-mcp-server-demo.git
    cd laravel-mcp-server-demo
    
  2. Install dependencies:

    composer install
    
  3. Copy the environment file and configure your database:

    cp .env.example .env
    php artisan key:generate
    
  4. Run migrations and seed the database:

    php artisan migrate --seed
    

Configuration

Edit the .env file to configure your database connection and other settings:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_mcp
DB_USERNAME=root
DB_PASSWORD=

Usage

MCP Tool: Get Users

The main MCP tool get_users provides paginated user data with filtering and sorting capabilities.

Endpoint
GET /mcp/test
Query Parameters
ParameterTypeDescription
searchstringSearch term for name or email (optional)
rolestringFilter by user role (admin, moderator, user)
is_activebooleanFilter by active status (true/false)
sortstringSort field with optional - prefix for descending
per_pageintegerNumber of items per page (default: 20, max: 100)
pageintegerPage number (default: 1)
Example Request
GET /mcp/test?search=john&role=admin&is_active=true&sort=-created_at&per_page=10&page=1
Example Response
{
    "data": [
        {
            "id": 1,
            "name": "John Doe",
            "email": "john@example.com",
            "role": "admin",
            "is_active": true,
            "created_at": "2023-01-01T00:00:00.000000Z",
            "updated_at": "2023-01-01T00:00:00.000000Z"
        }
    ],
    "meta": {
        "current_page": 1,
        "from": 1,
        "last_page": 1,
        "path": "http://localhost:8000/mcp/test",
        "per_page": 10,
        "to": 1,
        "total": 1
    }
}

MCP Client Configuration

To connect to this MCP server from a client application, add the following configuration to your MCP client's configuration file:

"laravel-mcp-server-demo": {
  "command": "npx",
  "args": [
    "-y",
    "mcp-remote",
    "http://localhost:8000/mcp"
  ],
  "disabledTools": [
    "example",
    "hello-world",
    "check-version"
  ]
}

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request