@falzz1010/laravel-mcp-server 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +100 -0
  2. package/LICENSE +21 -0
  3. package/README.md +866 -0
  4. package/build/index.d.ts +2 -0
  5. package/build/index.d.ts.map +1 -0
  6. package/build/index.js +101 -0
  7. package/build/index.js.map +1 -0
  8. package/build/prompts/laravel-prompts.d.ts +4 -0
  9. package/build/prompts/laravel-prompts.d.ts.map +1 -0
  10. package/build/prompts/laravel-prompts.js +81 -0
  11. package/build/prompts/laravel-prompts.js.map +1 -0
  12. package/build/resources/laravel-info.d.ts +4 -0
  13. package/build/resources/laravel-info.d.ts.map +1 -0
  14. package/build/resources/laravel-info.js +99 -0
  15. package/build/resources/laravel-info.js.map +1 -0
  16. package/build/tests/full-security-audit.test.d.ts +2 -0
  17. package/build/tests/full-security-audit.test.d.ts.map +1 -0
  18. package/build/tests/full-security-audit.test.js +226 -0
  19. package/build/tests/full-security-audit.test.js.map +1 -0
  20. package/build/tests/security.test.d.ts +2 -0
  21. package/build/tests/security.test.d.ts.map +1 -0
  22. package/build/tests/security.test.js +124 -0
  23. package/build/tests/security.test.js.map +1 -0
  24. package/build/tools/list-routes.d.ts +4 -0
  25. package/build/tools/list-routes.d.ts.map +1 -0
  26. package/build/tools/list-routes.js +68 -0
  27. package/build/tools/list-routes.js.map +1 -0
  28. package/build/tools/read-env.d.ts +4 -0
  29. package/build/tools/read-env.d.ts.map +1 -0
  30. package/build/tools/read-env.js +51 -0
  31. package/build/tools/read-env.js.map +1 -0
  32. package/build/tools/read-file.d.ts +4 -0
  33. package/build/tools/read-file.d.ts.map +1 -0
  34. package/build/tools/read-file.js +60 -0
  35. package/build/tools/read-file.js.map +1 -0
  36. package/build/tools/read-logs.d.ts +4 -0
  37. package/build/tools/read-logs.d.ts.map +1 -0
  38. package/build/tools/read-logs.js +60 -0
  39. package/build/tools/read-logs.js.map +1 -0
  40. package/build/tools/run-artisan.d.ts +5 -0
  41. package/build/tools/run-artisan.d.ts.map +1 -0
  42. package/build/tools/run-artisan.js +130 -0
  43. package/build/tools/run-artisan.js.map +1 -0
  44. package/build/tools/run-tinker.d.ts +4 -0
  45. package/build/tools/run-tinker.d.ts.map +1 -0
  46. package/build/tools/run-tinker.js +75 -0
  47. package/build/tools/run-tinker.js.map +1 -0
  48. package/build/tools/write-file.d.ts +4 -0
  49. package/build/tools/write-file.d.ts.map +1 -0
  50. package/build/tools/write-file.js +103 -0
  51. package/build/tools/write-file.js.map +1 -0
  52. package/build/utils/audit.d.ts +23 -0
  53. package/build/utils/audit.d.ts.map +1 -0
  54. package/build/utils/audit.js +52 -0
  55. package/build/utils/audit.js.map +1 -0
  56. package/build/utils/config.d.ts +12 -0
  57. package/build/utils/config.d.ts.map +1 -0
  58. package/build/utils/config.js +63 -0
  59. package/build/utils/config.js.map +1 -0
  60. package/build/utils/file.d.ts +8 -0
  61. package/build/utils/file.d.ts.map +1 -0
  62. package/build/utils/file.js +96 -0
  63. package/build/utils/file.js.map +1 -0
  64. package/build/utils/process.d.ts +16 -0
  65. package/build/utils/process.d.ts.map +1 -0
  66. package/build/utils/process.js +78 -0
  67. package/build/utils/process.js.map +1 -0
  68. package/build/utils/rate-limiter.d.ts +19 -0
  69. package/build/utils/rate-limiter.d.ts.map +1 -0
  70. package/build/utils/rate-limiter.js +57 -0
  71. package/build/utils/rate-limiter.js.map +1 -0
  72. package/build/utils/security.d.ts +23 -0
  73. package/build/utils/security.d.ts.map +1 -0
  74. package/build/utils/security.js +282 -0
  75. package/build/utils/security.js.map +1 -0
  76. package/package.json +61 -0
package/README.md ADDED
@@ -0,0 +1,866 @@
1
+ # ๐Ÿš€ Laravel MCP Server
2
+
3
+ > **AI-Powered Laravel Development Assistant** โ€” Secure bridge between AI Clients (Claude Desktop, Cursor, VS Code) and your local Laravel projects.
4
+
5
+ <div align="center">
6
+
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.5-blue?logo=typescript)](https://www.typescriptlang.org/)
8
+ [![Node.js](https://img.shields.io/badge/Node.js-18+-green?logo=node.js)](https://nodejs.org/)
9
+ [![Laravel](https://img.shields.io/badge/Laravel-8+-red?logo=laravel)](https://laravel.com/)
10
+ [![MCP](https://img.shields.io/badge/MCP-1.30-purple)](https://modelcontextprotocol.io/)
11
+
12
+ </div>
13
+
14
+ ---
15
+
16
+ ## ๐Ÿ“– Table of Contents
17
+
18
+ - [What is Laravel MCP Server?](#-what-is-laravel-mcp-server)
19
+ - [Features](#-features)
20
+ - [Security Architecture](#-security-architecture)
21
+ - [Installation](#-installation)
22
+ - [Quick Start](#-quick-start)
23
+ - [Configuration](#-configuration)
24
+ - [Usage Examples](#-usage-examples)
25
+ - [Tools Reference](#-tools-reference)
26
+ - [Security Details](#-security-details)
27
+ - [Troubleshooting](#-troubleshooting)
28
+ - [Contributing](#-contributing)
29
+ - [License](#-license)
30
+
31
+ ---
32
+
33
+ ## ๐ŸŽฏ What is Laravel MCP Server?
34
+
35
+ Laravel MCP Server adalah **MCP (Model Context Protocol) Server** berbasis TypeScript/Node.js yang memungkinkan AI Assistant seperti Claude untuk:
36
+
37
+ - โœ… Menjalankan perintah `php artisan` dengan aman
38
+ - โœ… Membaca dan menganalisis Laravel logs
39
+ - โœ… Melihat routes, config, dan structure proyek
40
+ - โœ… Membaca dan menulis source code (dengan proteksi ketat)
41
+ - โœ… Menjalankan kode PHP via Tinker (dalam sandbox mode)
42
+
43
+ **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.
44
+
45
+ ---
46
+
47
+ ## โœจ Features
48
+
49
+ ### ๐Ÿ”ง 7 Powerful Tools
50
+
51
+ | Tool | Fungsi | Access Level |
52
+ |------|--------|--------------|
53
+ | **`run_artisan`** | Jalankan perintah artisan yang aman | ๐ŸŸข Always Active |
54
+ | **`read_logs`** | Baca Laravel logs dengan filter | ๐ŸŸข Always Active |
55
+ | **`list_routes`** | Lihat semua routes dengan filter | ๐ŸŸข Always Active |
56
+ | **`read_env`** | Lihat `.env` dengan credential masking | ๐ŸŸก Masked by Default |
57
+ | **`read_file`** | Baca source code proyek | ๐ŸŸข Always Active |
58
+ | **`write_file`** | Tulis/edit file proyek | ๐Ÿ”ด Requires `--allow-write` |
59
+ | **`run_tinker`** | Jalankan PHP code via Tinker | ๐Ÿ”ด Requires `--allow-tinker` |
60
+
61
+ ### ๐Ÿ“‚ 3 Laravel Resources
62
+
63
+ - **`laravel://env`** โ€” Static view of `.env` dengan credential masking
64
+ - **`laravel://routes`** โ€” JSON view lengkap semua routes
65
+ - **`laravel://config/{key}`** โ€” Dynamic config reader (contoh: `laravel://config/app.name`)
66
+
67
+ ### ๐Ÿ’ฌ 3 Smart Prompts
68
+
69
+ - **`debug-error`** โ€” Otomatis baca logs dan minta AI menganalisis error
70
+ - **`create-crud`** โ€” Template untuk generate CRUD lengkap (Model, Migration, Controller, Routes)
71
+ - **`review-code`** โ€” Code review dengan fokus Laravel best practices
72
+
73
+ ### ๐Ÿ›ก๏ธ 10-Layer Security System
74
+
75
+ 1. **Environment Gate** โ€” Menolak start jika `APP_ENV=production`
76
+ 2. **Rate Limiter** โ€” Max 30 perintah/menit, 500 perintah/jam
77
+ 3. **Command Classifier** โ€” 3-tier risk classification (READ_ONLY, CAUTIOUS, DANGEROUS)
78
+ 4. **Input Sanitizer** โ€” Blokir shell injection (`;`, `&&`, `$()`, backticks, dll)
79
+ 5. **Flag Validator** โ€” Blokir `--force`, `--seed`, `--drop-*`, `--wipe`
80
+ 6. **Path Protector** โ€” Blokir path traversal (`../`, symlinks keluar project)
81
+ 7. **Write Guard** โ€” Whitelist directory + extension untuk `write_file`
82
+ 8. **Tinker Sandbox** โ€” Blokir 15+ fungsi PHP berbahaya
83
+ 9. **Execution Sandbox** โ€” Timeout ketat, no shell access (`execFile` only)
84
+ 10. **Audit Trail** โ€” Log semua operasi ke `.laravel-mcp-audit.jsonl`
85
+
86
+ ---
87
+
88
+ ## ๐Ÿ—๏ธ Security Architecture
89
+
90
+ ### 3-Tier Command Classification
91
+
92
+ Setiap perintah artisan dikategorikan berdasarkan tingkat risiko:
93
+
94
+ | Tier | Warna | Level | Contoh Perintah | Perlakuan |
95
+ |------|-------|-------|-----------------|-----------|
96
+ | ๐ŸŸข **READ_ONLY** | Hijau | Aman | `about`, `route:list`, `config:show` | Langsung dieksekusi |
97
+ | ๐ŸŸก **CAUTIOUS** | Kuning | Hati-hati | `make:*`, `migrate`, `cache:clear` | Audit log + Rate limited |
98
+ | ๐Ÿ”ด **DANGEROUS** | Merah | Berbahaya | `migrate:fresh`, `db:wipe`, `down` | **DIBLOKIR TOTAL** |
99
+
100
+ ### Permanently Blocked Commands (20+)
101
+
102
+ Perintah berikut **TIDAK PERNAH** bisa dijalankan, bahkan dengan flag khusus:
103
+
104
+ ```
105
+ migrate:fresh โ†’ Hapus SEMUA tabel + migrate ulang
106
+ migrate:reset โ†’ Rollback SEMUA migrations
107
+ migrate:refresh โ†’ Reset + re-migrate database
108
+ db:wipe โ†’ Hapus SEMUA tabel, views, types
109
+ down โ†’ Matikan aplikasi (maintenance mode)
110
+ tinker โ†’ Ada tool terpisah yang lebih aman
111
+ serve โ†’ Blocking command yang bisa hang server
112
+ queue:restart โ†’ Restart semua queue workers
113
+ vendor:publish โ†’ Bisa overwrite file penting
114
+ package:discover โ†’ Security risk
115
+ ```
116
+
117
+ **Lihat full list di:** [implementation_plan.md - Tier DANGEROUS](implementation_plan.md#tier-dangerous)
118
+
119
+ ### File Write Protection
120
+
121
+ Tool `write_file` hanya bisa menulis ke directory yang di-whitelist:
122
+
123
+ โœ… **Allowed Directories:**
124
+ ```
125
+ app/ โ†’ Models, Controllers, Services
126
+ routes/ โ†’ Route definitions
127
+ database/migrations/ โ†’ Migration files
128
+ database/seeders/ โ†’ Seeder files
129
+ database/factories/ โ†’ Factory definitions
130
+ resources/views/ โ†’ Blade templates
131
+ config/ โ†’ Config files
132
+ tests/ โ†’ Test files
133
+ ```
134
+
135
+ โŒ **Blocked Directories:**
136
+ ```
137
+ .env, vendor/, node_modules/, storage/, public/,
138
+ bootstrap/, artisan, composer.json, .git/
139
+ ```
140
+
141
+ โœ… **Allowed Extensions:**
142
+ ```
143
+ .php, .blade.php, .json, .yaml, .yml, .xml, .stub, .md, .txt
144
+ ```
145
+
146
+ โŒ **Blocked Extensions:**
147
+ ```
148
+ .sh, .bat, .exe, .phar, .js, .env*
149
+ ```
150
+
151
+ ### Auto Backup System
152
+
153
+ Setiap kali `write_file` mengubah file yang sudah ada, server otomatis membuat backup ke:
154
+
155
+ ```
156
+ .laravel-mcp-backup/
157
+ โ”œโ”€โ”€ User.php.2026-08-01T143022.bak
158
+ โ”œโ”€โ”€ ProductController.php.2026-08-01T143045.bak
159
+ โ””โ”€โ”€ ...
160
+ ```
161
+
162
+ ---
163
+
164
+ ## ๐Ÿ“ฆ Installation
165
+
166
+ ### Prerequisites
167
+
168
+ - **Node.js** 18.0 atau lebih baru
169
+ - **PHP** 8.0 atau lebih baru
170
+ - **Laravel Project** (lokal di mesin kamu)
171
+
172
+ ### Install Dependencies
173
+
174
+ ```bash
175
+ # Clone repository (jika dari Git)
176
+ git clone https://github.com/your-username/laravel-mcp-server.git
177
+ cd laravel-mcp-server
178
+
179
+ # Install dependencies
180
+ npm install
181
+
182
+ # Build TypeScript โ†’ JavaScript
183
+ npm run build
184
+ ```
185
+
186
+ ### Verify Installation
187
+
188
+ ```bash
189
+ # Test security layer
190
+ npm test
191
+
192
+ # Expected output:
193
+ # โœ“ All security tests passed (40 tests)
194
+ ```
195
+
196
+ ---
197
+
198
+ ## ๐Ÿš€ Quick Start
199
+
200
+ ### 1. Basic Usage (Read-Only Mode)
201
+
202
+ Mode paling aman โ€” hanya bisa baca data, tidak bisa menulis:
203
+
204
+ ```bash
205
+ node build/index.js /path/to/your/laravel-project
206
+ ```
207
+
208
+ **Yang bisa dilakukan:**
209
+ - โœ… Jalankan perintah artisan READ_ONLY (`route:list`, `about`, dll)
210
+ - โœ… Baca logs (`read_logs`)
211
+ - โœ… Baca source code (`read_file`)
212
+ - โœ… Lihat `.env` dengan masking (`read_env`)
213
+ - โŒ Tidak bisa menulis file
214
+ - โŒ Tidak bisa jalankan Tinker
215
+
216
+ ### 2. With Write Access
217
+
218
+ Izinkan AI menulis/edit file proyek (dengan whitelist ketat):
219
+
220
+ ```bash
221
+ node build/index.js /path/to/your/laravel-project --allow-write
222
+ ```
223
+
224
+ **Tambahan yang bisa dilakukan:**
225
+ - โœ… Generate controller, model, migration via `make:*`
226
+ - โœ… Edit file di `app/`, `routes/`, `database/`, `config/`, `tests/`
227
+ - โœ… Auto backup sebelum overwrite
228
+
229
+ ### 3. With Tinker Access
230
+
231
+ Izinkan AI menjalankan kode PHP (dalam sandbox mode):
232
+
233
+ ```bash
234
+ node build/index.js /path/to/your/laravel-project --allow-tinker
235
+ ```
236
+
237
+ **Tambahan yang bisa dilakukan:**
238
+ - โœ… Query database via Eloquent: `User::count()`
239
+ - โœ… Test helpers: `cache()->get('key')`
240
+ - โœ… Manipulasi data: `User::find(1)->update(['name' => 'Test'])`
241
+ - โŒ **Diblokir:** `exec()`, `system()`, `unlink()`, `file_put_contents()`, dll
242
+
243
+ ### 4. Full Access Mode (USE WITH CAUTION!)
244
+
245
+ ```bash
246
+ node build/index.js /path/to/your/laravel-project --allow-write --allow-tinker
247
+ ```
248
+
249
+ ### 5. Dry-Run Mode (Preview Only)
250
+
251
+ Lihat preview command tanpa benar-benar menjalankannya:
252
+
253
+ ```bash
254
+ node build/index.js /path/to/your/laravel-project --dry-run
255
+ ```
256
+
257
+ ---
258
+
259
+ ## โš™๏ธ Configuration
260
+
261
+ ### Claude Desktop Configuration
262
+
263
+ Edit `claude_desktop_config.json` (biasanya di `%APPDATA%\Claude\` atau `~/.config/claude/`):
264
+
265
+ ```json
266
+ {
267
+ "mcpServers": {
268
+ "laravel-dev": {
269
+ "command": "node",
270
+ "args": [
271
+ "E:/desain-ui/laravel-mcp-server/build/index.js",
272
+ "E:/xampp/htdocs/my-laravel-app",
273
+ "--allow-write"
274
+ ],
275
+ "env": {
276
+ "NODE_ENV": "production"
277
+ }
278
+ }
279
+ }
280
+ }
281
+ ```
282
+
283
+ ### VS Code / Cursor Configuration
284
+
285
+ Edit `.vscode/settings.json` atau Cursor settings:
286
+
287
+ ```json
288
+ {
289
+ "mcp.servers": {
290
+ "laravel": {
291
+ "command": "node",
292
+ "args": [
293
+ "E:/desain-ui/laravel-mcp-server/build/index.js",
294
+ "${workspaceFolder}",
295
+ "--allow-write"
296
+ ]
297
+ }
298
+ }
299
+ }
300
+ ```
301
+
302
+ ### CLI Arguments Reference
303
+
304
+ | Argument | Default | Deskripsi |
305
+ |----------|---------|-----------|
306
+ | `[path]` | *required* | Path ke root proyek Laravel |
307
+ | `--allow-write` | `false` | Aktifkan tool `write_file` |
308
+ | `--allow-tinker` | `false` | Aktifkan tool `run_tinker` |
309
+ | `--dry-run` | `false` | Preview mode (tidak eksekusi command) |
310
+ | `--php [path]` | `php` | Custom PHP binary path |
311
+ | `--timeout [ms]` | `30000` | Timeout untuk artisan commands (ms) |
312
+ | `--rate-limit [n]` | `30` | Max requests per menit |
313
+
314
+ **Contoh lengkap:**
315
+
316
+ ```bash
317
+ node build/index.js \
318
+ /var/www/laravel-app \
319
+ --allow-write \
320
+ --php /usr/bin/php8.2 \
321
+ --timeout 60000 \
322
+ --rate-limit 50
323
+ ```
324
+
325
+ ---
326
+
327
+ ## ๐Ÿ’ก Usage Examples
328
+
329
+ ### Example 1: Debugging Error Logs
330
+
331
+ **User berkata ke Claude:**
332
+ > "Ada error di aplikasi, coba lihat log dan jelasin masalahnya"
333
+
334
+ **AI menggunakan tool `read_logs`:**
335
+ ```json
336
+ {
337
+ "tool": "read_logs",
338
+ "arguments": {
339
+ "lines": 50,
340
+ "filter": "ERROR"
341
+ }
342
+ }
343
+ ```
344
+
345
+ **Output:**
346
+ ```
347
+ [2026-08-01 14:30:22] local.ERROR: Call to undefined method App\Models\User::getFullNameAttribute()
348
+ {"exception":"Error","file":"app/Http/Controllers/UserController.php","line":42}
349
+ ```
350
+
351
+ **AI menganalisis:**
352
+ > "Error terjadi karena method accessor `getFullNameAttribute()` tidak ditemukan. Seharusnya accessor didefinisikan dengan prefix `get` dan suffix `Attribute`. Coba tambahkan method ini di Model User..."
353
+
354
+ ### Example 2: Generate CRUD Resource
355
+
356
+ **User:**
357
+ > "Bikin CRUD untuk Product dong, fieldnya: name, description, price, stock"
358
+
359
+ **AI menggunakan prompt `create-crud`:**
360
+ ```json
361
+ {
362
+ "prompt": "create-crud",
363
+ "arguments": {
364
+ "model_name": "Product",
365
+ "fields": "name:string,description:text,price:decimal,stock:integer"
366
+ }
367
+ }
368
+ ```
369
+
370
+ **AI kemudian menjalankan:**
371
+ 1. `run_artisan make:model Product -m` โ†’ Buat Model + Migration
372
+ 2. `write_file database/migrations/..._create_products_table.php` โ†’ Edit migration
373
+ 3. `run_artisan make:controller ProductController --resource` โ†’ Buat Controller
374
+ 4. `write_file routes/web.php` โ†’ Tambahkan route resource
375
+
376
+ ### Example 3: Code Review
377
+
378
+ **User:**
379
+ > "Review code di `app/Http/Controllers/OrderController.php`"
380
+
381
+ **AI menggunakan prompt `review-code`:**
382
+ ```json
383
+ {
384
+ "prompt": "review-code",
385
+ "arguments": {
386
+ "file_path": "app/Http/Controllers/OrderController.php"
387
+ }
388
+ }
389
+ ```
390
+
391
+ **AI membaca file lalu memberikan feedback:**
392
+ > โœ… **Positif:**
393
+ > - Controller menggunakan Form Request untuk validasi
394
+ > - Query menggunakan Eloquent relationships dengan benar
395
+ >
396
+ > โš ๏ธ **Perlu Diperbaiki:**
397
+ > - Method `store()` tidak menggunakan DB transaction, risiko partial save
398
+ > - Query di `index()` bisa N+1 problem, tambahkan `with(['user', 'items'])`
399
+ > - Tidak ada authorization check, sebaiknya gunakan Policy
400
+
401
+ ---
402
+
403
+ ## ๐Ÿ”ง Tools Reference
404
+
405
+ ### 1. `run_artisan`
406
+
407
+ Jalankan perintah `php artisan` yang aman.
408
+
409
+ **Parameters:**
410
+ ```typescript
411
+ {
412
+ command: string; // e.g. "make:controller"
413
+ args?: string[]; // e.g. ["UserController", "--resource"]
414
+ }
415
+ ```
416
+
417
+ **Example:**
418
+ ```json
419
+ {
420
+ "tool": "run_artisan",
421
+ "arguments": {
422
+ "command": "make:model",
423
+ "args": ["Product", "-m", "-c", "-r"]
424
+ }
425
+ }
426
+ ```
427
+
428
+ **Response:**
429
+ ```json
430
+ {
431
+ "success": true,
432
+ "output": "Model created successfully.\nCreated Migration: 2026_08_01_143022_create_products_table",
433
+ "exitCode": 0
434
+ }
435
+ ```
436
+
437
+ ### 2. `read_logs`
438
+
439
+ Baca baris terakhir dari Laravel logs.
440
+
441
+ **Parameters:**
442
+ ```typescript
443
+ {
444
+ lines?: number; // Default: 100, Max: 500
445
+ filter?: string; // Keyword untuk filter (case-insensitive)
446
+ }
447
+ ```
448
+
449
+ **Example:**
450
+ ```json
451
+ {
452
+ "tool": "read_logs",
453
+ "arguments": {
454
+ "lines": 50,
455
+ "filter": "ERROR"
456
+ }
457
+ }
458
+ ```
459
+
460
+ ### 3. `list_routes`
461
+
462
+ Lihat semua routes dengan optional filter.
463
+
464
+ **Parameters:**
465
+ ```typescript
466
+ {
467
+ method?: string; // Filter by HTTP method: GET, POST, PUT, DELETE
468
+ path?: string; // Filter by path pattern (regex)
469
+ }
470
+ ```
471
+
472
+ **Example:**
473
+ ```json
474
+ {
475
+ "tool": "list_routes",
476
+ "arguments": {
477
+ "method": "POST",
478
+ "path": "/api/"
479
+ }
480
+ }
481
+ ```
482
+
483
+ ### 4. `read_env`
484
+
485
+ Baca file `.env` dengan credential masking.
486
+
487
+ **Parameters:**
488
+ ```typescript
489
+ {
490
+ show_values?: boolean; // Default: false (mask sensitive values)
491
+ }
492
+ ```
493
+
494
+ **Masked Keys:**
495
+ ```
496
+ PASSWORD, SECRET, KEY, TOKEN, HASH, PRIVATE, CREDENTIAL,
497
+ API_KEY, AUTH, MAIL_PASSWORD, AWS_*, REDIS_PASSWORD,
498
+ DB_PASSWORD, PUSHER_*, MIX_PUSHER_*
499
+ ```
500
+
501
+ ### 5. `read_file`
502
+
503
+ Baca source code dari proyek Laravel.
504
+
505
+ **Parameters:**
506
+ ```typescript
507
+ {
508
+ path: string; // Relative path dari root project
509
+ }
510
+ ```
511
+
512
+ **Example:**
513
+ ```json
514
+ {
515
+ "tool": "read_file",
516
+ "arguments": {
517
+ "path": "app/Models/User.php"
518
+ }
519
+ }
520
+ ```
521
+
522
+ **Security:**
523
+ - โœ… Path traversal protection
524
+ - โœ… Max file size: 1MB
525
+ - โŒ Cannot read `.env` (use `read_env` instead)
526
+
527
+ ### 6. `write_file` (Requires `--allow-write`)
528
+
529
+ Tulis/edit file di proyek Laravel.
530
+
531
+ **Parameters:**
532
+ ```typescript
533
+ {
534
+ path: string; // Relative path
535
+ content: string; // File content
536
+ }
537
+ ```
538
+
539
+ **Example:**
540
+ ```json
541
+ {
542
+ "tool": "write_file",
543
+ "arguments": {
544
+ "path": "app/Models/Product.php",
545
+ "content": "<?php\n\nnamespace App\\Models;\n..."
546
+ }
547
+ }
548
+ ```
549
+
550
+ **Security:**
551
+ - โœ… Directory whitelist (only `app/`, `routes/`, `database/`, `config/`, `tests/`)
552
+ - โœ… Extension whitelist (`.php`, `.blade.php`, `.json`, `.yaml`, dll)
553
+ - โœ… Auto backup ke `.laravel-mcp-backup/`
554
+ - โœ… Max file size: 500KB
555
+ - โŒ Cannot write to `.env`, `vendor/`, `node_modules/`, dll
556
+
557
+ ### 7. `run_tinker` (Requires `--allow-tinker`)
558
+
559
+ Jalankan kode PHP via Tinker.
560
+
561
+ **Parameters:**
562
+ ```typescript
563
+ {
564
+ code: string; // PHP code (tanpa <?php tag)
565
+ }
566
+ ```
567
+
568
+ **Example:**
569
+ ```json
570
+ {
571
+ "tool": "run_tinker",
572
+ "arguments": {
573
+ "code": "User::count()"
574
+ }
575
+ }
576
+ ```
577
+
578
+ **Security:**
579
+ - โœ… Timeout ultra-ketat: 10 detik
580
+ - โœ… Max code length: 2000 karakter
581
+ - โŒ **Blocked functions:** `exec()`, `system()`, `shell_exec()`, `passthru()`, `popen()`, `proc_open()`, `unlink()`, `rmdir()`, `file_put_contents()`, `fwrite()`, `curl_exec()`, `eval()`, dll (15+ functions)
582
+ - โŒ **Blocked keywords:** `::truncate()`, `::delete()`, `->forceDelete()`, `DB::statement()`, `DB::unprepared()`, `Schema::drop()`, dll
583
+
584
+ ---
585
+
586
+ ## ๐Ÿ”’ Security Details
587
+
588
+ ### Audit Logging
589
+
590
+ Semua operasi dicatat dalam **JSON Lines** format di:
591
+
592
+ ```
593
+ {laravelPath}/.laravel-mcp-audit.jsonl
594
+ ```
595
+
596
+ **Example log entry:**
597
+ ```json
598
+ {"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}
599
+ ```
600
+
601
+ **Fields:**
602
+ - `timestamp` โ€” ISO 8601 timestamp
603
+ - `sessionId` โ€” Unique per server session
604
+ - `tool` โ€” Tool yang dipanggil
605
+ - `tier` โ€” Risk tier (READ_ONLY, CAUTIOUS, DANGEROUS)
606
+ - `command` โ€” Artisan command (if applicable)
607
+ - `args` โ€” Command arguments
608
+ - `filePath` โ€” File yang dibaca/ditulis (if applicable)
609
+ - `exitCode` โ€” Command exit code
610
+ - `outputSize` โ€” Output size in bytes
611
+ - `fileHash` โ€” SHA-256 hash dari file yang ditulis
612
+ - `status` โ€” ALLOWED / BLOCKED / ERROR
613
+ - `reason` โ€” Alasan jika blocked
614
+ - `duration` โ€” Execution duration in ms
615
+
616
+ ### Rate Limiting
617
+
618
+ **Default limits:**
619
+ - 30 requests per menit
620
+ - 500 requests per jam
621
+ - 2 detik cooldown minimum antar perintah CAUTIOUS
622
+
623
+ **READ_ONLY commands tidak dihitung dalam limit.**
624
+
625
+ **Jika limit tercapai:**
626
+ ```json
627
+ {
628
+ "error": "RATE_LIMIT_EXCEEDED",
629
+ "message": "Too many requests. Try again in 15 seconds.",
630
+ "retryAfterMs": 15000
631
+ }
632
+ ```
633
+
634
+ ### Environment Protection
635
+
636
+ Server **menolak untuk start** jika:
637
+
638
+ ```bash
639
+ # .env file contains:
640
+ APP_ENV=production
641
+ ```
642
+
643
+ **Error message:**
644
+ ```
645
+ [FATAL ERROR] Refusing to run in PRODUCTION environment.
646
+ This server is designed for LOCAL development only.
647
+ ```
648
+
649
+ **Warning untuk staging:**
650
+ ```bash
651
+ # .env file contains:
652
+ APP_ENV=staging
653
+ ```
654
+
655
+ **Warning message:**
656
+ ```
657
+ [WARNING] Running in STAGING environment. Proceed with caution.
658
+ ```
659
+
660
+ ---
661
+
662
+ ## ๐Ÿ” Development & Debugging
663
+
664
+ ### MCP Inspector
665
+
666
+ Gunakan MCP Inspector untuk debug tools secara interaktif:
667
+
668
+ ```bash
669
+ # Install inspector (jika belum)
670
+ npm install -g @modelcontextprotocol/inspector
671
+
672
+ # Run inspector
673
+ npm run inspect /path/to/laravel-project
674
+ ```
675
+
676
+ **Inspector akan:**
677
+ 1. Start MCP server
678
+ 2. Buka web interface di browser
679
+ 3. Tampilkan semua tools, resources, prompts
680
+ 4. Izinkan testing tool secara interaktif
681
+
682
+ ### Development Mode
683
+
684
+ Watch mode untuk auto-rebuild saat edit code:
685
+
686
+ ```bash
687
+ npm run dev /path/to/laravel-project
688
+ ```
689
+
690
+ ### Enable Debug Logging
691
+
692
+ Set environment variable untuk verbose logging:
693
+
694
+ ```bash
695
+ # Unix/Mac
696
+ DEBUG=mcp:* node build/index.js /path/to/laravel-project
697
+
698
+ # Windows CMD
699
+ set DEBUG=mcp:* && node build/index.js /path/to/laravel-project
700
+
701
+ # Windows PowerShell
702
+ $env:DEBUG="mcp:*"; node build/index.js /path/to/laravel-project
703
+ ```
704
+
705
+ ---
706
+
707
+ ## ๐Ÿ› Troubleshooting
708
+
709
+ ### Error: "Invalid Laravel path"
710
+
711
+ **Problem:** Server tidak menemukan file `artisan` di path yang diberikan.
712
+
713
+ **Solution:**
714
+ ```bash
715
+ # Pastikan path mengarah ke ROOT project Laravel
716
+ ls /path/to/laravel-project/artisan
717
+
718
+ # Bukan ke subfolder
719
+ # โŒ SALAH: /path/to/laravel-project/app
720
+ # โœ… BENAR: /path/to/laravel-project
721
+ ```
722
+
723
+ ### Error: "Refusing to run in PRODUCTION environment"
724
+
725
+ **Problem:** File `.env` memiliki `APP_ENV=production`.
726
+
727
+ **Solution:**
728
+ ```bash
729
+ # Edit .env
730
+ APP_ENV=local # atau 'development'
731
+
732
+ # Server ini HANYA untuk development, TIDAK untuk production!
733
+ ```
734
+
735
+ ### Error: "PHP binary not found"
736
+
737
+ **Problem:** Command `php` tidak ditemukan di PATH.
738
+
739
+ **Solution:**
740
+ ```bash
741
+ # Option 1: Tambahkan PHP ke PATH (recommended)
742
+ export PATH="/usr/local/bin:$PATH"
743
+
744
+ # Option 2: Specify PHP path explicitly
745
+ node build/index.js /path/to/laravel --php /usr/bin/php8.2
746
+ ```
747
+
748
+ ### Error: "Command not allowed"
749
+
750
+ **Problem:** AI mencoba menjalankan command yang di-blocklist.
751
+
752
+ **Solution:**
753
+ Ini adalah **fitur keamanan**. Command berbahaya seperti `migrate:fresh`, `db:wipe`, dll memang diblokir secara permanen.
754
+
755
+ **Workaround:**
756
+ ```bash
757
+ # Jalankan manual di terminal kamu (jika benar-benar diperlukan)
758
+ cd /path/to/laravel-project
759
+ php artisan migrate:fresh --seed
760
+ ```
761
+
762
+ ### Tools tidak muncul di Claude Desktop
763
+
764
+ **Problem:** Setelah konfigurasi, tools tidak muncul.
765
+
766
+ **Solution:**
767
+ 1. Restart Claude Desktop
768
+ 2. Cek file config path:
769
+ - Windows: `%APPDATA%\Claude\claude_desktop_config.json`
770
+ - Mac: `~/Library/Application Support/Claude/claude_desktop_config.json`
771
+ 3. Cek build folder exist: `ls build/index.js`
772
+ 4. Test manual:
773
+ ```bash
774
+ node build/index.js /path/to/laravel-project
775
+ # Should output: [INFO] Laravel MCP Server running on stdio transport.
776
+ ```
777
+
778
+ ---
779
+
780
+ ## ๐Ÿงช Running Tests
781
+
782
+ ### Full Test Suite
783
+
784
+ ```bash
785
+ npm test
786
+ ```
787
+
788
+ **Expected output:**
789
+ ```
790
+ โœ“ classifyCommand() - READ_ONLY commands (7 tests)
791
+ โœ“ classifyCommand() - CAUTIOUS commands (12 tests)
792
+ โœ“ classifyCommand() - DANGEROUS commands (20 tests)
793
+ โœ“ sanitizeArgs() - Shell injection protection (8 tests)
794
+ โœ“ isPathSafe() - Path traversal protection (6 tests)
795
+ โœ“ isWriteAllowed() - Write protection (5 tests)
796
+ โœ“ sanitizeTinkerCode() - Tinker sandbox (8 tests)
797
+ โœ“ Rate Limiter (4 tests)
798
+ โœ“ Environment check (3 tests)
799
+
800
+ Total: 40 tests passed
801
+ ```
802
+
803
+ ### Run Specific Test File
804
+
805
+ ```bash
806
+ # Unix/Mac
807
+ node --test build/tests/security.test.js
808
+
809
+ # Windows
810
+ node --test build\tests\security.test.js
811
+ ```
812
+
813
+ ---
814
+
815
+ ## ๐Ÿค Contributing
816
+
817
+ Kontribusi sangat welcome! Terutama untuk:
818
+
819
+ 1. **Security improvements** โ€” Additional validation, better sandboxing
820
+ 2. **Tool additions** โ€” New Laravel-specific tools
821
+ 3. **Bug fixes** โ€” Especially edge cases di Windows/Mac/Linux
822
+ 4. **Documentation** โ€” Tutorial, use cases, best practices
823
+
824
+ **Contribution guidelines:**
825
+ 1. Fork repository
826
+ 2. Create feature branch: `git checkout -b feature/amazing-feature`
827
+ 3. Commit changes: `git commit -m 'Add amazing feature'`
828
+ 4. Push to branch: `git push origin feature/amazing-feature`
829
+ 5. Open Pull Request
830
+
831
+ **Testing requirements:**
832
+ - โœ… Semua test harus pass: `npm test`
833
+ - โœ… TypeScript harus compile tanpa error: `npm run build`
834
+ - โœ… Tambahkan test untuk fitur baru
835
+
836
+ ---
837
+
838
+ ## ๐Ÿ“„ License
839
+
840
+ MIT License โ€” feel free to use in your projects!
841
+
842
+ ---
843
+
844
+ ## ๐Ÿ™ Acknowledgments
845
+
846
+ - [Model Context Protocol](https://modelcontextprotocol.io/) โ€” MCP SDK
847
+ - [Anthropic](https://www.anthropic.com/) โ€” Claude Desktop
848
+ - [Laravel](https://laravel.com/) โ€” The PHP Framework
849
+
850
+ ---
851
+
852
+ ## ๐Ÿ“ž Support
853
+
854
+ - ๐Ÿ“– **Documentation:** [implementation_plan.md](implementation_plan.md)
855
+ - ๐Ÿ› **Bug Reports:** [GitHub Issues](https://github.com/your-username/laravel-mcp-server/issues)
856
+ - ๐Ÿ’ฌ **Discussions:** [GitHub Discussions](https://github.com/your-username/laravel-mcp-server/discussions)
857
+
858
+ ---
859
+
860
+ <div align="center">
861
+
862
+ **Made with โค๏ธ for Laravel Developers**
863
+
864
+ โญ Star this repo if you find it useful!
865
+
866
+ </div>