server

server

174

PHP MCP Server provides a server-side implementation of the Model Context Protocol for PHP applications, enabling interaction with AI assistants. It simplifies the creation of MCP servers using PHP Attributes, metadata inference, and supports both stdio and http+sse transports.

PHP MCP Server

PHP MCP Server provides a robust server-side implementation of the Model Context Protocol (MCP) for PHP applications. This package allows AI assistants to interact with PHP backends by exposing parts of the application as MCP Tools, Resources, and Prompts. Features include:

  • Attribute-Based Definition: Using PHP Attributes to define MCP elements.
  • Manual Registration: Register elements programmatically.
  • Explicit Discovery: Scan for attributes on demand.
  • Metadata Inference: Generate MCP schemas from PHP type hints.
  • Selective Caching: Cache discovered element definitions.
  • Flexible Transports: Supports stdio and http+sse.
  • PSR Compliance: Integrates with PSR standards for Logging, Container, and SimpleCache.

Installation

The package requires PHP >= 8.1 and can be installed via Composer.

Architecture

The server follows a decoupled architecture consisting of various components like ServerBuilder, Configuration, Server, Registry, Processor, etc.

Running the Server

The server is transport-agnostic and can be used with stdio or http+sse transports.

Defining MCP Elements

Use attributes or manual registration to expose functionality as MCP elements. Manual registration takes precedence over discovered elements.