php-transport-implementation

Implementation rules for transport layers in a PHP MCP software-development kit, including how connections start, send messages, close, and report events.

In plain words
What is it for?
Use them when building or reviewing PHP transports, including standard-input/output transport, message handling, closure handling, and error handling.
Why use it?
They keep different transport implementations consistent with the SDK's shared interface and asynchronous programming model.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/dalehurley/php-mcp-sdk/php-transport-implementation
Clone the repo
git clone --depth 1 https://github.com/dalehurley/php-mcp-sdk

Made for: Cursor.

Per session 10 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,882 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00010 $0.02882
Opus 5 $0.00005 $0.01441
Sonnet 5 $0.00002 $0.00576
Haiku 4.5 $0.00001 $0.00288

Measured 2d ago against content hash b7a6a044cdfe, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

php-transport-implementation scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/php-transport-implementation.mdc · 447 lines

How it starts

The opening of the file, as written. The whole thing — 447 lines — stays where its author put it; the contents beside it link to each section on GitHub.

PHP MCP Transport Implementation Guide

Transport Interface

All transports must implement the base Transport interface:

namespace MCP\Shared;

use React\Promise\PromiseInterface;

interface Transport {
    /**
     * Start the transport connection
     */
    public function start(): PromiseInterface;

    /**
     * Send a message through the transport
     */
    public function send(array $message): PromiseInterface;

    /**
     * Close the transport connection
     */
    public function close(): PromiseInterface;

    /**
     * Set handler for incoming messages
     */
    public function setMessageHandler(callable $handler): void;

    /**
     * Set handler for transport closure
     */
    public function setCloseHandler(callable $handler): void;

    /**
     * Set handler for transport errors
     */
    public function setErrorHandler(callable $handler): void;
}

STDIO Transport

Server STDIO Transport

namespace MCP\Server\Transport;

use MCP\Shared\Transport;
use React\EventLoop\LoopInterface;
use React\Stream\ReadableResourceStream;
use React\Stream\WritableResourceStream;
use React\Promise\Promise;
use React\Promise\PromiseInterface;

class StdioServerTransport implements Transport {
    private ReadableResourceStream $stdin;
    private WritableResourceStream $stdout;
    private LoopInterface $loop;
    private ?callable $messageHandler = null;
    private string $buffer = '';

    public function __construct(?LoopInterface $loop = null) {
        $this->loop = $loop ?? Loop::get();
    }

    public function start(): PromiseInterface {
        return new Promise(function ($resolve) {
            // Set up streams
            $this->stdin = new ReadableResourceStream(STDIN, $this->loop);
            $this->stdout = new WritableResourceStream(STDOUT, $this->loop);

            // Handle incoming data
            $this->stdin->on('data', [$this, 'handleData']);
            $this->stdin->on('close', [$this, 'handleClose']);
            $this->stdin->on('error', [$this, 'handleError']);

            $resolve();
        });
    }

    private function handleData(string $chunk): void {
        $this->buffer .= $chunk;

        // Parse messages from buffer
        while (($pos = strpos($this->buffer, "\n")) !== false) {
            $line = substr($this->buffer, 0, $pos);
            $this->buffer = substr($this->buffer, $pos + 1);

            if (trim($line) === '') {
                continue;
            }

            try {
                $message = json_decode($line, true, 512, JSON_THROW_ON_ERROR);
                if ($this->messageHandler) {
                    ($this->messageHandler)($message);
                }
            } catch (\JsonException $e) {
                $this->handleError(new \RuntimeException("Invalid JSON: " . $e->getMessage()));
            }
        }
    }

    public function send(array $message): PromiseInterface {
        return new Promise(function ($resolve, $reject) use ($message) {
            try {
                $json = json_encode($message, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES);
                $this->stdout->write($json . "\n");
                $resolve();
            } catch (\JsonException $e) {
                $reject(new \RuntimeException("Failed to encode message: " . $e->getMessage()));
            }
        });
    }
}

Read the full file on GitHub · 447 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 447 lines · 10 tokens per session scan A b7a6a044cdfe

Subscribe to this mod's changes

php-transport-implementation is a cursor rule published in the GitHub repository dalehurley/php-mcp-sdk (27 stars, last pushed 9mo ago), licensed MIT. It adds 10 tokens to every session and 2,882 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.