pub struct Ops<M> { /* private fields */ }Expand description
The operations a module registers.
Implementations§
Source§impl<M: Send + Sync + 'static> Ops<M>
impl<M: Send + Sync + 'static> Ops<M>
Sourcepub fn tool<A, R, E, F, Fut>(
&mut self,
name: &'static str,
feature: Feature,
handler: F,
) -> &mut Selfwhere
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,
pub fn tool<A, R, E, F, Fut>(
&mut self,
name: &'static str,
feature: Feature,
handler: F,
) -> &mut Selfwhere
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.
Sourcepub fn task<A, R, E, F, Fut>(
&mut self,
name: &'static str,
feature: Feature,
handler: F,
) -> &mut Selfwhere
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,
pub fn task<A, R, E, F, Fut>(
&mut self,
name: &'static str,
feature: Feature,
handler: F,
) -> &mut Selfwhere
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.
Sourcepub fn app(
&mut self,
tool: &str,
uri: &'static str,
html: &'static str,
) -> &mut Self
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.
Sourcepub fn resource<A, E, F, Fut>(
&mut self,
uri: &'static str,
name: &'static str,
feature: Feature,
handler: F,
) -> &mut Self
pub fn resource<A, E, F, Fut>( &mut self, uri: &'static str, name: &'static str, feature: Feature, handler: F, ) -> &mut Self
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.
Sourcepub fn prompt<A, E, F, Fut>(
&mut self,
name: &'static str,
feature: Feature,
handler: F,
) -> &mut Self
pub fn prompt<A, E, F, Fut>( &mut self, name: &'static str, feature: Feature, handler: F, ) -> &mut Self
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.
Sourcepub fn complete<E, F, Fut>(
&mut self,
target: &'static str,
argument: &'static str,
handler: F,
) -> &mut Self
pub fn complete<E, F, Fut>( &mut self, target: &'static str, argument: &'static str, handler: F, ) -> &mut Self
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.
Sourcepub fn app_only(&mut self, tool: &str) -> &mut Self
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.
Sourcepub fn looks(&mut self, target: &str, looks: Looks) -> &mut Self
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.
Sourcepub fn server(&mut self, looks: Looks) -> &mut Self
pub fn server(&mut self, looks: Looks) -> &mut Self
How the server itself shows to people, in hosts that list servers.
Sourcepub fn instructions(&mut self, text: &'static str) -> &mut Self
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.