Skip to content

Php SDK

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

Install

$git clone https://github.com/modelcontextprotocol/php-sdk

Install command taken from the project's README or registry entry. Always review code before running it.

MCP PHP SDK

The official PHP SDK for the Model Context Protocol (MCP). It provides a framework-agnostic API for implementing MCP servers and clients in PHP — tools, resources, prompts, STDIO and HTTP transports, sessions, authorization, and both protocol eras (the initialize handshake and the stateless 2026-07-28 revision).

This project represents a collaboration between the PHP Foundation and the Symfony project. It adopts development practices and standards from the Symfony project, including Coding Standards and the Backward Compatibility Promise.

Until the first major release, this SDK is considered experimental, please see the roadmap for planned next steps and features.

Protocol Conformance

Measured weekly against the MCP Conformance Test Framework, as passing checks out of total. The 2026-07-28 scores run against the framework's alpha releases, so they move as upstream publishes new scenarios.

Revision Server Client
2026-07-28 Server conformance 2026-07-28 Client conformance 2026-07-28
2025-11-25 Server conformance 2025-11-25 Client conformance 2025-11-25

Installation

composer require mcp/sdk

Build a server

A server is a plain PHP class plus three lines of wiring:

use Mcp\Capability\Attribute\McpResource;
use Mcp\Capability\Attribute\McpTool;
use Mcp\Server;
use Mcp\Server\Transport\StdioTransport;

class Calculator
{
    /**
     * Adds two numbers.
     */
    #[McpTool]
    public function add(int $a, int $b): int
    {
        return $a + $b;
    }

    #[McpResource(uri: 'config://calculator/settings')]
    public function settings(): array
    {
        return ['precision' => 2];
    }
}

exit(Server::builder()
    ->setServerInfo('Calculator', '1.0.0')
    ->setDiscovery(__DIR__, ['.'], excludeDirs: ['vendor'])
    ->build()
    ->run(new StdioTransport()));

The setDiscovery() call needs symfony/finder:

composer require symfony/finder

The walkthrough in First server explains each piece, and Try it with the Inspector shows it running.

Build a client

Similar plugs

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

Java 面试 & 后端通用面试指南,覆盖计算机基础、数据库、分布式、高并发、系统设计与 AI 应用开发

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype…

Explore related