Skip to content

Add suspend() and resume() for MCP clients#2

Open
thekid wants to merge 1 commit intomainfrom
feature/suspend
Open

Add suspend() and resume() for MCP clients#2
thekid wants to merge 1 commit intomainfrom
feature/suspend

Conversation

@thekid
Copy link
Member

@thekid thekid commented Aug 23, 2025

This allows to resume an MCP HTTP server session when re-connecting. When resuming, the protocol initialization can be omitted, thus saving multiple roundtrips.

use use io\modelcontextprotocol\McpClient;

$suspens= 'suspense.json';
if (file_exists($suspense)) {
  $client= McpClient::resume(json_decode(file_get_contents($suspense), true));
} else {
  $client= new McpClient($argv[1]);
}

// [...call tools etcetera...]

file_put_contents($suspense, json_encode($client->suspend()));


/** Suspends this MCP client for later continuation */
public function suspend(): array {
return [
Copy link
Member Author

Choose a reason for hiding this comment

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

This needs a check if the transport is resumeable

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.

1 participant