pub struct SchemaManager<S: SchemaStore> { /* private fields */ }Expand description
Top-level handle for one upstream MCP server’s schema view.
Generic over the store backend; downstream typically uses
SchemaManager<MemorySchemaStore> for the OSS proxy and swaps in a
database-backed store for cloud deployments.
Implementations§
Source§impl<S: SchemaStore> SchemaManager<S>
impl<S: SchemaStore> SchemaManager<S>
pub fn new(upstream_id: impl Into<String>, store: S) -> Self
Sourcepub async fn wait_idle(&self)
pub async fn wait_idle(&self)
Wait until every task spawned via [spawn_ingest] has finished.
Used by shutdown/test code so the bus sees every
SchemaVersionCreated event before it drains.
pub fn upstream_id(&self) -> &str
Sourcepub async fn warm(&self, method: &str)
pub async fn warm(&self, method: &str)
Seed the in-memory state for method from the store.
Callers normally don’t need to invoke this directly — ingest
lazy-warms on the first call for a method. Exposed for explicit
startup warm-up when desired.
Sourcepub async fn preload(&self, version: SchemaVersion)
pub async fn preload(&self, version: SchemaVersion)
Bootstrap in-memory state from a pre-existing SchemaVersion
(typically loaded from an external persistent store at startup).
Seeds current_hash + next_version_number so subsequent
ingest calls with matching content return None (no phantom
new version) and non-matching content increments from
version.version + 1. Also writes the version into the
manager’s in-process store so latest / list_tools /
get_tool / etc. see it without needing the first live request.
Idempotent per method: if current_hash is already set (either
from a prior preload or a completed ingest), this is a no-op.
Sourcepub async fn ingest(
&self,
method: &str,
request_body: &Value,
response_body: &Value,
) -> Option<SchemaVersion>
pub async fn ingest( &self, method: &str, request_body: &Value, response_body: &Value, ) -> Option<SchemaVersion>
Feed a schema-method response through the manager.
Returns Some(version) when a new SchemaVersion was created
(pagination complete AND content differs from the current
version). Returns None when:
- The response is not a complete page (still buffering).
- The content hash matches the current version.
- The response has no
resultfield.
Sourcepub fn spawn_ingest<F>(
self: &Arc<Self>,
method: String,
request_body: Value,
response_body: Value,
on_version: F,
)
pub fn spawn_ingest<F>( self: &Arc<Self>, method: String, request_body: Value, response_body: Value, on_version: F, )
Spawn an async ingest task so the caller’s hot path does not pay for merge/hash/store work.
Returns immediately after spawning. Use [wait_idle] to block
until every spawned task (including this one) has completed.
The caller provides a sink closure that receives the new
SchemaVersion when one is produced (for emitting events).
The closure runs on the spawned task, not on the caller.
Sourcepub async fn latest(&self, method: &str) -> Option<SchemaVersion>
pub async fn latest(&self, method: &str) -> Option<SchemaVersion>
Latest stored version for method, or None if nothing has
been ingested yet.
pub async fn list_tools(&self) -> Vec<Value>
pub async fn list_resources(&self) -> Vec<Value>
pub async fn list_resource_templates(&self) -> Vec<Value>
pub async fn list_prompts(&self) -> Vec<Value>
pub async fn get_tool(&self, name: &str) -> Option<Value>
pub async fn get_resource(&self, uri: &str) -> Option<Value>
pub async fn get_prompt(&self, name: &str) -> Option<Value>
Sourcepub fn mark_stale(&self, method: &str)
pub fn mark_stale(&self, method: &str)
Mark the current version for method as stale. Idempotent.
Sync on purpose — the stale flag is used by the hot request
path (observing notifications/tools/list_changed) where a
round-trip to async code would be overkill.