Recommended Free Tools
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.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Requirements 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.
#1 Best Overall
| 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:
Rank #2
- 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.
Connect an agent to a remote tool server
- Install the package. Run
composer require mcp/sdkin the project, and confirm the PHP runtime reports 8.1 or newer withphp -v. - 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.
- 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.
- 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.
- 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.
Rank #4
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.
Assumptions behind the short snippet
- PHP 8.1 or newer, with Composer available.
- Autoloading is configured so the server classes load without manual
requirecalls. - Server metadata such as name and version is set, as in the official walkthrough.
- Discovery directories are configured and
vendoris 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/.
Quick Recap
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.




