Adds new MCP tools to Laravel Boost for Eloquent model introspection. Designed for AI assistants and development tools that need to understand your application's data structure.
Provides complete model schemas, relationships and accessors so AI assistants can generate more accurate Eloquent queries and code without needing to read through multiple model files. This reduces token usage, speeds up responses, and eliminates guesswork about your database structure.
- MCP Tools - Expose model schemas to AI assistants via Laravel MCP
- Model Discovery - Automatically discover models in your app and configured vendor packages
- Schema Introspection - Extract columns, relationships, and accessors from models
- Caching - Built-in caching for performance
- Vendor Support - Include models from packages like Spatie Permission, Media Library, etc.
- PHP 8.2+
- Laravel 11 or 12
- Laravel MCP package (optional, for MCP tools)
composer require visualbuilder/eloquent-schemaPublish the configuration file:
php artisan vendor:publish --tag=eloquent-schema-config// config/eloquent-schema.php
return [
// Cache TTL in seconds (0 to disable)
'cache_ttl' => env('ELOQUENT_SCHEMA_CACHE_TTL', 3600),
// Additional model paths to scan
'model_paths' => [
// app_path('Domain/Models'),
],
// Explicitly include specific models
'additional_models' => [
// \App\Models\SomeModel::class,
],
// Exclude specific models from discovery
'excluded_models' => [
// \App\Models\ExcludedModel::class,
],
// Vendor packages to include (use composer package names)
'included_packages' => [
// 'spatie/laravel-permission',
// 'spatie/laravel-medialibrary',
],
// MCP tools configuration
'mcp' => [
'enabled' => true,
],
];This package provides three MCP tools for AI assistants:
List all discoverable Eloquent models in the application.
Parameters:
filter(string, optional) - Filter models by name (case-insensitive partial match)include_vendor(boolean, default: false) - Include models from vendor packages
Example Response:
{
"count": 5,
"namespace": "App\\Models",
"models": ["User", "Order", "Product"],
"vendor_models": ["Spatie\\Permission\\Models\\Role", "Spatie\\Permission\\Models\\Permission"]
}Note: Combine namespace + model name for the full class (e.g., App\Models\User). Vendor models include their full namespace. The vendor_models key is only present when vendor models exist.
Get the complete schema for an Eloquent model including columns, relationships, and accessors.
Parameters:
model(string, required) - Fully qualified model class namemax_depth(integer, default: 2, max: 3) - Depth for relationship exploration
Example Response:
{
"model": "App\\Models\\Order",
"table": "orders",
"columns": {
"id": "bigint",
"user_id": "bigint",
"status": {
"type": "enum:pending|processing|shipped|delivered",
"enum_class": "App\\Enums\\OrderStatus"
},
"total": "decimal",
"created_at": "datetime",
"updated_at": "datetime"
},
"accessors": {
"formatted_total": "string"
},
"relationships": {
"user": {
"type": "BelongsTo",
"model": "User"
},
"lineItems": {
"type": "HasMany",
"model": "OrderLineItem"
}
}
}Get a compact list of model columns and relationship names. Useful for building queries.
Parameters:
model(string, required) - Fully qualified model class name
Example Response:
{
"model": "App\\Models\\Order",
"table": "orders",
"columns": ["id", "user_id", "status", "total", "created_at", "updated_at"],
"accessors": ["formatted_total"],
"relationships": ["user", "lineItems", "payments"]
}# List all app models
php artisan eloquent-schema:list
# Include vendor models
php artisan eloquent-schema:list --vendor
# Filter by name
php artisan eloquent-schema:list --filter=User
# Show count only
php artisan eloquent-schema:list --countInteractively discover and select vendor packages with Eloquent models:
# Interactive selection
php artisan eloquent-schema:discover
# List available packages without selection
php artisan eloquent-schema:discover --list# Warm the cache (discovers models and preloads schemas)
php artisan eloquent-schema:cache
# Skip schema preloading
php artisan eloquent-schema:cache --no-schema
# Set relationship depth for schema caching (warning: depth 2+ uses significant memory)
php artisan eloquent-schema:cache --max-depth=2
# Clear the cache
php artisan eloquent-schema:clear
# Clear including individual schema caches
php artisan eloquent-schema:clear --schemaTest the eloquent-schema MCP tools directly from the command line:
# Test list-models
php artisan eloquent-schema:mcp list-models
php artisan eloquent-schema:mcp list-models --vendor --filter=User
# Test model-schema
php artisan eloquent-schema:mcp model-schema --model='App\Models\Order'
php artisan eloquent-schema:mcp model-schema --model='App\Models\Order' --max-depth=2
# Test model-fields
php artisan eloquent-schema:mcp model-fields --model='App\Models\Order'List and call any registered MCP tool (works with Laravel Boost and custom tools):
# List all available MCP tools
php artisan mcp:tools --list
# Describe a tool's parameters
php artisan mcp:tools ModelSchema --describe
# Call any MCP tool with arguments
php artisan mcp:tools GetConfig --args='{"key":"app.name"}'
php artisan mcp:tools ListModels
php artisan mcp:tools DatabaseSchema --args='{"filter":"users"}'
php artisan mcp:tools ModelSchema --args='{"model":"App\\Models\\Order","max_depth":1}'To include models from vendor packages:
-
Run the discovery command to find packages with models:
php artisan eloquent-schema:discover
-
Select the packages you want to include
-
Add the suggested configuration to
config/eloquent-schema.php:'included_packages' => [ 'spatie/laravel-permission', 'spatie/laravel-medialibrary', ],
-
Warm the cache:
php artisan eloquent-schema:cache
When your app extends a vendor model, the package intelligently prefers your app model:
App\Models\UserextendsSpatie\Permission\Models\User→ OnlyApp\Models\Useris included- Models with the same basename prefer the App version
Add the tools to your config/boost.php:
'mcp' => [
'tools' => [
'include' => [
\Visualbuilder\EloquentSchema\Mcp\Tools\ListModels::class,
\Visualbuilder\EloquentSchema\Mcp\Tools\ModelSchema::class,
\Visualbuilder\EloquentSchema\Mcp\Tools\ModelFields::class,
],
'exclude' => [],
],
],If using a custom MCP server, register the tools in your server class:
use Visualbuilder\EloquentSchema\Mcp\Tools\ListModels;
use Visualbuilder\EloquentSchema\Mcp\Tools\ModelSchema;
use Visualbuilder\EloquentSchema\Mcp\Tools\ModelFields;
class YourServer extends Server
{
protected array $tools = [
ListModels::class,
ModelSchema::class,
ModelFields::class,
];
}You can also use the services directly:
use Visualbuilder\EloquentSchema\Services\ModelDiscoveryService;
use Visualbuilder\EloquentSchema\Services\ModelSchemaService;
// Discover models
$discovery = app(ModelDiscoveryService::class);
$models = $discovery->getModels(includeVendor: true);
// Get schema for a model
$schema = app(ModelSchemaService::class);
$orderSchema = $schema->getSchema(Order::class, maxDepth: 2);
// Get flat field list
$fields = $schema->getFlatFieldList(Order::class);Caching improves performance when frequently querying model schemas:
# Warm the cache (recommended after model changes)
php artisan eloquent-schema:cache
# Clear the cache when models change
php artisan eloquent-schema:clear --schemaSet cache TTL via environment variable:
ELOQUENT_SCHEMA_CACHE_TTL=3600
Set to 0 to disable caching during active development.
MIT License. See LICENSE for details.