461
462
public readonly cacheState = derived(reader => {
463
>
const currentNonce = () => this._fullDefinitions.read(reader)?.server?.cacheNonce;
mcpServer.ts
464
>
const stateWhenServingFromCache = () => {
465
>
if (this._tools.hasStaticDefinition(reader)) {
466
>
return McpServerCacheState.Cached;
467
>
}
468
>
469
>
if (!this._tools.fromCache) {
470
>
return McpServerCacheState.Unknown;
471
>
}
472
>
473
>
return currentNonce() === this._tools.fromCache.nonce ? McpServerCacheState.Cached : McpServerCacheState.Outdated;
474
>
};
475
>
476
>
const fromServer = this._tools.fromServerPromise.read(reader);
477
>
const connectionState = this.connectionState.read(reader);
478
>
const isIdle = McpConnectionState.canBeStarted(connectionState.state) || !fromServer;
479
>
if (isIdle) {
480
>
return stateWhenServingFromCache();
481
>
}
482
>
483
>
const fromServerResult = fromServer?.promiseResult.read(reader);
484
>
if (!fromServerResult) {
485
>
return this._tools.fromCache ? McpServerCacheState.RefreshingFromCached : McpServerCacheState.RefreshingFromUnknown;
486
>
}
487
>
488
>
if (fromServerResult.error) {
489
>
return stateWhenServingFromCache();
490
>
}
491
>
492
>
return fromServerResult.data?.nonce === currentNonce() ? McpServerCacheState.Live : McpServerCacheState.Outdated;
493
});
494