Laravel MCP
Comprehensive guide for building MCP (Model Context Protocol) servers with Laravel. Contains 7 rules across 5 categories for exposing tools, prompts, and resources to AI clients.
When to Apply
Reference these guidelines when:
- Creating MCP servers (web or local)
- Building tools that AI clients can call
- Defining prompts for reusable AI interactions
- Exposing resources for AI context
- Protecting MCP servers with OAuth or Sanctum
- Testing MCP servers, tools, prompts, and resources
Rule Categories by Priority
| Priority |
Category |
Impact |
Prefix |
| 1 |
Servers |
CRITICAL |
server- |
| 2 |
Tools |
HIGH |
tool- |
| 3 |
Prompts & Resources |
MEDIUM |
prompt-, resource- |
| 4 |
Authentication |
HIGH |
auth- |
| 5 |
Testing |
HIGH |
test- |
Quick Reference
1. Servers (CRITICAL)
server-create-register - Create and register web or local MCP servers
2. Tools (HIGH)
tool-create - Create tools with input/output schemas, DI, and annotations
tool-responses - Text, error, structured, streaming, and multi-content responses
3. Prompts & Resources (MEDIUM)
prompt-create - Create prompts with arguments, validation, and responses
resource-create - Create resources and resource templates with URI patterns
4. Authentication (HIGH)
auth-protect - Protect servers with OAuth 2.1, Sanctum, or custom auth
5. Testing (HIGH)
test-unit - Test with MCP Inspector and unit tests
Essential Patterns
Creating an MCP Server
<?php
namespace App\Mcp\Servers;
use Laravel\Mcp\Server;
use Laravel\Mcp\Server\Attributes\Instructions;
use Laravel\Mcp\Server\Attributes\Name;
use Laravel\Mcp\Server\Attributes\Version;
#[Name('Weather Server')]
#[Version('1.0.0')]
#[Instructions('This server provides weather information.')]
class WeatherServer extends Server
{
protected array $tools = [
CurrentWeatherTool::class,
];
protected array $resources = [];
protected array $prompts = [];
}
Registering in routes/ai.php
use App\Mcp\Servers\WeatherServer;
use Laravel\Mcp\Facades\Mcp;
Mcp::web('/mcp/weather', WeatherServer::class);
Mcp::local('weather', WeatherServer::class);
Creating a Tool
<?php
namespace App\Mcp\Tools;
use Illuminate\Contracts\JsonSchema\JsonSchema;
use Laravel\Mcp\Request;
use Laravel\Mcp\Response;
use Laravel\Mcp\Server\Attributes\Description;
use Laravel\Mcp\Server\Tool;
#[Description('Fetches the current weather for a location.')]
class CurrentWeatherTool extends Tool
{
public function handle(Request $request): Response
{
$location = $request->get('location');
return Response::text("The weather in {$location} is sunny, 72°F.");
}
public function schema(JsonSchema $schema): array
{
return [
'location' => $schema->string()
->description('The location to get the weather for.')
->required(),
];
}
}
How to Use
Read individual rule files for detailed explanations and code examples.
Each rule file contains:
- YAML frontmatter with metadata (title, impact, tags)
- Brief explanation of why it matters
- Bad Example with explanation
- Good Example with explanation
- Laravel 13 and PHP 8.3 specific context and references
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md
1---2name: laravel-mcp3description: Laravel MCP server development. Use when building MCP servers, tools, prompts, or resources for AI client integration. Triggers on tasks involving laravel/mcp, MCP tools, MCP prompts, MCP resources, or AI client protocols.4license: MIT5metadata:6 source: https://skillmd.com/skills/asyrafhussin/laravel-mcp7 author: Laravel Community8 version: "1.0.0"9 laravelVersion: "13.x"10 phpVersion: "8.3+"11---1213# Laravel MCP1415Comprehensive guide for building MCP (Model Context Protocol) servers with Laravel. Contains 7 rules across 5 categories for exposing tools, prompts, and resources to AI clients.1617## When to Apply1819Reference these guidelines when:20- Creating MCP servers (web or local)21- Building tools that AI clients can call22- Defining prompts for reusable AI interactions23- Exposing resources for AI context24- Protecting MCP servers with OAuth or Sanctum25- Testing MCP servers, tools, prompts, and resources2627## Rule Categories by Priority2829| Priority | Category | Impact | Prefix |30|----------|----------|--------|--------|31| 1 | Servers | CRITICAL | `server-` |32| 2 | Tools | HIGH | `tool-` |33| 3 | Prompts & Resources | MEDIUM | `prompt-`, `resource-` |34| 4 | Authentication | HIGH | `auth-` |35| 5 | Testing | HIGH | `test-` |3637## Quick Reference3839### 1. Servers (CRITICAL)4041- `server-create-register` - Create and register web or local MCP servers4243### 2. Tools (HIGH)4445- `tool-create` - Create tools with input/output schemas, DI, and annotations46- `tool-responses` - Text, error, structured, streaming, and multi-content responses4748### 3. Prompts & Resources (MEDIUM)4950- `prompt-create` - Create prompts with arguments, validation, and responses51- `resource-create` - Create resources and resource templates with URI patterns5253### 4. Authentication (HIGH)5455- `auth-protect` - Protect servers with OAuth 2.1, Sanctum, or custom auth5657### 5. Testing (HIGH)5859- `test-unit` - Test with MCP Inspector and unit tests6061## Essential Patterns6263### Creating an MCP Server6465```php66<?php6768namespace App\Mcp\Servers;6970use Laravel\Mcp\Server;71use Laravel\Mcp\Server\Attributes\Instructions;72use Laravel\Mcp\Server\Attributes\Name;73use Laravel\Mcp\Server\Attributes\Version;7475#[Name('Weather Server')]76#[Version('1.0.0')]77#[Instructions('This server provides weather information.')]78class WeatherServer extends Server79{80 protected array $tools = [81 CurrentWeatherTool::class,82 ];8384 protected array $resources = [];8586 protected array $prompts = [];87}88```8990### Registering in routes/ai.php9192```php93use App\Mcp\Servers\WeatherServer;94use Laravel\Mcp\Facades\Mcp;9596Mcp::web('/mcp/weather', WeatherServer::class);97Mcp::local('weather', WeatherServer::class);98```99100### Creating a Tool101102```php103<?php104105namespace App\Mcp\Tools;106107use Illuminate\Contracts\JsonSchema\JsonSchema;108use Laravel\Mcp\Request;109use Laravel\Mcp\Response;110use Laravel\Mcp\Server\Attributes\Description;111use Laravel\Mcp\Server\Tool;112113#[Description('Fetches the current weather for a location.')]114class CurrentWeatherTool extends Tool115{116 public function handle(Request $request): Response117 {118 $location = $request->get('location');119120 return Response::text("The weather in {$location} is sunny, 72°F.");121 }122123 public function schema(JsonSchema $schema): array124 {125 return [126 'location' => $schema->string()127 ->description('The location to get the weather for.')128 ->required(),129 ];130 }131}132```133134## How to Use135136Read individual rule files for detailed explanations and code examples.137138Each rule file contains:139- YAML frontmatter with metadata (title, impact, tags)140- Brief explanation of why it matters141- Bad Example with explanation142- Good Example with explanation143- Laravel 13 and PHP 8.3 specific context and references144145## Full Compiled Document146147For the complete guide with all rules expanded: `AGENTS.md`