mcp-tool-creation
Master creating MCP tools with type-safe parameters, automatic schema generation, and best practices
What this skill does
You are an expert in creating MCP tools using the rmcp crate, with deep knowledge of the `#[tool]` macro system, parameter handling, and tool design patterns.
## Your Expertise
You guide developers on:
- Tool design and API patterns
- `#[tool]` macro usage and configuration
- Parameter types and validation
- Error handling in tools
- Async tool implementation
- Schema generation and introspection
- Testing tools thoroughly
## What are MCP Tools?
**Tools** are functions that AI assistants can invoke to perform actions or computations. They are the primary way MCP servers expose capabilities.
### Tool Characteristics
- **Invocable**: AI assistants can call them
- **Typed**: Parameters and returns have schemas
- **Async**: Support long-running operations
- **Described**: Clear descriptions for AI understanding
- **Safe**: Error handling and validation
## The #[tool] Macro System
### Basic Tool Declaration
```rust
use rmcp::prelude::*;
#[tool(tool_box)]
struct MyService;
#[tool(tool_box)]
impl MyService {
#[tool(description = "Add two numbers together")]
async fn add(&self, a: i32, b: i32) -> i32 {
a + b
}
}
```
### Macro Components
1. **`#[tool(tool_box)]` on impl block**
- Marks the impl as containing tools
- Generates `list_tools()` method
- Generates `call_tool()` dispatcher
2. **`#[tool(description = "...")]` on methods**
- Required for each tool
- Description for AI understanding
- Should be clear and concise
3. **Method signature requirements**
- Must be `async fn`
- First parameter must be `&self`
- Parameters must be Deserialize + JsonSchema
- Return must implement IntoCallToolResult
## Parameter Handling
### Simple Parameters
Simple types work out of the box:
```rust
#[tool(tool_box)]
impl MyService {
#[tool(description = "Process numbers")]
async fn process(
&self,
count: i32,
name: String,
active: bool,
score: f64,
) -> String {
format!("{} {} {} {}", count, name, active, score)
}
}
```
**Supported simple types:**
- Integers: `i8`, `i16`, `i32`, `i64`, `u8`, `u16`, `u32`, `u64`
- Floats: `f32`, `f64`
- Strings: `String`, `&str`
- Booleans: `bool`
### Optional Parameters
Use `Option<T>` for optional parameters:
```rust
#[tool(tool_box)]
impl SearchService {
#[tool(description = "Search with optional filters")]
async fn search(
&self,
query: String,
limit: Option<u32>,
offset: Option<u32>,
sort_by: Option<String>,
) -> Vec<String> {
let limit = limit.unwrap_or(10);
let offset = offset.unwrap_or(0);
// Search logic
vec![]
}
}
```
### Complex Parameters
For complex parameter objects, use `#[tool(aggr)]`:
```rust
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
struct SearchRequest {
query: String,
#[serde(default)]
limit: u32,
#[serde(default)]
offset: u32,
filters: Option<Vec<String>>,
}
#[tool(tool_box)]
impl SearchService {
#[tool(description = "Search with complex parameters")]
async fn search(&self, #[tool(aggr)] req: SearchRequest) -> Vec<String> {
// Use req.query, req.limit, etc.
vec![]
}
}
```
**Requirements for complex parameters:**
- Must derive `Deserialize`, `Serialize`, `JsonSchema`
- Use `#[tool(aggr)]` attribute
- Can include nested structures
- Supports `#[serde]` attributes
### Array Parameters
Handle arrays and vectors:
```rust
#[tool(tool_box)]
impl BatchService {
#[tool(description = "Process multiple items")]
async fn process_batch(&self, items: Vec<String>) -> Vec<String> {
items.into_iter()
.map(|s| s.to_uppercase())
.collect()
}
#[tool(description = "Sum array of numbers")]
async fn sum_array(&self, numbers: Vec<i32>) -> i32 {
numbers.iter().sum()
}
}
```
### Enum Parameters
Use enums for constrained choices:
```rust
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "lowercase")]
enum SortOrder {
Asc,
Desc,
}
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "lowercase")]
enum OutputFormat {
Json,
Yaml,
Toml,
}
#[tool(tool_box)]
impl DataService {
#[tool(description = "Fetch data with format and sort options")]
async fn fetch_data(
&self,
format: OutputFormat,
sort: SortOrder,
) -> String {
format!("{:?} {:?}", format, sort)
}
}
```
## Return Types
### Simple Returns
Return simple values directly:
```rust
#[tool(tool_box)]
impl MyService {
#[tool(description = "Get count")]
async fn count(&self) -> i32 {
42
}
#[tool(description = "Get message")]
async fn message(&self) -> String {
"Hello".to_string()
}
}
```
### Complex Returns
Return structured data:
```rust
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
struct User {
id: u64,
name: String,
email: String,
active: bool,
}
#[tool(tool_box)]
impl UserService {
#[tool(description = "Get user by ID")]
async fn get_user(&self, id: u64) -> User {
User {
id,
name: "John Doe".to_string(),
email: "[email protected]".to_string(),
active: true,
}
}
#[tool(description = "List all users")]
async fn list_users(&self) -> Vec<User> {
vec![]
}
}
```
### Result Returns
Handle errors with `Result`:
```rust
use thiserror::Error;
#[derive(Debug, Error)]
enum ServiceError {
#[error("Not found: {0}")]
NotFound(String),
#[error("Invalid input: {0}")]
InvalidInput(String),
#[error("Database error: {0}")]
DatabaseError(String),
}
#[tool(tool_box)]
impl DataService {
#[tool(description = "Fetch item by ID")]
async fn fetch(&self, id: String) -> Result<String, ServiceError> {
if id.is_empty() {
return Err(ServiceError::InvalidInput(
"ID cannot be empty".to_string()
));
}
// Fetch logic
Ok("Item data".to_string())
}
}
```
## Tool Design Patterns
### Pattern 1: CRUD Operations
```rust
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
struct Item {
id: String,
name: String,
value: i32,
}
#[tool(tool_box)]
struct ItemService {
items: Arc<RwLock<HashMap<String, Item>>>,
}
#[tool(tool_box)]
impl ItemService {
#[tool(description = "Create a new item")]
async fn create(&self, name: String, value: i32) -> Result<Item, String> {
let id = uuid::Uuid::new_v4().to_string();
let item = Item { id: id.clone(), name, value };
let mut items = self.items.write().await;
items.insert(id.clone(), item.clone());
Ok(item)
}
#[tool(description = "Get item by ID")]
async fn get(&self, id: String) -> Result<Item, String> {
let items = self.items.read().await;
items.get(&id)
.cloned()
.ok_or_else(|| format!("Item {} not found", id))
}
#[tool(description = "Update an item")]
async fn update(
&self,
id: String,
name: Option<String>,
value: Option<i32>,
) -> Result<Item, String> {
let mut items = self.items.write().await;
let item = items.get_mut(&id)
.ok_or_else(|| format!("Item {} not found", id))?;
if let Some(name) = name {
item.name = name;
}
if let Some(value) = value {
item.value = value;
}
Ok(item.clone())
}
#[tool(description = "Delete an item")]
async fn delete(&self, id: String) -> Result<(), String> {
let mut items = self.items.write().await;
items.remove(&id)
.ok_or_else(|| foRelated in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.