Skip to main content

Ops

Struct Ops 

Source
pub struct Ops<M> { /* private fields */ }
Expand description

The operations a module registers.

Implementations§

Source§

impl<M: Send + Sync + 'static> Ops<M>

Source

pub fn tool<A, R, E, F, Fut>( &mut self, name: &'static str, feature: Feature, handler: F, ) -> &mut Self
where A: DeserializeOwned + JsonSchema + 'static, R: Serialize + JsonSchema + 'static, E: Display, F: Fn(Arc<M>, Ctx, A) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<R, E>> + Send + 'static,

Registers an operation served as the MCP tool name, callable by spaces entitled to feature.

§Panics

When name is registered twice or A is not a struct: both are mistakes in the module, found by its first test.

Source

pub fn task<A, R, E, F, Fut>( &mut self, name: &'static str, feature: Feature, handler: F, ) -> &mut Self
where A: DeserializeOwned + JsonSchema + 'static, R: Serialize + JsonSchema + 'static, E: Display, F: Fn(Arc<M>, Ctx, A) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<R, E>> + Send + 'static,

Registers a long operation, over about a second, like Self::tool. A caller that supports tasks gets a task at once and polls it for the result; any other caller waits for the result as for a tool.

Source

pub fn app( &mut self, tool: &str, uri: &'static str, html: &'static str, ) -> &mut Self

Shows tool’s results as an MCP App in hosts that render them (Claude, ChatGPT, VS Code): the HTML page html, served as the resource uri. The page receives the tool’s structured result from the host. Tools may share one page.

§Panics

When tool is not registered yet, uri is not a ui:// URI, or uri already serves a different page.

Source

pub fn resource<A, E, F, Fut>( &mut self, uri: &'static str, name: &'static str, feature: Feature, handler: F, ) -> &mut Self
where A: DeserializeOwned + JsonSchema + 'static, E: Display, F: Fn(Arc<M>, Ctx, A) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Body, E>> + Send + 'static,

Registers a resource at uri, readable by spaces entitled to feature. A URI with {name} variables is a template: the handler receives the variables, percent-decoded, as A, and A’s doc comment describes the template. A plain URI takes A = () and is listed.

§Panics

When uri is registered twice or is not a valid template.

Source

pub fn prompt<A, E, F, Fut>( &mut self, name: &'static str, feature: Feature, handler: F, ) -> &mut Self
where A: DeserializeOwned + JsonSchema + 'static, E: Display, F: Fn(Arc<M>, Ctx, A) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Vec<Message>, E>> + Send + 'static,

Registers a prompt name, available to spaces entitled to feature. Its arguments are the fields of A, which MCP passes as strings, and A’s doc comment describes it.

§Panics

When name is registered twice or A is not a struct.

Source

pub fn complete<E, F, Fut>( &mut self, target: &'static str, argument: &'static str, handler: F, ) -> &mut Self
where E: Display, F: Fn(Arc<M>, Ctx, Completing) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Vec<String>, E>> + Send + 'static,

Completes argument of target, a prompt’s name or a resource template’s URI: the handler gets what the user typed so far and returns suggestions. Gated by the target’s feature.

§Panics

When target is not registered yet.

Source

pub fn app_only(&mut self, tool: &str) -> &mut Self

Keeps tool from the model: only an MCP App calls it, such as the undo button on a page that shows what another tool did. It is still identified, entitled and metered like any call.

§Panics

When tool is not registered yet.

Source

pub fn hints(&mut self, tool: &str, hints: Hints) -> &mut Self

Tells hosts what they may assume about tool.

§Panics

When tool is not registered yet.

Source

pub fn looks(&mut self, target: &str, looks: Looks) -> &mut Self

How target (a tool or prompt by name, or a resource by URI) shows to people.

§Panics

When target is not registered yet.

Source

pub fn server(&mut self, looks: Looks) -> &mut Self

How the server itself shows to people, in hosts that list servers.

Source

pub fn instructions(&mut self, text: &'static str) -> &mut Self

Guidance for a model on using the module’s tools, sent when a client connects, for hosts that do not load the module’s SKILL.md.

Auto Trait Implementations§

§

impl<M> !RefUnwindSafe for Ops<M>

§

impl<M> !UnwindSafe for Ops<M>

§

impl<M> Forget for Ops<M>

§

impl<M> Freeze for Ops<M>
where Vec<Op<M>>: Freeze, Vec<Readable<M>>: Freeze, Vec<Promptable<M>>: Freeze, Vec<Completer<M>>: Freeze,

§

impl<M> Send for Ops<M>
where Vec<Op<M>>: Send, Vec<Readable<M>>: Send, Vec<Promptable<M>>: Send, Vec<Completer<M>>: Send,

§

impl<M> Sync for Ops<M>
where Vec<Op<M>>: Sync, Vec<Readable<M>>: Sync, Vec<Promptable<M>>: Sync, Vec<Completer<M>>: Sync,

§

impl<M> Unpin for Ops<M>
where Vec<Op<M>>: Unpin, Vec<Readable<M>>: Unpin, Vec<Promptable<M>>: Unpin, Vec<Completer<M>>: Unpin,

§

impl<M> UnsafeUnpin for Ops<M>
where Vec<Op<M>>: UnsafeUnpin, Vec<Readable<M>>: UnsafeUnpin, Vec<Promptable<M>>: UnsafeUnpin, Vec<Completer<M>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more