[Server] Simplify server entrypoint with run-based transport lifecycle (#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
This commit is contained in:
parent
e2243bc2d9
commit
2dbd411194
1 changed files with 82 additions and 74 deletions
|
|
@ -35,7 +35,14 @@ final class Server
|
|||
return new Builder();
|
||||
}
|
||||
|
||||
public function connect(TransportInterface $transport): void
|
||||
/**
|
||||
* @template TResult
|
||||
*
|
||||
* @param TransportInterface<TResult> $transport
|
||||
*
|
||||
* @return TResult
|
||||
*/
|
||||
public function run(TransportInterface $transport): mixed
|
||||
{
|
||||
$transport->initialize();
|
||||
|
||||
|
|
@ -56,5 +63,11 @@ final class Server
|
|||
$transport->onSessionEnd(function (Uuid $sessionId) {
|
||||
$this->jsonRpcHandler->destroySession($sessionId);
|
||||
});
|
||||
|
||||
try {
|
||||
return $transport->listen();
|
||||
} finally {
|
||||
$transport->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue