
螺旋框架的MCP服务器实现
概览
Spiral 框架的强大且灵活的实现。该软件包提供完整的 MCP 服务器解决方案,具备自动工具发现、基于属性的配置以及与 Spular 依赖注入容器的无缝集成。 ✨ - 自动发现并注册使用 PHP 属性🔧的 MCP 工具 - 支持 HTTP、流式 HTTP 和 STDIO 传输 🎯 - 用简单的 PHP 属性🛡️定义工具行为 - 使用螺旋/json 模式生成器⚡自动生成 JSON 模式 - 可扩展的请求/响应处理🔌中间件系统 - 与 Spiral Framework 的 IoC 容器📊一流集成 - 内置会话处理和可配置的 TTL 🚀 - 专为高性能生产环境设计 - PHP 8.3 或更高版本 - Spiral Framework 3.15+ - Composer 将引导加载程序添加到你的 Spiral 应用中: :欲了解更多关于DTO模式定义的信息,请访问spiral/json-schema-generator。
概述(AI 翻译)
一个强大且灵活的 * 模型上下文协议(MCP)服务器** 实现,适用于螺旋框架。本包 提供完整的MCP服务器解决方案,具备自动工具发现、基于属性的配置和无缝连接 与Spiral的依赖注入容器集成。
目录
- 特色
- 要求
- 安装
- 快速入门
- 配置
- 创建工具
- 工具属性
- 中间件
- 贡献
- 许可证
特色
✨ 自动工具发现 - 使用 PHP 属性自动发现并注册 MCP 工具 🔧 多重传输选项 - 支持 HTTP、流式 HTTP 和 STDIO 传输 🎯 基于属性的配置 - 用简单的PHP属性定义工具行为 🛡️ Schema Validation - 使用螺旋/json-schema-generator 自动生成 JSON schema ⚡ 中间件支持——可扩展的请求/响应处理中间件系统 🔌 螺旋集成 - 与螺旋框架的 IoC 容器的一流集成 📊 会话管理 - 内置会话处理,可配置TTL 🚀 生产准备——专为高性能生产环境设计
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
Spiral MCP Server
A powerful and flexible Model Context Protocol (MCP) Server implementation for the Spiral Framework. This package provides a complete MCP server solution with automatic tool discovery, attribute-based configuration, and seamless integration with Spiral’s dependency injection container.
Table of Contents
- Features
- Requirements
- Installation
- Quick Start
- Configuration
- Creating Tools
- Tool Attributes
- Middleware
- Contributing
- License
Features
✨ Automatic Tool Discovery - Automatically discovers and registers MCP tools using PHP attributes
🔧 Multiple Transport Options - Supports HTTP, streaming HTTP, and STDIO transports
🎯 Attribute-Based Configuration - Define tool behavior with simple PHP attributes
🛡️ Schema Validation - Automatic JSON schema generation using spiral/json-schema-generator
⚡ Middleware Support - Extensible middleware system for request/response processing
🔌 Spiral Integration - First-class integration with Spiral Framework’s IoC container
📊 Session Management - Built-in session handling with configurable TTL
🚀 Production Ready - Designed for high-performance production environments
Requirements
- PHP 8.3 or higher
- Spiral Framework 3.15+
- Composer
Installation
Install the package via Composer:
composer require spiral/mcp-server
Add the bootloader to your Spiral application:
// app/src/Application/Kernel.php
use Spiral\McpServer\Bootloader\McpServerBootloader;
protected const LOAD = [
// ... other bootloaders
McpServerBootloader::class,
];
Quick Start
1. Create Your First Tool
Create a simple calculator tool:
<?php
namespace App\Tool;
use Spiral\McpServer\Attribute\Tool;
use Spiral\McpServer\Attribute\IsReadonly;
#[Tool(
name: 'calculator_add',
description: 'Adds two numbers together'
)]
#[IsReadonly]
class CalculatorTool
{
public function __invoke(CalculatorRequest $request): array
{
return [
'result' => $request->a + $request->b,
'operation' => 'addition'
];
}
}
2. Define the Request Schema
<?php
namespace App\Tool;
use Spiral\JsonSchemaGenerator\Attribute\Field;
final readonly class CalculatorRequest
{
public function __construct(
#[Field(
title: 'First Number',
description: 'The first number to add'
)]
public float $a,
#[Field(
title: 'Second Number',
description: 'The second number to add'
)]
public float $b,
) {}
}
Note: For more information about DTO schema definition visit spiral/json-schema-generator.
3. Set Environment Variables
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →