Skip to main content

Module skill

Module skill 

Source
Expand description

The skill contract — the uniform capability unit of an MCP server.

Every tool a server exposes is a skill: a self-contained type that implements Skill (name / description / schema / call, plus optional metadata). The trait is generic over a server-state type S, which is whatever shared state your tools need — HTTP clients, database handles, configuration. The framework never looks inside S; it only hands each call a &S so the tool body can use it.

use std::sync::Arc;
use futures::future::BoxFuture;
use mcp_skill_framework::{schema_for, text_result, Skill, SkillCtx};
use rmcp::model::{CallToolResult, JsonObject};
use rmcp::ErrorData as McpError;
use serde::Deserialize;

struct App; // your shared server state

#[derive(Deserialize, schemars::JsonSchema)]
struct GreetArgs {
    /// Who to greet.
    name: String,
}

struct Greet;
impl Skill<App> for Greet {
    fn name(&self) -> &'static str { "greet" }
    fn description(&self) -> &'static str { "Greet someone by name." }
    fn schema(&self) -> Arc<JsonObject> { schema_for::<GreetArgs>() }
    fn call<'a>(&self, ctx: SkillCtx<'a, App>) -> BoxFuture<'a, Result<CallToolResult, McpError>> {
        Box::pin(async move {
            let (_app, args) = ctx.parse::<GreetArgs>()?;
            Ok(text_result(format!("Hello, {}!", args.name)))
        })
    }
}

Structs§

NoArgs
Empty argument set, for skills that take no parameters.
SkillCtx
What a Skill::call receives: a borrow of the shared server state plus the raw, already-extracted argument object (parse it with SkillCtx::parse).
SkillExample
One concrete worked example for a Skill. Surfaced through an introspection tool (see crate::describe); not part of the MCP tools/list payload, which stays tight (just description and inputSchema) so the orientation is paid for once and looked up on demand thereafter.

Traits§

Skill
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.

Functions§

schema_for
Build a JSON schema for an arguments struct (helper for Skill::schema).