构建 Laravel MCP 服务器的 SDK
概览
该SDK为强大的php-mcp/server库提供了一个Laravel优化的包装器,使你能够将Laravel应用的功能暴露为标准化的MCP、,以及像Anthropic的Claude、Cursor IDE、OpenAI的ChatGPT等AI助手。 - : 深度集成 Laravel 的服务容器、配置、缓存、日志、会话和 Artisan 控制台 - : 利用 Mcp 外观定义 MCP 元素,采用优雅的 Laravel 风格 API- : 使用 PHP 8 属性(#[McpTool]、#[McpResource] 等。
概述(AI 翻译)
** 一个全面的 Laravel SDK 用于构建具备企业级功能和 Laravel 原生集成的模型上下文协议(MCP)服务器。**
该SDK为强大的php-mcp/server库提供了一个Laravel优化的包装器,使你能够将Laravel应用的功能作为标准化的MCP——工具**、资源**、提示和资源模板**,适用于Anthropic的Claude、Cursor IDE、OpenAI的ChatGPT等AI助手。
主要特色
- Laravel-原生集成:深度集成Laravel的服务容器、配置、缓存、日志记录、会话和Artisan控制台
- 流流元素定义:使用优雅的Laravel风格API定义MCP元素,使用
Mcp界面 - 基于属性的发现:使用PHP 8属性(
#[McpTool]、#[McpResource]等)并实现自动发现和缓存 - 高级会话管理:Laravel原生会话处理程序(文件、数据库、缓存、redis),具自动垃圾回收功能
- 灵活的交通选择:
- 集成HTTP:通过支持中间件的Laravel路由服务
- 专用 HTTP 服务器:高性能独立 ReactPHP 服务器
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
Laravel MCP Server SDK
A comprehensive Laravel SDK for building Model Context Protocol (MCP) servers with enterprise-grade features and Laravel-native integrations.
This SDK provides a Laravel-optimized wrapper for the powerful php-mcp/server library, enabling you to expose your Laravel application’s functionality as standardized MCP Tools, Resources, Prompts, and Resource Templates for AI assistants like Anthropic’s Claude, Cursor IDE, OpenAI’s ChatGPT, and others.
Key Features
- Laravel-Native Integration: Deep integration with Laravel’s service container, configuration, caching, logging, sessions, and Artisan console
- Fluent Element Definition: Define MCP elements with an elegant, Laravel-style API using the
Mcpfacade - Attribute-Based Discovery: Use PHP 8 attributes (
#[McpTool],#[McpResource], etc.) with automatic discovery and caching - Advanced Session Management: Laravel-native session handlers (file, database, cache, redis) with automatic garbage collection
- Flexible Transport Options:
- Integrated HTTP: Serve through Laravel routes with middleware support
- Dedicated HTTP Server: High-performance standalone ReactPHP server
- STDIO: Command-line interface for direct client integration
- Streamable Transport: Enhanced HTTP transport with resumability and event sourcing
- Artisan Commands: Commands for serving, discovery, and element management
- Full Test Coverage: Comprehensive test suite ensuring reliability
This package supports the 2025-03-26 version of the Model Context Protocol.
Requirements
- PHP >= 8.1
- Laravel >= 10.0
- Extensions:
json,mbstring,pcre(typically enabled by default)
Installation
Install the package via Composer:
composer require php-mcp/laravel:^3.0 -W
Publish the configuration file:
php artisan vendor:publish --provider="PhpMcp\Laravel\McpServiceProvider" --tag="mcp-config"
For database session storage, publish the migration:
php artisan vendor:publish --provider="PhpMcp\Laravel\McpServiceProvider" --tag="mcp-migrations"
php artisan migrate
Configuration
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →配置
{
"mcpServers": {
"my-laravel-app": {
"command": "php",
"args": [
"/absolute/path/to/your/laravel/project/artisan",
"mcp:serve",
"--transport=stdio"
]
}
}
}