pub struct PriceBook {
pub default_units: u64,
pub names: BTreeMap<String, u64>,
pub methods: BTreeMap<String, u64>,
}Expand description
Per-name unit pricing with a fallback.
BTreeMap rather than HashMap so a serialized price book round trips in a
stable order, which makes config diffs readable and tests deterministic.
Fields§
§default_units: u64Charged for a delivered call with no entry in Self::names.
names: BTreeMap<String, u64>Per-name overrides, keyed on the decoded Mcp-Name value.
A value of 0 makes that name free, which is the supported way to expose
a loss-leader tool without carving it out of the billing path.
methods: BTreeMap<String, u64>Per-method overrides, applied when no name matched.
Mainly useful for pricing resources/read differently from tools/call
across the board.
Implementations§
Source§impl PriceBook
impl PriceBook
Sourcepub fn with_name(self, name: impl Into<String>, units: u64) -> Self
pub fn with_name(self, name: impl Into<String>, units: u64) -> Self
Set the price of one name. Chainable, for building books in tests and config.
Sourcepub fn with_method(self, method: &Method, units: u64) -> Self
pub fn with_method(self, method: &Method, units: u64) -> Self
Set the price of one method.
Sourcepub fn units_for(&self, method: &Method, name: Option<&str>) -> u64
pub fn units_for(&self, method: &Method, name: Option<&str>) -> u64
Units owed for a delivered call.
Resolution order is most specific first: the name, then the method, then
the default. name must already be decoded from the Mcp-Name sentinel
form (see crate::name::decode); passing the raw header value here
silently prices every non-ASCII-named tool at the default.