Skip to content

Latest commit

 

History

History
188 lines (144 loc) · 9.22 KB

File metadata and controls

188 lines (144 loc) · 9.22 KB

Full Laravel MCP Application with CodeRabbit AI (Part 1)

Disclaimer: This is a personal summary and interpretation based on a YouTube video. It is not official material and not endorsed by the original creator. All rights remain with the respective creators.

This document summarizes the key takeaways from the video. I highly recommend watching the full video for visual context and coding demonstrations.

Before You Get Started

  • I summarize key points to help you learn and review quickly.
  • Simply click on Ask AI links to dive into any topic you want.

AI-Powered buttons

Teach Me: 5 Years Old | Beginner | Intermediate | Advanced | (reset auto redirect)

Learn Differently: Analogy | Storytelling | Cheatsheet | Mindmap | Flashcards | Practical Projects | Code Examples | Common Mistakes

Check Understanding: Generate Quiz | Interview Me | Refactor Challenge | Assessment Rubric | Next Steps

What is Laravel MCP and Why It Matters

Laravel MCP is a new package that adds a dedicated entry point for AI agents (Cursor, Claude, Junie, etc.) to interact with your Laravel app — just like you already have web routes, API routes, and console commands. Think of it as “an API for agents”. It lets agents perform actions on behalf of the user without the user ever touching a browser or Postman.

Key analogy from Nuno:
Imagine a hotel. Reservations can come in via:

  • Phone call
  • Website form
  • Third-party API (booking.com)
  • MCP → AI agents call your app directly with natural language

Ask AI: Laravel MCP Basics

Project Goal – Nuno Nation Chat

We’re building a tiny chat app (“Nuno Nation Chat”) from scratch so anyone can:

  1. Open Cursor (or Claude)
  2. Say “I am Nuno, say good morning to the Nuno nation”
  3. The agent uses MCP → sends the message → fetches the timeline → shows it just works

No frontend yet – everything happens through AI agents via the MCP protocol.

Starter Kit & Domain Layer (Message Model)

Nuno uses his own strict starter kit (Pint, Rector, PHPStan level max, Pest, Laravel Essentials, etc.).

php artisan make:model Message -m

Migration:

$table->string('name');
$table->text('body');
$table->timestamps();

Model is left completely open (Model::unguard()) – Nuno prefers this over $fillable for small/internal tools.

Factory + model test for toArray() (ensures no hidden attributes leak).

All committed, pushed, reviewed by CodeRabbit (more on that below).

Ask AI: Laravel Message Model Setup

CodeRabbit AI – The Star of the Review Process

Nuno has been using CodeRabbit for a week and is genuinely impressed:

  • Auto-reviews every PR
  • Generates accurate sequence diagrams
  • Learns your preferences (e.g. final/readonly classes, no down() method, prefer Model::unguard)
  • Suggests real architectural improvements (add index on created_at, avoid key order in tests, etc.)
  • Free for open-source, 14-day trial for private repos, then Pro plan

He shows multiple live reviews where CodeRabbit catches bugs, suggests better practices, and even backs off when told “I actually like Model::unguard”.

Ask AI: CodeRabbit AI Code Review

Actions Pattern – The Core Business Logic

php artisan make:action CreateMessage
public function handle(string $name, string $body): Message
{
    return Message::create([
        'name' => $name,
        'body' => $body,
    ]);
}

Action is unit-tested and reused everywhere (MCP tool, future web controller, queue jobs, etc.). This is why Nuno loves actions — single source of truth for business rules.

Ask AI: Laravel Actions Pattern

Installing & Configuring Laravel MCP

composer require laravel/mcp
php artisan vendor:publish --tag=mcp-routes

Routes file: routes/ai.php – this is the entry point agents will hit (e.g. /mcp/chat).

Create server:

php artisan make:mcp-server NunoNationChat

Server class gets:

  • name, version
  • detailed $instructions (most important part!)
  • tools[], resources[], prompts[]

Nuno’s instructions example:

“This is the Nuno Nation chat server. It’s a friendly chat that allows users to have a conversation about various topics. Users can send messages or get messages to see what others have shared.”

Ask AI: Laravel MCP Server Setup

Creating the Send Message Tool

php artisan make:mcp-tool SendMessage

Key points Nuno emphasizes:

  • Tool description must be crystal clear
  • Schema defines exact JSON structure the agent must follow
  • Always validate the incoming data (schema is public but not enforced)

Schema example:

Schema::string('name')
    ->description('The name of the user sending the message. Ask the user for their first name if unknown. Never use "user", "assistant", "AI", etc.')
    ->minLength(1)
    ->maxLength(50)
    ->required(),

Schema::string('content')
    ->description('The message content')
    ->minLength(1)
    ->maxLength(500)
    ->required(),

Handle method:

  • Validates request
  • Resolves CreateMessage action
  • Returns markdown response: “Your message has been successfully sent…”

The tool reuses the same CreateMessage action we wrote earlier — perfect separation of concerns.

Ask AI: Laravel MCP Tool Creation

What’s Coming in Part 2 (teased)

  • GetMessages tool
  • Authentication / rate limiting
  • Deploying to production
  • Actually chatting with Nuno via Cursor/Claude in real time

About the summarizer

I'm Ali Sol, a Backend Developer. Learn more: