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) -> PriceBook
pub fn with_name(self, name: impl Into<String>, units: u64) -> PriceBook
Set the price of one name. Chainable, for building books in tests and config.
Sourcepub fn with_method(self, method: &Method, units: u64) -> PriceBook
pub fn with_method(self, method: &Method, units: u64) -> PriceBook
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.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for PriceBook
impl<'de> Deserialize<'de> for PriceBook
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<PriceBook, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<PriceBook, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for PriceBook
Source§impl Serialize for PriceBook
impl Serialize for PriceBook
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for PriceBook
Auto Trait Implementations§
impl Freeze for PriceBook
impl RefUnwindSafe for PriceBook
impl Send for PriceBook
impl Sync for PriceBook
impl Unpin for PriceBook
impl UnsafeUnpin for PriceBook
impl UnwindSafe for PriceBook
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more