PHPackages                             elliottlawson/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. elliottlawson/mcp-php-sdk

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

elliottlawson/mcp-php-sdk
=========================

PHP SDK for Model Context Protocol

v0.2.1(1y ago)0110[1 issues](https://github.com/elliottlawson/mcp-php-sdk/issues)MITPHPPHP ^8.1CI passing

Since Mar 21Pushed 1y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (8)Versions (4)Used By (0)

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

[](#mcp-php-sdk)

A PHP SDK for the Model Context Protocol (MCP), allowing seamless integration between applications and Large Language Models (LLMs).

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Composer

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

[](#installation)

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

Overview
--------

[](#overview)

The Model Context Protocol (MCP) is an open standard for connecting large language models (LLMs) to applications, APIs, and external data sources. This PHP SDK provides a structured implementation for PHP applications to integrate with MCP.

Main Components
---------------

[](#main-components)

### Protocol Layer

[](#protocol-layer)

The Protocol layer handles the core MCP message format and communication patterns:

- `McpMessage`: Represents JSON-RPC 2.0 messages used in MCP
- `Protocol`: Handles message framing, request-response linking, and pattern registration

### Transport Layer

[](#transport-layer)

The Transport layer defines how messages are sent and received:

- `TransportInterface`: Defines the contract for all transport implementations
- `StdioTransport`: Implementation for command-line applications using standard input/output
- `SseTransport`: Implementation for web applications using Server-Sent Events (SSE)

### Resources

[](#resources)

Resources are data sources that LLMs can access:

- `Resource`: Represents a data source
- `ResourceTemplate`: Handles URI templates and pattern matching
- `ResourceContent`: Represents the content of a resource

### Tools

[](#tools)

Tools enable LLMs to execute code and produce side effects:

- `Tool`: Represents a tool definition
- `ToolResult`: Encapsulates the result of a tool execution

### Prompts

[](#prompts)

Prompts define reusable templates for LLM interactions:

- `Prompt`: Represents a prompt definition
- `PromptArgument`: Defines arguments for prompts
- `PromptResult`: Represents the result of a prompt execution

### Server

[](#server)

The server components tie everything together:

- `McpServer`: The main server class that manages connections, resources, tools, and prompts
- `ServerCapabilities`: Defines the capabilities of the server

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

[](#quick-start)

### Basic CLI Server

[](#basic-cli-server)

```
