Skip to main content

Skill

Trait Skill 

Source
pub trait Skill<S>:
    Send
    + Sync
    + 'static {
    // Required methods
    fn name(&self) -> &'static str;
    fn description(&self) -> &'static str;
    fn schema(&self) -> Arc<JsonObject> ;
    fn call<'a>(
        &self,
        ctx: SkillCtx<'a, S>,
    ) -> BoxFuture<'a, Result<CallToolResult, McpError>>;

    // Provided methods
    fn examples(&self) -> &'static [SkillExample] { ... }
    fn use_cases(&self) -> &'static [&'static str] { ... }
    fn validation_rules(&self) -> &'static [Rule] { ... }
    fn validate(&self, args: &JsonObject) -> ValidationResult { ... }
    fn check_capability(&self) -> SkillCapability { ... }
}
Expand description

The contract every tool implements. Object-safe, so skills are stored as Box<dyn Skill<S>> and assembled uniformly. Generic over the shared server-state type S.

Required Methods§

Source

fn name(&self) -> &'static str

Tool name (the MCP name, e.g. translate).

Source

fn description(&self) -> &'static str

One-line tool description shown to the model.

Source

fn schema(&self) -> Arc<JsonObject>

JSON schema of the tool’s arguments. Build it with schema_for.

Source

fn call<'a>( &self, ctx: SkillCtx<'a, S>, ) -> BoxFuture<'a, Result<CallToolResult, McpError>>

Run the tool.

Provided Methods§

Source

fn examples(&self) -> &'static [SkillExample]

Canonical invocation examples. Defaults to empty; opt in to surface worked examples through introspection. See SkillExample.

Source

fn use_cases(&self) -> &'static [&'static str]

Short phrases naming the situations this tool is the right answer for. Defaults to empty. A model uses these to disambiguate between similarly-named tools; the dispatcher does not consult them.

Source

fn validation_rules(&self) -> &'static [Rule]

Declarative validation rules evaluated by the dispatcher BEFORE the call body runs. Defaults to empty (no rules). Override to assert domain constraints (range bounds, allowed enum values, mutual exclusion) so the caller gets a structured validation_failed payload it can correct from, rather than a free-form error string. See crate::validation::Rule for the DSL.

Source

fn validate(&self, args: &JsonObject) -> ValidationResult

Run validation against the parsed argument object. The default impl evaluates Self::validation_rules — most skills only override the declarative rule list. Override this directly when you need fully imperative validation that can’t be expressed in the DSL.

Source

fn check_capability(&self) -> SkillCapability

Per-tool capability probe — defaults to SkillCapability::Ready. Override when a single tool has a requirement its family doesn’t cover (a stricter binary, a compile-time feature, a configured endpoint). Probes are stateless and run once at startup.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§