October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

MCP in PHP: Connect an Agent to a Remote Tool Server in 4 Lines

Use the official MCP PHP SDK and Streamable HTTP to connect an agent to a remote PHP tool server, and learn what the "4 lines" snippet leaves out.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To connect an agent to a remote tool server from PHP, use the official MCP PHP SDK (Composer package mcp/sdk) and the Streamable HTTP transport. The same SDK covers both directions: PHP can expose its own tools as an MCP server, and a PHP application can act as an MCP client that calls another server. The “4 lines” in the title describes a short snippet, not a complete deployment. The official first-server walkthrough also involves autoloading, attributed PHP methods, server metadata, discovery configuration and transport setup, so the sections below spell out what surrounds the short code.

What the SDK covers

The MCP PHP SDK is a collaboration between the PHP Foundation and Symfony. Its project announcement, dated September 5, 2025, names David Soria Parra (Lead Maintainer), Christopher Hertel (Symfony) and Roman Pronskiy (PHP Foundation) among the contributors. The SDK supports implementing both MCP clients and MCP servers.

As an Amazon Associate I earn from qualifying purchases.

Its overview page states the project’s status in these words: “This SDK is experimental until the first major release; see the roadmap for what is planned next.” Check the SDK’s roadmap before relying on it in production, because that status is time-sensitive and may have changed since the page was written.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Requirements before you write code

  • PHP 8.1 or newer, as published in the SDK documentation.
  • Composer, used to install the package with composer require mcp/sdk.
  • symfony/finder, if you use the attribute discovery approach from the official first-server example (composer require symfony/finder).
  • For a remote server: a PHP application that handles PSR-7 requests, or a PHP-capable web host that can run one.

Choose the transport first

The real decision is the transport, because it determines how the client reaches your PHP process. These are different deployment shapes, not interchangeable labels.

Situation SDK transport What to account for
A local MCP host launches the PHP server as a subprocess STDIO The protocol travels over stdin and stdout. Any other output written to stdout corrupts the stream.
The MCP client is remote, or the server lives inside a web application Streamable HTTP Requests enter through your HTTP stack. Authorization, deployment and browser origins become your responsibility.

This article focuses on Streamable HTTP because the title concerns a remote server. STDIO is covered in the pitfalls section below.

How the server describes what it offers

The SDK’s server model separates three kinds of capability:

  • Tools are actions the model can call.
  • Resources are read-only data the client can fetch.
  • Prompts are templates that a person invokes.

In the first-server example, PHP attributes mark a method as a tool or a resource. The SDK derives the tool name and its input schema from the method metadata and the PHP parameter types, so typed parameters are not optional decoration: they become the schema the agent sees. Discovery scans the directories you configure. The walkthrough excludes vendor from that scan, and it notes that scanning is lazy unless you configure it otherwise.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Connect an agent to a remote tool server

  1. Install the package. Run composer require mcp/sdk in the project, and confirm the PHP runtime reports 8.1 or newer with php -v.
  2. Write the server class. Add a public method with a PHP attribute that marks it as a tool, and give every parameter a PHP type. Keep the method’s name and docblock meaningful, because they shape what the agent sees.
  3. Expose the endpoint over Streamable HTTP. The HTTP transport accepts a PSR-7 server request and looks up PSR-17 response and stream factories through discovery. Make sure your application provides a PSR-17 implementation so discovery can succeed. Mount the endpoint on a route your web server forwards to PHP.
  4. Restrict browser access. If a browser-based client calls an endpoint protected by OAuth or a Bearer token, list the trusted origins explicitly. The documentation advises against a wildcard origin.
  5. Point the agent’s MCP client at the endpoint. Configure the client with the endpoint URL, call a tool, and confirm the agent receives the tool’s name and schema.

The short snippet covers the MCP wiring only. Authorization, TLS, routing and hosting are separate tasks, and nothing in a few lines of code supplies them automatically.

Verify the implementation

The official examples show three checks: start an example server, open it with the MCP Inspector (published on npm as @modelcontextprotocol/inspector), and run the client examples for both STDIO and HTTP.

PHP’s built-in development server, started with php -S, handles one request at a time. The examples warn that the documented sampling round-trip, where the server asks the client to run a model call and waits for the answer, will block unless you run worker processes. Test sampling behind a real PHP-FPM or similar worker setup, not on the built-in server alone.

STDIO pitfalls

With STDIO, stdout carries the protocol itself. A stray echo, var_dump or framework debug line on stdout breaks the message stream. Send diagnostic output to stderr or to a logger instead.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Assumptions behind the short snippet

  • PHP 8.1 or newer, with Composer available.
  • Autoloading is configured so the server classes load without manual require calls.
  • Server metadata such as name and version is set, as in the official walkthrough.
  • Discovery directories are configured and vendor is excluded.
  • A PSR-7 request flow and PSR-17 factories are available for Streamable HTTP.
  • Authorization and trusted origins are configured for any protected or browser-facing endpoint.

For the exact code of each step, follow the official quick start and first-server examples in the SDK documentation, which ship as complete PHP files that can sit alongside vendor/.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.