MCP (Model Context Protocol) server builder for Laravilt Framework

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/laravilt/mcp

v0.0.1 2025-11-12 16:22 UTC

This package is auto-updated.

Last update: 2025-12-02 13:11:17 UTC


README

Model Context Protocol (MCP) server builder for Laravilt Framework.

Installation

composer require laravilt/mcp

Overview

The MCP package enables you to expose Laravilt Resources through the Model Context Protocol, allowing AI assistants and other MCP clients to interact with your application's data.

Features

  • Automatic MCP server generation from Resources
  • CRUD operations exposed as MCP tools
  • Resource listing and reading capabilities
  • Type-safe tool definitions
  • Built-in validation and error handling
  • Support for custom tools and resources

Usage

Basic MCP Server

use Laravilt\MCP\MCPServer;
use Laravilt\MCP\ResourceMCPServer;

class UserMCPServer extends ResourceMCPServer
{
    protected string $resource = UserResource::class;

    public function tools(): array
    {
        return [
            $this->listResourceTool(),
            $this->readResourceTool(),
            $this->createResourceTool(),
            $this->updateResourceTool(),
            $this->deleteResourceTool(),
        ];
    }
}

Custom Tools

use Laravilt\MCP\Tools\MCPTool;

class SearchUserTool extends MCPTool
{
    public function name(): string
    {
        return 'search_users';
    }

    public function description(): string
    {
        return 'Search users by name or email';
    }

    public function parameters(): array
    {
        return [
            'query' => [
                'type' => 'string',
                'description' => 'Search query',
                'required' => true,
            ],
        ];
    }

    public function execute(array $arguments): array
    {
        $query = $arguments['query'];
        $users = User::where('name', 'like', "%{$query}%")
            ->orWhere('email', 'like', "%{$query}%")
            ->get();

        return [
            'users' => UserResource::collection($users)->toArray(),
        ];
    }
}

Registering MCP Servers

// In your service provider
use Laravilt\MCP\MCPServer;

MCPServer::register([
    UserMCPServer::class,
    PostMCPServer::class,
]);

MCP Protocol

The MCP (Model Context Protocol) is a standard protocol for exposing application capabilities to AI assistants. This package implements the protocol specification, allowing your Laravel application to communicate with Claude, GPT, and other MCP-compatible clients.

Testing

composer test              # Run tests
composer test:coverage     # With coverage
composer test:types        # PHPStan analysis
composer test:style        # Code style check
composer format            # Auto-fix code style

Changelog

Please see CHANGELOG for more information.

Contributing

Please see CONTRIBUTING for details.

Security

Please review SECURITY for security issues.

License

The MIT License (MIT). Please see License File for more information.