Skip to content

Add MCP client Streamable HTTP transport - #227

Merged
taylorotwell merged 39 commits into
mainfrom
add-client-http-transport
May 29, 2026
Merged

Add MCP client Streamable HTTP transport#227
taylorotwell merged 39 commits into
mainfrom
add-client-http-transport

Conversation

@pushpak1300

Copy link
Copy Markdown
Member

Currently the MCP client can only talk to servers over stdio (Client::local()), so there's no way to connect to a remote or hosted MCP server over HTTP.

This adds a Streamable HTTP transport (MCP 2025-11-25):

// before: stdio only
$client = Client::local('npx', ['-y', '@modelcontextprotocol/server-everything']);

// after: connect over HTTP
$client = Client::web('https://mcp.example.com/mcp');
$client->tools();

// with a static bearer token
Client::web('https://mcp.example.com/mcp')->withToken(env('REMOTE_TOKEN'));

It POSTs each JSON-RPC frame via the Http facade (so it's Http::fake() testable), handles both application/json and text/event-stream responses, captures and echoes MCP-Session-Id, sends MCP-Protocol-Version, re-initializes on a 404, and sends a best-effort DELETE on disconnect. withToken() lives on a new WebClient subclass since stdio clients have no auth concept. No OAuth yet, that's a later stage.

Known limitation: SSE responses are read in full before parsing rather than incrementally, so a server that sends a blocking server->client request mid-stream (say a ping it waits on) would hang until the timeout. Narrow for this client since it advertises no sampling/roots/elicitation capabilities, but I'd like to follow up with incremental streaming. Open to feedback on whether that should block this PR.

Stacked on #226.

# Conflicts:
#	src/Client.php
#	src/Client/Contracts/Method.php
#	src/Client/Methods/Initialize.php
#	src/Client/Methods/Ping.php
#	src/Client/Transport/StdioTransport.php
#	tests/Unit/Client/ClientTest.php
@pushpak1300
pushpak1300 requested a review from WendellAdriel May 25, 2026 11:47
@pushpak1300
pushpak1300 marked this pull request as ready for review May 25, 2026 12:04
@pushpak1300
pushpak1300 marked this pull request as draft May 25, 2026 12:04
@pushpak1300

Copy link
Copy Markdown
Member Author

Ready for review. Putting in draft until #226 is merged.

@pushpak1300
pushpak1300 requested a review from TitasGailius May 25, 2026 12:45
Comment thread src/Client/Transport/HttpTransport.php
Comment thread src/Client/Transport/HttpTransport.php Outdated
Comment thread src/Client/Transport/HttpTransport.php Outdated
@pushpak1300
pushpak1300 force-pushed the add-client-http-transport branch from 9aaa38c to dac43d1 Compare May 25, 2026 15:54
@pushpak1300
pushpak1300 requested a review from WendellAdriel May 25, 2026 15:59

@WendellAdriel WendellAdriel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@TitasGailius TitasGailius left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, great job! 🔥

Base automatically changed from add-client-tools-list-call to main May 27, 2026 23:31
An error occurred while trying to automatically change base from add-client-tools-list-call to main May 27, 2026 23:31
…port

# Conflicts:
#	src/Client.php
#	src/Client/Protocol.php
@pushpak1300
pushpak1300 marked this pull request as ready for review May 28, 2026 09:49
@pushpak1300
pushpak1300 requested a review from taylorotwell May 28, 2026 09:54
@taylorotwell
taylorotwell merged commit 57b3713 into main May 29, 2026
22 checks passed
@taylorotwell
taylorotwell deleted the add-client-http-transport branch May 29, 2026 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants