LMAD MCP Laravel API Discovery Tools
Introduction
When working with AI coding assistants like Claude Code, Cursor, or GitHub Copilot with Laravel projects, there's often a gap in what the AI can understand. The assistants can see the routes, but they lack context about:
- What validation rules apply to a POST request?
- What fields does the API actually return?
- Where is the controller method defined?
- What authorization logic is in place?
This means constantly having to copy-paste code, explain FormRequest rules, and describe JsonResource structures to the AI assistant. It's tedious and slows down development significantly.
LMAD (Laravel MCP API Discovery) is a new package that bridges this gap. It's an MCP (Model Context Protocol) server that gives AI assistants deep understanding of Laravel APIs. Instead of just route listings, LMAD provides complete endpoint analysis including validation rules, response schemas, file locations, and more.
You can find the package on GitHub: https://github.com/0xmergen/lmad
What is MCP?
MCP (Model Context Protocol) is an open standard that allows AI assistants to connect to external data sources and tools. Instead of an AI being limited to its training data, MCP enables it to:
- Query your application's codebase in real-time
- Access tools that can analyze your code
- Provide context-aware assistance based on your actual code
Think of MCP as a "bridge" between AI assistants and your Laravel application.
Installation
You'll need at least PHP 8.2 and Laravel 11.0 to use this package.
composer require 0xmergen/lmad
After installing, LMAD will automatically register its MCP server in your Laravel application.
Configuring Your AI Assistant
LMAD works with several AI assistants that support MCP. Here's how to set it up:
Claude Code
Create or edit your Claude Desktop config file:
macOS/Linux: ~/.claude.json
{
"mcpServers": {
"lmad": {
"command": "php",
"args": [
"artisan",
"mcp:start",
"lmad"
],
"env": {
"APP_ENV": "local"
}
}
}
}
Cline (VS Code)
Install the Cline extension from the VS Code Marketplace.
Open VS Code Settings, search for "Cline: MCP Servers", and add:
{
"lmad": {
"command": "php",
"args": [
"artisan",
"mcp:start",
"lmad"
],
"env": {
"APP_ENV": "local"
}
}
}
Cursor
Cursor has built-in MCP support. Add the server configuration in your Cursor settings:
{
"mcpServers": {
"lmad": {
"command": "php",
"args": [
"artisan",
"mcp:start",
"lmad"
],
"env": {
"APP_ENV": "local"
}
}
}
}
After configuring, restart your AI assistant. The LMAD tools will be available for use when working on your Laravel project.
What LMAD Provides
LMAD provides 5 MCP tools that AI assistants can use to understand your Laravel APIs:
-
list_api_routes- List all API routes with filtering -
get_route_details- Get detailed route information -
get_request_rules- Analyze FormRequest validation rules -
get_response_schema- Understand what APIs return -
analyze_endpoint- Complete endpoint analysis (all-in-one)
Listing API Routes
The list_api_routes tool allows listing all API routes with optional filters. For example, to find all CRM-related routes:
The tool returns comprehensive information including:
- Route URI and HTTP method
- Controller class and method
- Route middleware
- File paths for easy navigation
Unlike Laravel Boost's basic route listing, LMAD provides:
- Wildcard pattern matching (
api/crm/*) - Multiple filter options (method, domain, vendor exclusion)
- Exact file locations
Analyzing Request Validation
One of LMAD's most powerful features is the get_request_rules tool, which analyzes FormRequest validation rules.
For a FormRequest like App\Http\Requests\Crm\Company\StoreRequest, the tool returns:
{
"class": "App\\Http\\Requests\\Crm\\Company\\StoreRequest",
"rules": {
"name": ["required", "string", "max:255"],
"tax_number": ["nullable", "string", "max:50"],
"email": ["nullable", "email", "max:255"],
"employee_count": ["nullable", "integer", "min:0"],
"status": ["nullable", "in:active,inactive,prospect"]
},
"custom_messages": {},
"custom_attributes": {},
"authorization": {
"type": "bool",
"returns": true
}
}
This means your AI assistant can:
- Generate valid API request payloads
- Understand validation error scenarios
- Know what fields are required/optional
- See authorization logic at a glance
Understanding Response Schemas
The get_response_schema tool analyzes what your API endpoints actually return.
For a controller method returning a JsonResource:
{
"type": "json_resource",
"resource_class": "App\\Http\\Resources\\Crm\\Company\\CompanyResource",
"fields": [
"id", "name", "tax_number", "email", "phone",
"website", "address", "city", "country",
"employee_count", "status", "customers_count",
"contacts_count", "created_at", "updated_at"
],
"file": "app/Http/Resources/Crm/Company/CompanyResource.php",
"start_line": 13
}
Now your AI assistant knows:
- The exact structure of API responses
- Which fields are returned
- Where to find the Resource class
- Conditional fields like
whenCounted()
Complete Endpoint Analysis
The analyze_endpoint tool combines everything into a single call. For POST api/crm/companies, it returns:
{
"route": {
"uri": "api/crm/companies",
"method": "POST",
"middleware": ["api"],
"name": "companies.store"
},
"controller": {
"class": "App\\Http\\Controllers\\Crm\\CompanyController",
"method": "store",
"file": "app/Http/Controllers/Crm/CompanyController.php",
"start_line": 23
},
"request": {
"class": "App\\Http\\Requests\\Crm\\Company\\StoreRequest",
"rules": {
"name": ["required", "string", "max:255"],
"tax_number": ["nullable", "string", "max:50"]
}
},
"response": {
"type": "json_response",
"status_code": 201
}
}
With this information, AI assistants can:
- Generate accurate API calls
- Create valid test cases
- Write proper documentation
- Understand the complete request/response flow
LMAD vs Laravel Boost
| Feature | LMAD | Laravel Boost |
|---|---|---|
| Route Listing | ✅ | ✅ |
| FormRequest Analysis | ✅ | ❌ |
| Response Schema | ✅ | ❌ |
| File Locations | ✅ | ❌ |
| Authorization Logic | ✅ | ❌ |
| Complete Analysis | ✅ | ❌ |
Laravel Boost provides basic route information. LMAD goes much deeper.
How It Works
LMAD uses PHP Reflection to analyze your code without executing it:
-
Route Discovery - Parses Laravel's route collection via
RouteFacade::getRoutes() - Controller Inspection - Uses reflection to extract method signatures
- Request Analysis - Parses FormRequest rules (string and array formats)
- Response Analysis - Identifies JsonResource, Model, and Response types
- Aggregation - Combines everything into structured JSON
This means:
- No code execution required
- Safe to use in production
- Works with any Laravel project structure
- Laravel 12 compatible (no Kernel.php needed)
Real-World Use Cases
1. Auto-Generating API Documentation
Your AI assistant can generate accurate docs based on actual FormRequest and JsonResource classes.
2. Writing Integration Tests
$this->postJson('/api/crm/companies', [
'name' => 'Acme Corp',
'email' => 'info@acme.com',
'employee_count' => 50
])->assertCreated();
3. API Client Generation
Generate TypeScript interfaces based on actual JsonResource fields:
interface Company {
id: number;
name: string;
tax_number?: string;
email?: string;
employee_count?: number;
status?: 'active' | 'inactive' | 'prospect';
created_at: string;
updated_at: string;
}
Conclusion
LMAD fills an important gap for Laravel developers working with AI coding assistants. By providing deep API analysis through MCP, it enables AI assistants to understand your Laravel APIs at a much deeper level than simple route listings.
Whether you're generating documentation, writing tests, or building API clients, LMAD can significantly speed up your development workflow.
You can check out the package on GitHub: https://github.com/0xmergen/lmad
Metadata
Tags: laravel, mcp, model context protocol, ai, api, discovery, laravel 12, claude code, cursor, copilot
Author: @0xmergen
Estimated Reading Time: 5-7 minutes
Category: Packages
Top comments (0)