error-handling-patterns

Implement McpResult-based error handling patterns for Rust MCP server handlers.

2|Updated Aug 17, 2025
One-click install
npx skills add https://github.com/aussierobots/turul-mcp-framework --skill error-handling-patterns-aussierobots
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: error-handling-patterns
Source: https://github.com/aussierobots/turul-mcp-framework/tree/main/plugins/turul-mcp-skills/skills/error-handling-patterns
Command: npx skills add https://github.com/aussierobots/turul-mcp-framework --skill error-handling-patterns-aussierobots

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill clarifies the MCP error handling architecture and best practices for returning McpError variants across tool, resource, and prompt handlers.

Core Features & Use Cases

  • Explains the three-layer error architecture: domain errors, framework conversions, and JSON-RPC responses, and the Golden Rule that handlers must return McpResult<T>.
  • Provides a decision tree for selecting the appropriate McpError variant for parameter issues, execution failures, and not-found conditions.
  • Includes concrete Rust examples of converting errors with From, map_err, and explicit constructors in tool, resource, and prompt contexts.

Quick Start

Identify and apply MCP error handling patterns in tool, resource, and prompt handlers using the McpError variants and conversion helpers.

Frequently Asked Questions about error-handling-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle errors in a Rust MCP server?

Rust MCP server error handling requires returning McpResult<T> from tool, resource, and prompt handlers while using McpError variants to map domain errors into JSON-RPC responses.

What is the MCP error handling architecture in Rust?

The MCP error architecture uses three layers: domain errors, framework conversions, and JSON-RPC responses. Handlers must return McpResult<T> to let the framework automatically convert McpError variants into proper protocol responses.

How do I choose the right McpError variant for parameter validation failures?

Selecting McpError variants for parameter validation involves using a decision tree that distinguishes parameter issues, execution failures, and not-found conditions to return the correct McpResult<T> from your handler.

Can I use From and map_err to convert domain errors to McpError in Rust?

Yes, you can convert domain errors to McpError using From implementations, map_err, and explicit constructors in tool, resource, and prompt contexts to satisfy the McpResult<T> return requirement.

What's the best way to map tool execution failures to McpError variants?

Mapping tool execution failures to McpError variants relies on framework conversions and explicit constructors to translate domain errors into JSON-RPC errors while maintaining the McpResult<T> return type.

Why does my MCP server return a generic JSON-RPC error instead of the specific McpError?

Generic JSON-RPC errors occur when handlers bypass the McpResult<T> return rule. You must use McpError constructors and conversion helpers to ensure the framework maps domain errors to the correct variants.