Get the FREE Ultimate OpenClaw Setup Guide →

php-sdk

The official PHP SDK for Model Context Protocol servers and clients. Maintained in collaboration with The PHP Foundation.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio modelcontextprotocol-php-sdk php /absolute/path/to/server.php

How to use

The PHP MCP SDK provides a framework-agnostic way to implement MCP servers and clients using PHP attributes and Symfony-style design patterns. It supports defining MCP capabilities as tools and resources using attributes, discovering them automatically, and exposing them over multiple transports such as STDIO and HTTP. The server builder makes it straightforward to register tools, resources, and session handling, while the included transports enable integration with CLI tools and web applications. Developers can also rely on the provided discovery and caching options to optimize startup and runtime performance.

With the SDK, you can: define MCP elements using attributes like McpTool and McpResource, build an MCP server via Server::builder(), and run it with a chosen transport (STDIO or HTTP). You can also register capabilities manually, manage sessions with various stores (in-memory, files, PSR-16 caches), and customize discovery behavior. The Quick Start demonstrates creating a simple class with tools and a resource, wiring a server script, and testing with an MCP Inspector. This makes it practical to prototype rapid MCP-enabled services in PHP and gradually adopt more framework-specific integrations as your project evolves.

How to install

Prerequisites:

  • PHP 8.0 or higher
  • Composer (dependency manager for PHP)
  1. Install the MCP PHP SDK via Composer:
composer require mcp/sdk
  1. Optionally install framework integrations or tooling you plan to use (examples):
  • Symfony components or bundles if you plan to integrate within Symfony projects
  • Any PSR-7/PSR-15 HTTP libraries if you plan to use the HTTP transport
  1. Create your MCP server script and define your elements, then run the server using PHP. See the Quick Start in the README for a minimal example. You may also add tests and CI as you refine the server behavior.

Additional notes

Tips and common considerations:

  • The SDK is experimental and subject to API changes; pin versions and monitor the changelog or issues for stabilization progress.
  • Discovery can be cached to improve startup time; consider enabling a PSR-16 cache for discovery results.
  • If using the HTTP transport, ensure your PSR-7 compatible request/response factories are properly configured.
  • For session management, you can switch between in-memory, file-based, or PSR-16 adapters. This is helpful for running multiple server instances or scaling out.
  • When testing with the MCP Inspector, you can exercise tools and resources defined by your server to validate behavior before going to production.

Related MCP Servers

Sponsor this space

Reach thousands of developers