Laravel Mcp

作者 asyrafhussin1aa0ff717c10MIT86 个星标收录于 2026年10月8日更新于 2026年10月8日仓库6周前更新

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.

AI 生成的概览

指导使用 Laravel 构建 MCP 服务器,向 AI 客户端暴露工具、提示词和资源。

功能
该技能提供使用 Laravel 开发模型上下文协议(MCP)服务器的参考规则。内容涵盖创建和注册 Web 或本地服务器、定义带输入输出 schema 和响应类型的工具、构建提示词与资源、使用 OAuth 2.1 或 Sanctum 保护服务器,以及通过 MCP Inspector 和单元测试进行测试。它是指令型指南,包含代码示例,不附带可执行脚本。
适用场景
适用于在 Laravel 应用中创建 MCP 服务器,或为 AI 客户端集成添加 MCP 工具、提示词、资源的场景。也适用于保护或测试已有的 Laravel MCP 服务器。
运行要求
需要 Laravel 13.x 与 PHP 8.3+,以及 laravel/mcp 包。不附带脚本,仅为文档。

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

PriorityCategoryImpactPrefix
1ServersCRITICALserver-
2ToolsHIGHtool-
3Prompts & ResourcesMEDIUMprompt-, resource-
4AuthenticationHIGHauth-
5TestingHIGHtest-

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
<?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

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
<?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

来源与署名

来源:asyrafhussin/agent-skills位于skills/laravel-mcp提交1aa0ff7

许可证: MIT

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架