[Server] Throw the SDK's own RuntimeException from FileSessionStore (#404)

The constructor guarded its unwritable-directory case with the global
`\RuntimeException`, the only throw in `src/` still outside
`Mcp\Exception\ExceptionInterface`. A consumer wrapping server setup in a
`catch (ExceptionInterface)` missed it and got an unhandled SPL exception on
a misconfigured session directory instead.

`Mcp\Exception\RuntimeException` extends `\RuntimeException`, so this is
additive: existing `catch (\RuntimeException)` blocks keep working.

The constructor had no test coverage at all, so this adds one for the throw
plus the directory-creation and write/read paths around it.
This commit is contained in:
Christopher Hertel 2026-08-14 21:29:26 +02:00 • committed by GitHub
commit a987a3a248
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,6 +11,7 @@
namespace Mcp\Server\Session;
use Mcp\Exception\RuntimeException;
use Mcp\Server\NativeClock;
use Psr\Clock\ClockInterface;
use Symfony\Component\Uid\Uuid;
@ -31,7 +32,7 @@ class FileSessionStore implements SessionStoreInterface
}
if (!is_dir($this->directory) || !is_writable($this->directory)) {
throw new \RuntimeException(\sprintf('Session directory "%s" is not writable.', $this->directory));
throw new RuntimeException(\sprintf('Session directory "%s" is not writable.', $this->directory));
}
}