server
Сообществоот php-mcp
Core PHP implementation for the Model Context Protocol (MCP) server
Установка
dockerfile
FROM php:8.3-fpm-alpine
# Install system dependencies
RUN apk --no-cache add \
nginx \
supervisor \
&& docker-php-ext-enable opcache
# Install PHP extensions for MCP
RUN docker-php-ext-install pdo_mysql pdo_sqlite opcache
# Create application directory
WORKDIR /var/www/mcp
# Copy application code
COPY . /var/www/mcp
COPY docker/nginx.conf /etc/nginx/nginx.conf
COPY docker/supervisord.conf /etc/supervisord.conf
COPY docker/php.ini /usr/local/etc/php/conf.d/production.ini
# Install Composer dependencies
RUN composer install --no-dev --optimize-autoloader --no-interaction
# Set permissions
RUN chown -R www-data:www-data /var/www/mcp
# Expose port
EXPOSE 80
# Start supervisor
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
Описание
# PHP MCP Server SDK [](https://packagist.org/packages/php-mcp/server) [](https://packagist.org/packages/php-mcp/server) [](https://github.com/php-mcp/server/actions/workflows/tests.yml) [](LICENSE) **A comprehensive PHP SDK for building [Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) servers. Create production-ready MCP servers in PHP with modern architecture, extensive testing, and flexible transport options.** This SDK enables you to expose your PHP application's functionality as standardized MCP **Tools**, **Resources**, and **Prompts**, allowing AI assistants (like Anthropic's Claude, Cursor IDE, OpenAI's ChatGPT, etc.) to interact with your backend using the MCP standard. ## 🚀 Key Features - **🏗️ Modern Architecture**: Built with PHP 8.1+ features, PSR standards, and modular design - **📡 Multiple Transports**: Supports `stdio`, `http+sse`, and new **streamable HTTP** with resumability - **🎯 Attribute-Based Definition**: Use PHP 8 Attributes (`#[McpTool]`, `#[McpResource]`, etc.) for zero-config element registration - **🔧 Flexible Handlers**: Support for closures, class methods, static methods, and invokable classes - **📝 Smart Schema Generation**: Automatic JSON schema generation from method signatures with optional `#[Schema]` attribute enhancements - **⚡ Session Management**: Advanced session handling with multiple storage backends - **🔄 Event-Driven**: ReactPHP-based for high concurrency and non-blocking operations - **📊 Batch Processing**: Full support for JSON-RPC batch requests - **💾 Smart Caching**: Intelligent caching of discovered elements with manual override precedence - **🧪 Completion Providers**: Built-in support for argument completion in tools and prompts - **🔌 Dependency Injection**: Full PSR-11 container support with auto-wiring - **📋 Comprehensive Testing**: Extensive test suite with integration tests for all transports This package supports the **2025-03-26** version of the Model Context Protocol with backward compatibility. ## 📋 Requirements - **PHP** >= 8.1 - **Composer** - **For HTTP Transport**: An event-driven PHP environment (CLI recommended) - **Extensions**: `json`, `mbstring`, `pcre` (typically enabled by default) ## 📦 Installation ```bash composer require php-mcp/server ``` > **💡 Laravel Users**: Consider using [`php-mcp/laravel`](https://github.com/php-mcp/laravel) for enhanced framework integration, configuration management, and Artisan commands. ## ⚡ Quick Start: Stdio Server with Discovery This example demonstrates the most common usage pattern - a `stdio` server using attribute discovery. **1. Define Your MCP Elements** Create `src/CalculatorElements.php`: ```php <?php namespace App; use PhpMcp\Server\Attributes\McpTool; use PhpMcp\Server\Attributes\Schema; class CalculatorElements { /** * Adds two numbers together. * * @param int $a The first number * @param int $b The second number * @return int The sum of the two numbers */ #[McpTool(name: 'add_numbers')] public function add(int $a, int $b): int { return $a + $b; } /** * Calculates power with validation. */ #[McpTool(name: 'calculate_power')] public function power( #[Schema(type: 'number', minimum: 0, maximum: 1000)] float $base, #[Schema(type: 'integer', minimum: 0, maximum: 10)] int $exponent ): float { return pow($base, $exponent); } } ``` **2. Create the Server Script** Create `mcp-server.php`: ```php #!/usr/bin/env php <?php declare(strict_types=1); require_once __DIR__ . '/vendor/autoload.php'; use PhpMcp\Server\Server; use PhpMcp\Server\Transports\StdioServerTransport; try { // Build server configuration $server = Server::make() ->withServerInfo('PHP Calculator Server', '1.0.0') ->build(); // Discover MCP elements via attributes $server->discover( basePath: __DIR__, scanDirs: ['src'] ); // Start listening via stdio transport $transport = new StdioServerTransport(); $server->listen($transport); } catch (\Throwable $e) { fwrite(STDERR, "[CRITICAL ERROR] " . $e->getMessage() . "\n"); exit(1); } ``` **3. Configure Your MCP Client** Add to your client configuration (e.g., `.cursor/mcp.json`): ```json { "mcpServers": { "php-calculator": { "command": "php", "args": ["/absolute/path/to/your/mcp-server.php"] } } } ``` **4. Test the Server** Your AI assistant can now call: - `add_numbers` - Add
Отзывы (0)
Пока нет отзывов. Будьте первым!
Статистика
Информация
Технологии
Похожие серверы
mcp-chain-of-draft-server
Chain of Draft Server is a powerful AI-driven tool that helps developers make better decisions through systematic, iterative refinement of thoughts and designs. It integrates seamlessly with popular AI agents and provides a structured approach to reasoning, API design, architecture decisions, code reviews, and implementation planning.
mcp-use-ts
mcp-use is the framework for MCP with the best DX - Build AI agents, create MCP servers with UI widgets, and debug with built-in inspector. Includes client SDK, server SDK, React hooks, and powerful dev tools.
mesh
Define and compose secure MCPs in TypeScript. Generate AI workflows and agents with React + Tailwind UI. Deploy anywhere.
rhinomcp
RhinoMCP connects Rhino 3D to AI Agent through the Model Context Protocol (MCP)