feat(client): accept a cached era verdict on ConnectOptions.prior (#2511)

This commit is contained in:
Felix Weinberger 2026-07-17 17:25:02 +01:00 • committed by GitHub
commit f60dff0674
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,8 +7,8 @@
* 2. The result is `JSON.stringify`-ed (the "persist" step — in a real gateway
* you would write this to Redis, a config map, or a process-local cache).
* 3. Three fresh worker clients connect with
* `connect(transport, { prior: JSON.parse(persisted) })`: each connect()
* sends nothing on the wire, and `callTool` works immediately.
* `connect(transport, { prior: { kind: 'modern', discover: JSON.parse(persisted) } })`:
* each connect() sends nothing on the wire, and `callTool` works immediately.
* 4. The server's `request_count` tool proves it: after three worker connects
* the count is unchanged (no extra discover/initialize from the workers).
*
@ -19,7 +19,7 @@
* `DiscoverResult` across principals.
*/
import { check, parseExampleArgs } from '@mcp-examples/shared';
import type { DiscoverResult } from '@modelcontextprotocol/client';
import type { DiscoverResult, PriorDiscovery } from '@modelcontextprotocol/client';
import { Client, StreamableHTTPClientTransport } from '@modelcontextprotocol/client';
async function requestCount(client: Client): Promise<number> {
@ -56,7 +56,7 @@ await bootstrap.close();
// round trips each. Every worker presents the same authorization context
// as the bootstrap (unauthenticated here), so reuse is safe.
// ---------------------------------------------------------------------
const prior: DiscoverResult = JSON.parse(persisted) as DiscoverResult;
const prior: PriorDiscovery = { kind: 'modern', discover: JSON.parse(persisted) as DiscoverResult };
const workers = await Promise.all(
['worker-a', 'worker-b', 'worker-c'].map(async name => {
const worker = new Client({ name, version: '1.0.0' });