Laravel MCP Server
Secure bridge between AI clients and local Laravel projects, enabling AI to run artisan commands, read logs and routes, and safely read/write code with layered security protections.
README
๐ Laravel MCP Server
AI-Powered Laravel Development Assistant โ Secure bridge between AI Clients (Claude Desktop, Cursor, VS Code) and your local Laravel projects.
<div align="center">
</div>
โ ๏ธ Security Notice
This package intentionally requires system access for its core functionality (executing artisan commands, reading logs, etc.). All operations are protected by a 10-layer security system including:
- Input sanitization & command validation
- Path traversal prevention
- Production environment blocking
- Rate limiting & audit logging
- No shell injection (uses
execFileonly)
For local development only. Never use in production.
๐ข Expected npm/Socket Security Alerts
When installing this package, you may see alerts from npm or Socket.dev about:
- Shell Access โ Required - safely executes
php artisancommands - Filesystem Access โ Required - reads Laravel logs and source files
- Environment Variables โ Required - validates
APP_ENVto block production - Network Access โ Required - MCP protocol communication
- AI-detected risks โ Expected - automated scanners flag dev tools
These are NOT vulnerabilities - they are legitimate features of a Laravel development tool, all protected by our security layers. See SECURITY.md for complete details on how each capability is secured.
๐ Security Monitoring
We maintain enterprise-grade security through:
- โ CodeQL Analysis - Automated code security scanning
- โ Socket Security - Real-time dependency and supply chain monitoring
- โ Dependabot - Dependency vulnerability alerts
- โ Security Tests - 19 security-focused tests
- ๐ SBOM Available - Full software bill of materials
- ๐ OpenSSF Scorecard - Best practice monitoring (weekly)
See SUPPLY_CHAIN_SECURITY.md for complete security details.
๐ Table of Contents
- What is Laravel MCP Server?
- Features
- Security Architecture
- Installation
- Quick Start
- Configuration
- Usage Examples
- Tools Reference
- Security Details
- Troubleshooting
- Contributing
- License
๐ฏ What is Laravel MCP Server?
Laravel MCP Server adalah MCP (Model Context Protocol) Server berbasis TypeScript/Node.js yang memungkinkan AI Assistant seperti Claude untuk:
- โ
Menjalankan perintah
php artisandengan aman - โ Membaca dan menganalisis Laravel logs
- โ Melihat routes, config, dan structure proyek
- โ Membaca dan menulis source code (dengan proteksi ketat)
- โ Menjalankan kode PHP via Tinker (dalam sandbox mode)
Mengapa dibuat? AI modern sangat powerful untuk development, tapi memberikan akses terminal langsung ke AI sangat berbahaya. Server ini memberikan controlled access dengan 10 lapis security layer yang dirancang khusus untuk mencegah kerusakan pada proyek Laravel kamu.
โจ Features
๐ง 7 Powerful Tools
| Tool | Fungsi | Access Level |
|---|---|---|
run_artisan |
Jalankan perintah artisan yang aman | ๐ข Always Active |
read_logs |
Baca Laravel logs dengan filter | ๐ข Always Active |
list_routes |
Lihat semua routes dengan filter | ๐ข Always Active |
read_env |
Lihat .env dengan credential masking |
๐ก Masked by Default |
read_file |
Baca source code proyek | ๐ข Always Active |
write_file |
Tulis/edit file proyek | ๐ด Requires --allow-write |
run_tinker |
Jalankan PHP code via Tinker | ๐ด Requires --allow-tinker |
๐ 3 Laravel Resources
laravel://envโ Static view of.envdengan credential maskinglaravel://routesโ JSON view lengkap semua routeslaravel://config/{key}โ Dynamic config reader (contoh:laravel://config/app.name)
๐ฌ 3 Smart Prompts
debug-errorโ Otomatis baca logs dan minta AI menganalisis errorcreate-crudโ Template untuk generate CRUD lengkap (Model, Migration, Controller, Routes)review-codeโ Code review dengan fokus Laravel best practices
๐ก๏ธ 10-Layer Security System
- Environment Gate โ Menolak start jika
APP_ENV=production - Rate Limiter โ Max 30 perintah/menit, 500 perintah/jam
- Command Classifier โ 3-tier risk classification (READ_ONLY, CAUTIOUS, DANGEROUS)
- Input Sanitizer โ Blokir shell injection (
;,&&,$(), backticks, dll) - Flag Validator โ Blokir
--force,--seed,--drop-*,--wipe - Path Protector โ Blokir path traversal (
../, symlinks keluar project) - Write Guard โ Whitelist directory + extension untuk
write_file - Tinker Sandbox โ Blokir 15+ fungsi PHP berbahaya
- Execution Sandbox โ Timeout ketat, no shell access (
execFileonly) - Audit Trail โ Log semua operasi ke
.laravel-mcp-audit.jsonl
๐๏ธ Security Architecture
3-Tier Command Classification
Setiap perintah artisan dikategorikan berdasarkan tingkat risiko:
| Tier | Warna | Level | Contoh Perintah | Perlakuan |
|---|---|---|---|---|
| ๐ข READ_ONLY | Hijau | Aman | about, route:list, config:show |
Langsung dieksekusi |
| ๐ก CAUTIOUS | Kuning | Hati-hati | make:*, migrate, cache:clear |
Audit log + Rate limited |
| ๐ด DANGEROUS | Merah | Berbahaya | migrate:fresh, db:wipe, down |
DIBLOKIR TOTAL |
Permanently Blocked Commands (20+)
Perintah berikut TIDAK PERNAH bisa dijalankan, bahkan dengan flag khusus:
migrate:fresh โ Hapus SEMUA tabel + migrate ulang
migrate:reset โ Rollback SEMUA migrations
migrate:refresh โ Reset + re-migrate database
db:wipe โ Hapus SEMUA tabel, views, types
down โ Matikan aplikasi (maintenance mode)
tinker โ Ada tool terpisah yang lebih aman
serve โ Blocking command yang bisa hang server
queue:restart โ Restart semua queue workers
vendor:publish โ Bisa overwrite file penting
package:discover โ Security risk
Lihat full list di: implementation_plan.md - Tier DANGEROUS
File Write Protection
Tool write_file hanya bisa menulis ke directory yang di-whitelist:
โ Allowed Directories:
app/ โ Models, Controllers, Services
routes/ โ Route definitions
database/migrations/ โ Migration files
database/seeders/ โ Seeder files
database/factories/ โ Factory definitions
resources/views/ โ Blade templates
config/ โ Config files
tests/ โ Test files
โ Blocked Directories:
.env, vendor/, node_modules/, storage/, public/,
bootstrap/, artisan, composer.json, .git/
โ Allowed Extensions:
.php, .blade.php, .json, .yaml, .yml, .xml, .stub, .md, .txt
โ Blocked Extensions:
.sh, .bat, .exe, .phar, .js, .env*
Auto Backup System
Setiap kali write_file mengubah file yang sudah ada, server otomatis membuat backup ke:
.laravel-mcp-backup/
โโโ User.php.2026-08-01T143022.bak
โโโ ProductController.php.2026-08-01T143045.bak
โโโ ...
๐ฆ Installation
Prerequisites
- Node.js 18.0 atau lebih baru
- PHP 8.0 atau lebih baru
- Laravel Project (lokal di mesin kamu)
Install via npm (Recommended)
# Install globally
npm install -g @falzz1010/laravel-mcp-server
# Verify installation
laravel-mcp --version
Install from Source
# Clone repository
git clone https://github.com/Falzz1010/laravel-mcp-server.git
cd laravel-mcp-server
# Install dependencies
npm install
# Build TypeScript โ JavaScript
npm run build
Verify Installation
# Test security layer
npm test
# Expected output:
# โ All security tests passed (19 tests)
๐ Quick Start
1. Basic Usage (Read-Only Mode)
Mode paling aman โ hanya bisa baca data, tidak bisa menulis:
node build/index.js /path/to/your/laravel-project
Yang bisa dilakukan:
- โ
Jalankan perintah artisan READ_ONLY (
route:list,about, dll) - โ
Baca logs (
read_logs) - โ
Baca source code (
read_file) - โ
Lihat
.envdengan masking (read_env) - โ Tidak bisa menulis file
- โ Tidak bisa jalankan Tinker
2. With Write Access
Izinkan AI menulis/edit file proyek (dengan whitelist ketat):
node build/index.js /path/to/your/laravel-project --allow-write
Tambahan yang bisa dilakukan:
- โ
Generate controller, model, migration via
make:* - โ
Edit file di
app/,routes/,database/,config/,tests/ - โ Auto backup sebelum overwrite
3. With Tinker Access
Izinkan AI menjalankan kode PHP (dalam sandbox mode):
node build/index.js /path/to/your/laravel-project --allow-tinker
Tambahan yang bisa dilakukan:
- โ
Query database via Eloquent:
User::count() - โ
Test helpers:
cache()->get('key') - โ
Manipulasi data:
User::find(1)->update(['name' => 'Test']) - โ Diblokir:
exec(),system(),unlink(),file_put_contents(), dll
4. Full Access Mode (USE WITH CAUTION!)
node build/index.js /path/to/your/laravel-project --allow-write --allow-tinker
5. Dry-Run Mode (Preview Only)
Lihat preview command tanpa benar-benar menjalankannya:
node build/index.js /path/to/your/laravel-project --dry-run
โ๏ธ Configuration
Claude Desktop Configuration
Edit claude_desktop_config.json (biasanya di %APPDATA%\Claude\ atau ~/.config/claude/):
Using Global npm Package (Recommended)
{
"mcpServers": {
"laravel-dev": {
"command": "npx",
"args": [
"@falzz1010/laravel-mcp-server",
"E:/xampp/htdocs/my-laravel-app"
]
}
}
}
Using Local Installation
{
"mcpServers": {
"laravel-dev": {
"command": "node",
"args": [
"E:/desain-ui/laravel-mcp-server/build/index.js",
"E:/xampp/htdocs/my-laravel-app",
"--allow-write"
],
"env": {
"NODE_ENV": "production"
}
}
}
}
VS Code / Cursor Configuration
Using npm Package
Edit .vscode/settings.json atau Cursor settings:
{
"mcp.servers": {
"laravel": {
"command": "npx",
"args": [
"@falzz1010/laravel-mcp-server",
"${workspaceFolder}",
"--allow-write"
]
}
}
}
Using Local Installation
{
"mcp.servers": {
"laravel": {
"command": "node",
"args": [
"E:/desain-ui/laravel-mcp-server/build/index.js",
"${workspaceFolder}",
"--allow-write"
]
}
}
}
CLI Arguments Reference
| Argument | Default | Deskripsi |
|---|---|---|
[path] |
required | Path ke root proyek Laravel |
--allow-write |
false |
Aktifkan tool write_file |
--allow-tinker |
false |
Aktifkan tool run_tinker |
--dry-run |
false |
Preview mode (tidak eksekusi command) |
--php [path] |
php |
Custom PHP binary path |
--timeout [ms] |
30000 |
Timeout untuk artisan commands (ms) |
--rate-limit [n] |
30 |
Max requests per menit |
Contoh lengkap:
node build/index.js \
/var/www/laravel-app \
--allow-write \
--php /usr/bin/php8.2 \
--timeout 60000 \
--rate-limit 50
๐ก Usage Examples
Example 1: Debugging Error Logs
User berkata ke Claude:
"Ada error di aplikasi, coba lihat log dan jelasin masalahnya"
AI menggunakan tool read_logs:
{
"tool": "read_logs",
"arguments": {
"lines": 50,
"filter": "ERROR"
}
}
Output:
[2026-08-01 14:30:22] local.ERROR: Call to undefined method App\Models\User::getFullNameAttribute()
{"exception":"Error","file":"app/Http/Controllers/UserController.php","line":42}
AI menganalisis:
"Error terjadi karena method accessor
getFullNameAttribute()tidak ditemukan. Seharusnya accessor didefinisikan dengan prefixgetdan suffixAttribute. Coba tambahkan method ini di Model User..."
Example 2: Generate CRUD Resource
User:
"Bikin CRUD untuk Product dong, fieldnya: name, description, price, stock"
AI menggunakan prompt create-crud:
{
"prompt": "create-crud",
"arguments": {
"model_name": "Product",
"fields": "name:string,description:text,price:decimal,stock:integer"
}
}
AI kemudian menjalankan:
run_artisan make:model Product -mโ Buat Model + Migrationwrite_file database/migrations/..._create_products_table.phpโ Edit migrationrun_artisan make:controller ProductController --resourceโ Buat Controllerwrite_file routes/web.phpโ Tambahkan route resource
Example 3: Code Review
User:
"Review code di
app/Http/Controllers/OrderController.php"
AI menggunakan prompt review-code:
{
"prompt": "review-code",
"arguments": {
"file_path": "app/Http/Controllers/OrderController.php"
}
}
AI membaca file lalu memberikan feedback:
โ Positif:
- Controller menggunakan Form Request untuk validasi
- Query menggunakan Eloquent relationships dengan benar
โ ๏ธ Perlu Diperbaiki:
- Method
store()tidak menggunakan DB transaction, risiko partial save- Query di
index()bisa N+1 problem, tambahkanwith(['user', 'items'])- Tidak ada authorization check, sebaiknya gunakan Policy
๐ง Tools Reference
1. run_artisan
Jalankan perintah php artisan yang aman.
Parameters:
{
command: string; // e.g. "make:controller"
args?: string[]; // e.g. ["UserController", "--resource"]
}
Example:
{
"tool": "run_artisan",
"arguments": {
"command": "make:model",
"args": ["Product", "-m", "-c", "-r"]
}
}
Response:
{
"success": true,
"output": "Model created successfully.\nCreated Migration: 2026_08_01_143022_create_products_table",
"exitCode": 0
}
2. read_logs
Baca baris terakhir dari Laravel logs.
Parameters:
{
lines?: number; // Default: 100, Max: 500
filter?: string; // Keyword untuk filter (case-insensitive)
}
Example:
{
"tool": "read_logs",
"arguments": {
"lines": 50,
"filter": "ERROR"
}
}
3. list_routes
Lihat semua routes dengan optional filter.
Parameters:
{
method?: string; // Filter by HTTP method: GET, POST, PUT, DELETE
path?: string; // Filter by path pattern (regex)
}
Example:
{
"tool": "list_routes",
"arguments": {
"method": "POST",
"path": "/api/"
}
}
4. read_env
Baca file .env dengan credential masking.
Parameters:
{
show_values?: boolean; // Default: false (mask sensitive values)
}
Masked Keys:
PASSWORD, SECRET, KEY, TOKEN, HASH, PRIVATE, CREDENTIAL,
API_KEY, AUTH, MAIL_PASSWORD, AWS_*, REDIS_PASSWORD,
DB_PASSWORD, PUSHER_*, MIX_PUSHER_*
5. read_file
Baca source code dari proyek Laravel.
Parameters:
{
path: string; // Relative path dari root project
}
Example:
{
"tool": "read_file",
"arguments": {
"path": "app/Models/User.php"
}
}
Security:
- โ Path traversal protection
- โ Max file size: 1MB
- โ Cannot read
.env(useread_envinstead)
6. write_file (Requires --allow-write)
Tulis/edit file di proyek Laravel.
Parameters:
{
path: string; // Relative path
content: string; // File content
}
Example:
{
"tool": "write_file",
"arguments": {
"path": "app/Models/Product.php",
"content": "<?php\n\nnamespace App\\Models;\n..."
}
}
Security:
- โ
Directory whitelist (only
app/,routes/,database/,config/,tests/) - โ
Extension whitelist (
.php,.blade.php,.json,.yaml, dll) - โ
Auto backup ke
.laravel-mcp-backup/ - โ Max file size: 500KB
- โ Cannot write to
.env,vendor/,node_modules/, dll
7. run_tinker (Requires --allow-tinker)
Jalankan kode PHP via Tinker.
Parameters:
{
code: string; // PHP code (tanpa <?php tag)
}
Example:
{
"tool": "run_tinker",
"arguments": {
"code": "User::count()"
}
}
Security:
- โ Timeout ultra-ketat: 10 detik
- โ Max code length: 2000 karakter
- โ Blocked functions:
exec(),system(),shell_exec(),passthru(),popen(),proc_open(),unlink(),rmdir(),file_put_contents(),fwrite(),curl_exec(),eval(), dll (15+ functions) - โ Blocked keywords:
::truncate(),::delete(),->forceDelete(),DB::statement(),DB::unprepared(),Schema::drop(), dll
๐ Security Details
Audit Logging
Semua operasi dicatat dalam JSON Lines format di:
{laravelPath}/.laravel-mcp-audit.jsonl
Example log entry:
{"timestamp":"2026-08-01T14:30:22.000Z","sessionId":"abc123","tool":"run_artisan","tier":"CAUTIOUS","command":"make:controller","args":["ProductController","--resource"],"exitCode":0,"outputSize":45,"status":"ALLOWED","duration":1523}
Fields:
timestampโ ISO 8601 timestampsessionIdโ Unique per server sessiontoolโ Tool yang dipanggiltierโ Risk tier (READ_ONLY, CAUTIOUS, DANGEROUS)commandโ Artisan command (if applicable)argsโ Command argumentsfilePathโ File yang dibaca/ditulis (if applicable)exitCodeโ Command exit codeoutputSizeโ Output size in bytesfileHashโ SHA-256 hash dari file yang ditulisstatusโ ALLOWED / BLOCKED / ERRORreasonโ Alasan jika blockeddurationโ Execution duration in ms
Rate Limiting
Default limits:
- 30 requests per menit
- 500 requests per jam
- 2 detik cooldown minimum antar perintah CAUTIOUS
READ_ONLY commands tidak dihitung dalam limit.
Jika limit tercapai:
{
"error": "RATE_LIMIT_EXCEEDED",
"message": "Too many requests. Try again in 15 seconds.",
"retryAfterMs": 15000
}
Environment Protection
Server menolak untuk start jika:
# .env file contains:
APP_ENV=production
Error message:
[FATAL ERROR] Refusing to run in PRODUCTION environment.
This server is designed for LOCAL development only.
Warning untuk staging:
# .env file contains:
APP_ENV=staging
Warning message:
[WARNING] Running in STAGING environment. Proceed with caution.
๐ Development & Debugging
MCP Inspector
Gunakan MCP Inspector untuk debug tools secara interaktif:
# Install inspector (jika belum)
npm install -g @modelcontextprotocol/inspector
# Run inspector
npm run inspect /path/to/laravel-project
Inspector akan:
- Start MCP server
- Buka web interface di browser
- Tampilkan semua tools, resources, prompts
- Izinkan testing tool secara interaktif
Development Mode
Watch mode untuk auto-rebuild saat edit code:
npm run dev /path/to/laravel-project
Enable Debug Logging
Set environment variable untuk verbose logging:
# Unix/Mac
DEBUG=mcp:* node build/index.js /path/to/laravel-project
# Windows CMD
set DEBUG=mcp:* && node build/index.js /path/to/laravel-project
# Windows PowerShell
$env:DEBUG="mcp:*"; node build/index.js /path/to/laravel-project
๐ Troubleshooting
Error: "Invalid Laravel path"
Problem: Server tidak menemukan file artisan di path yang diberikan.
Solution:
# Pastikan path mengarah ke ROOT project Laravel
ls /path/to/laravel-project/artisan
# Bukan ke subfolder
# โ SALAH: /path/to/laravel-project/app
# โ
BENAR: /path/to/laravel-project
Error: "Refusing to run in PRODUCTION environment"
Problem: File .env memiliki APP_ENV=production.
Solution:
# Edit .env
APP_ENV=local # atau 'development'
# Server ini HANYA untuk development, TIDAK untuk production!
Error: "PHP binary not found"
Problem: Command php tidak ditemukan di PATH.
Solution:
# Option 1: Tambahkan PHP ke PATH (recommended)
export PATH="/usr/local/bin:$PATH"
# Option 2: Specify PHP path explicitly
node build/index.js /path/to/laravel --php /usr/bin/php8.2
Error: "Command not allowed"
Problem: AI mencoba menjalankan command yang di-blocklist.
Solution:
Ini adalah fitur keamanan. Command berbahaya seperti migrate:fresh, db:wipe, dll memang diblokir secara permanen.
Workaround:
# Jalankan manual di terminal kamu (jika benar-benar diperlukan)
cd /path/to/laravel-project
php artisan migrate:fresh --seed
Tools tidak muncul di Claude Desktop
Problem: Setelah konfigurasi, tools tidak muncul.
Solution:
- Restart Claude Desktop
- Cek file config path:
- Windows:
%APPDATA%\Claude\claude_desktop_config.json - Mac:
~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:
- Cek build folder exist:
ls build/index.js - Test manual:
node build/index.js /path/to/laravel-project # Should output: [INFO] Laravel MCP Server running on stdio transport.
๐งช Running Tests
Full Test Suite
npm test
Expected output:
โ classifyCommand() - READ_ONLY commands (7 tests)
โ classifyCommand() - CAUTIOUS commands (12 tests)
โ classifyCommand() - DANGEROUS commands (20 tests)
โ sanitizeArgs() - Shell injection protection (8 tests)
โ isPathSafe() - Path traversal protection (6 tests)
โ isWriteAllowed() - Write protection (5 tests)
โ sanitizeTinkerCode() - Tinker sandbox (8 tests)
โ Rate Limiter (4 tests)
โ Environment check (3 tests)
Total: 40 tests passed
Run Specific Test File
# Unix/Mac
node --test build/tests/security.test.js
# Windows
node --test build\tests\security.test.js
๐ค Contributing
Kontribusi sangat welcome! Terutama untuk:
- Security improvements โ Additional validation, better sandboxing
- Tool additions โ New Laravel-specific tools
- Bug fixes โ Especially edge cases di Windows/Mac/Linux
- Documentation โ Tutorial, use cases, best practices
Contribution guidelines:
- Fork repository
- Create feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open Pull Request
Testing requirements:
- โ
Semua test harus pass:
npm test - โ
TypeScript harus compile tanpa error:
npm run build - โ Tambahkan test untuk fitur baru
๐ License
MIT License โ feel free to use in your projects!
๐ Acknowledgments
- Model Context Protocol โ MCP SDK
- Anthropic โ Claude Desktop
- Laravel โ The PHP Framework
๐ Support
- ๐ Documentation: implementation_plan.md
- ๐ Bug Reports: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
<div align="center">
Made with โค๏ธ for Laravel Developers
โญ Star this repo if you find it useful!
</div>
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
Neon Database
MCP server for interacting with Neon Management API and databases
E2B
Using MCP to run code via e2b.
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.