PHPackages                             james2037/mcp-php-server - 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. [Framework](/categories/framework)
4. /
5. james2037/mcp-php-server

ActiveLibrary[Framework](/categories/framework)

james2037/mcp-php-server
========================

Model Context Protocol server framework in PHP

382[1 PRs](https://github.com/james2037/mcp-php-server/pulls)PHPCI passing

Since Jun 5Pushed 11mo ago1 watchersCompare

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

READMEChangelogDependenciesVersions (4)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/9cd36a0593ef7ade1e45d3fae62a5174504611fcc13f2d97aa7bd773e29450f1/68747470733a2f2f706f7365722e707567782e6f72672f6a616d6573323033372f6d63702d7068702d7365727665722f762f737461626c65)](https://packagist.org/packages/james2037/mcp-php-server)

PHP Model Context Protocol Server SDK
=====================================

[](#php-model-context-protocol-server-sdk)

This project provides a PHP implementation of the Model Context Protocol (MCP), enabling you to build servers that can provide context (data and tools) to Large Language Models (LLMs).

MCP is an open protocol that standardizes how applications interact with LLMs. For more information about MCP, please visit the official website:

Features
--------

[](#features)

This PHP MCP SDK provides the following core features:

- **Server Implementation**: Easily create MCP compliant servers.
- **Capabilities**:
    - `Tools`: Expose functionalities for LLMs to execute.
    - `Resources`: Provide data and content to LLMs.
- **Transports**:
    - `StdioTransport`: For command-line based MCP servers.
    - `HttpTransport`: For exposing MCP servers over HTTP (compatible with standard PHP web server environments like Apache/Nginx with PHP-FPM/mod\_php).
- **JSON-RPC Handling**: Manages request parsing and response formatting.
- **Attribute-Based Configuration**: Use PHP attributes to define tools, resources, and their parameters.

Getting Started
---------------

[](#getting-started)

This guide will walk you through creating simple MCP servers using this SDK.

### Prerequisites

[](#prerequisites)

- PHP 8.1 or higher
- Composer for dependency management

### Installation

[](#installation)

Install the dependencies using Composer:

```
composer require james2037/mcp-php-server
```

Creating an STDIO Server
------------------------

[](#creating-an-stdio-server)

An STDIO server communicates over standard input and standard output. This is commonly used for local tools or development purposes.

The following example demonstrates a server with:

1. An `EchoTool`: Takes a string and returns it.
2. A `GreetingResource`: Provides a static greeting message.

The full code for this example can be found in `examples/stdio_server.php`.

**Key parts of `examples/stdio_server.php`:**

```
