PHP MCP Server

by he426100

21 247 downloads Not rated yet MIT
GitHub

About

基于 PHP 实现的 MCP (Model Control Protocol) 服务器框架,通过注解优雅地定义 MCP 服务,支持 Tool、Prompt、Resource 三种处理器,支持Stdio、Sse 两种 transport。

Details

License
MIT

Explore

- Annotation-based definition of MCP services
- Support for Tool, Prompt, and Resource handlers
- Stdio and SSE transport modes
- Compatible with Swow (>1.5) and Swoole (>5.1) environments
- Integrated logging system
- Docker support for containerized deployment

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name PHP MCP Server
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Clone the repository and install dependencies via Composer. Run the test server with php bin/console mcp:test-server and optionally pass --transport (stdio or sse) and --port (default 8000 for SSE). The server can also be executed without local installation via CPX (Composer Package Executor) using cpx he426100/php-mcp-server mcp:test-server.

description

string

parameters

array

ResourceContents

资源内容对象

null

空值

用于定义工具类处理器:

use Mcp\Annotation\Tool;

class MyService {
#[Tool(
name: 'calculate-sum',
description: '计算两个数的和',
parameters: [
'num1' => [
'type' => 'number',
'description' => '第一个数字',
'required' => true
],
'num2' => [
'type' => 'number',
'description' => '第二个数字',
'required' => true
]
]
)]
public function sum(int $num1, int $num2): int
{
return $num1 + $num2;
}
}

| 参数 | 类型 | 说明 | 必填 |
|------|------|------|------|
| name | string | 工具名称 | 是 |
| description | string | 工具描述 | 是 |
| parameters | array | 参数定义 | 否 |

| 返回类型 | 说明 | 转换结果 |
|---------|------|---------|
| TextContent/ImageContent/EmbeddedResource | 直接返回内容对象 | 原样保留 |
| TextContent/ImageContent/EmbeddedResource 数组 | 内容对象数组 | 原样保留 |
| ResourceContents | 资源内容对象 | 转换为 EmbeddedResource |
| 字符串或标量类型 | 如 string、int、float、bool | 转换为 TextContent |
| null | 空值 | 转换为空字符串的 TextContent |
| 数组或对象 | 复杂数据结构 | 转换为 JSON 格式的 TextContent |

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "php mcp server": {
            "php-mcp-server": {
                "command": "docker",
                "args": [
                    "build",
                    "-t",
                    "php-mcp-server",
                    "."
                ]
            }
        }
    }
}

McpServers

{
    "php-mcp-server": {
        "command": "docker",
        "args": [
            "build",
            "-t",
            "php-mcp-server",
            "."
        ]
    }
}

English Version

这是一个基于 PHP 实现的 MCP (Model Control Protocol) 服务器框架,支持通过注解优雅地定义 MCP 服务。

项目概述

本项目提供了一个完整的 MCP 服务器实现,特色功能:

- 基于注解的 MCP 服务定义
- 支持 Tool、Prompt、Resource 三种处理器
- 支持 Stdio、Sse 两种传输方式
- 支持 Swow 和 Swoole 两种环境
- 完整的日志系统
- Docker 支持

系统要求

- PHP >= 8.1
- Composer
- Swow 扩展 > 1.5 或 Swoole > 5.1
- Docker (可选)

快速开始

安装

```bash

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.

Videos about PHP MCP Server

Relevant YouTube tutorials, setups, and demos