Laravel v12 - The PHP Framework For Web Artisans (project, gitignored)
Laravel MCP Skill
Comprehensive assistance with Laravel MCP (Model Context Protocol) development. Laravel MCP provides a simple and elegant way for AI clients to interact with your Laravel application through the Model Context Protocol, enabling you to define servers, tools, resources, and prompts for AI-powered interactions.
When to Use This Skill
This skill should be triggered when:
Building MCP servers for Laravel applications
Creating AI tools that perform actions in Laravel
Defining reusable prompts for AI interactions
Exposing Laravel resources (data/content) to AI clients
Implementing OAuth 2.1 or Sanctum authentication for MCP
Registering and configuring MCP routes (web or local)
Testing MCP servers and tools
Working with Laravel JSON Schema builder for tool inputs
Implementing streaming responses or progress notifications
Building AI-powered Laravel features using MCP
Key Concepts
Core Components
MCP Server: The central communication point that exposes MCP capabilities. Each server has:
name: Server identifier
version: Server version
instructions: Description of the server's purpose
tools: Array of tool classes
resources: Array of resource classes
prompts: Array of prompt classes
Tools: Enable AI clients to perform actions. Tools can:
Define input schemas using Laravel's JSON Schema builder
Validate arguments with Laravel validation rules
Support dependency injection
Return single or multiple responses
Stream responses using generators
Use annotations like #[IsReadOnly] and #[IsIdempotent]
Prompts: Reusable prompt templates that provide a standardized way to structure common queries with argument definitions and validation.
Resources: Enable your server to expose data and content that AI clients can read, including text and blob responses with customizable MIME types and URIs.
<?phpnamespaceApp\Mcp\Prompts;
useLaravel\Mcp\Server\Prompt;
useLaravel\Mcp\Server\Prompts\Argument;
classDescribeWeatherPromptextendsPrompt{
protectedstring$description = 'Generates a natural-language explanation of the weather.';
publicfunctionarguments(): array{
return [
newArgument(
name: 'tone',
description: 'The tone to use in the weather description.',
required: true,
),
];
}
publicfunctionhandle(Request $request): array{
$tone = $request->string('tone');
return [
Response::text("You are a weather assistant. Provide a {$tone} tone.")->asAssistant(),
Response::text("What is the current weather like in New York City?"),
];
}
}
8. Resource Definition
<?phpnamespaceApp\Mcp\Resources;
useLaravel\Mcp\Request;
useLaravel\Mcp\Response;
useLaravel\Mcp\Server\Resource;
classWeatherGuidelinesResourceextendsResource{
protectedstring$description = 'Comprehensive guidelines for using the Weather API.';
protectedstring$uri = 'weather://resources/guidelines';
protectedstring$mimeType = 'application/pdf';
publicfunctionhandle(Request $request): Response{
returnResponse::text($weatherData);
}
}
9. Server Registration (Web)
useApp\Mcp\Servers\WeatherServer;
useLaravel\Mcp\Facades\Mcp;
Mcp::web('/mcp/weather', WeatherServer::class);
// With middlewareMcp::web('/mcp/weather', WeatherServer::class)
->middleware(['throttle:mcp']);