Skip to content

Conversation

@CodeWithKyrian
Copy link
Contributor

This PR replaces the old connect() + listen() flow with a single run() method that wires, executes, and tears down transports for every example, doc, and transport implementation.

Motivation and Context

  • Simplifies server usage so developers no longer have to remember to call both connect() and listen() and worry about cleanup.
  • Keeps lifecycle responsibilities inside the SDK: transports expose the same interface (initialize, onMessage, listen, close) while the server coordinates their use and always closes them once listen() finishes...whether that’s a blocking STDIO loop, a one-shot HTTP request, or blocking asynchronous loop.

What’s Changed

  • Introduced Server::run() which initializes the transport, hooks up callbacks, runs listen(), closes the transport, and returns whatever the transport returns.
  • Updated STDIO transport to emit an integer status (0 for success, 1 when STDIN reading fails) and cleared session state during close.
  • Refreshed all docs and examples to call run() and, for STDIO scripts, exit with the returned status.
  • Extended the HTTP samples to rely on the response produced by run() instead of invoking listen() manually.

Breaking Changes

  • Server::connect() has been removed. All consumers must call Server::run($transport) and drop their manual $transport->listen()/$transport->close() calls (if any).

}

public function connect(TransportInterface $transport): void
public function run(TransportInterface $transport): mixed
Copy link
Member

Choose a reason for hiding this comment

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

which scenarios do we have instead of int?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check the StreamableHttpTransport and the http examples. For that, It returns a PSR-7 response instead

@CodeWithKyrian CodeWithKyrian force-pushed the feat/server-run-transport-lifecycle branch from 65cb638 to c0629f3 Compare October 8, 2025 20:45
@CodeWithKyrian CodeWithKyrian merged commit 2dbd411 into modelcontextprotocol:main Oct 10, 2025
10 checks passed
@CodeWithKyrian CodeWithKyrian deleted the feat/server-run-transport-lifecycle branch October 10, 2025 17:52
chr-hertel added a commit to symfony/ai that referenced this pull request Oct 10, 2025
This PR was merged into the main branch.

Discussion
----------

[MCP Bundle] Adopt new interface of MCP server

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| Docs?         | no
| Issues        |
| License       | MIT

Follows modelcontextprotocol/php-sdk#103

Commits
-------

6099b4d Adopt new interface of MCP server
bigdevlarry pushed a commit to bigdevlarry/php-sdk that referenced this pull request Nov 10, 2025
modelcontextprotocol#103)

* feat: replace connect/listen flow with run lifecycle

* feat(transport): add phpstan generics for typed transport returns

* refactor: standardize variable naming for MCP server instances in transport handling

* test: remove unnecessary phpstan-ignore annotation in DocBlockTestFixture
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.

2 participants