PHPackages                             eduardocruz/mcp-php-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. eduardocruz/mcp-php-sdk

ActiveLibrary

eduardocruz/mcp-php-sdk
=======================

PHP implementation of the Model Context Protocol (MCP)

3455↓50%PHPCI passing

Since Jun 21Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/eduardocruz/mcp-php-sdk)[ Packagist](https://packagist.org/packages/eduardocruz/mcp-php-sdk)[ RSS](/packages/eduardocruz-mcp-php-sdk/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

MCP PHP SDK
===========

[](#mcp-php-sdk)

[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](https://opensource.org/licenses/MIT)

A PHP implementation of the [Model Context Protocol (MCP)](https://modelcontextprotocol.io) specification. This SDK enables PHP applications to seamlessly integrate with LLM applications by providing contextual information, tools, and prompts through a standardized interface.

Table of Contents
-----------------

[](#table-of-contents)

- [MCP PHP SDK](#mcp-php-sdk)
    - [Table of Contents](#table-of-contents)
    - [Overview](#overview)
    - [Installation](#installation)
    - [Quick Start](#quick-start)
    - [What is MCP?](#what-is-mcp)
    - [Core Concepts](#core-concepts)
        - [Server](#server)
        - [Resources](#resources)
        - [Tools](#tools)
        - [Prompts](#prompts)
    - [Running Your Server](#running-your-server)
        - [stdio Transport](#stdio-transport)
    - [Documentation](#documentation)
    - [Support](#-support)
    - [Contributing](#contributing)
    - [License](#license)

Overview
--------

[](#overview)

The Model Context Protocol allows applications to provide context for LLMs in a standardized way, separating the concerns of providing context from the actual LLM interaction. This PHP SDK implements the full MCP specification (2025-03-26), making it easy to:

[![MCP PHP SDK Architecture](diagram.png)](diagram.png)

*Diagram created with [GitDiagram](https://gitdiagram.com/eduardocruz/mcp-php-sdk)*

- **Build MCP clients** that can connect to any MCP server
- **Create MCP servers** that expose resources, prompts, and tools
- **Use standard transports** like stdio with proper message framing
- **Handle all MCP protocol messages** and lifecycle events
- **Robust error handling** with standardized JSON-RPC error responses
- **Advanced resource management** with URI templates and dynamic content
- **Complete prompts system** for reusable LLM interaction patterns
- **Production-ready features** including error recovery, logging, and validation

Installation
------------

[](#installation)

```
composer require eduardocruz/mcp-php-sdk
```

> **Note:** Requires PHP 8.1 or higher.

Quick Start
-----------

[](#quick-start)

Let's create a simple MCP server that exposes a calculator tool and a dynamic resource:

```
