mcp-error-code-mapper
Map application errors to MCP error codes with proper messages, error types, and recovery suggestions.
What this skill does
# MCP Error Code Mapper
Map application errors to MCP error codes with proper handling.
## Capabilities
- Map errors to MCP error codes
- Create structured error responses
- Generate error documentation
- Implement error recovery hints
- Configure error serialization
- Create error handler utilities
## Usage
Invoke this skill when you need to:
- Map application errors to MCP errors
- Create structured error responses
- Implement error handling for tools
- Generate error documentation
## Inputs
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| language | string | Yes | Target language |
| errors | array | Yes | Error definitions |
| includeRecovery | boolean | No | Include recovery hints |
### Error Structure
```json
{
"errors": [
{
"name": "FileNotFound",
"mcpCode": -32002,
"message": "File not found: {path}",
"recovery": "Check if the file exists and the path is correct"
},
{
"name": "InvalidInput",
"mcpCode": -32602,
"message": "Invalid input: {reason}",
"recovery": "Review the input parameters and try again"
}
]
}
```
## Generated Patterns
### TypeScript Error Mapper
```typescript
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
// Standard MCP Error Codes
export const MCP_ERROR_CODES = {
PARSE_ERROR: -32700,
INVALID_REQUEST: -32600,
METHOD_NOT_FOUND: -32601,
INVALID_PARAMS: -32602,
INTERNAL_ERROR: -32603,
// Custom codes (-32000 to -32099)
FILE_NOT_FOUND: -32001,
PERMISSION_DENIED: -32002,
RESOURCE_NOT_FOUND: -32003,
VALIDATION_ERROR: -32004,
} as const;
// Error with recovery hint
interface McpErrorWithRecovery extends McpError {
data?: {
recovery?: string;
details?: unknown;
};
}
// Error factory functions
export function fileNotFoundError(path: string): McpErrorWithRecovery {
return {
code: MCP_ERROR_CODES.FILE_NOT_FOUND,
message: `File not found: ${path}`,
data: {
recovery: 'Check if the file exists and the path is correct',
details: { path },
},
};
}
export function invalidParamsError(reason: string): McpErrorWithRecovery {
return {
code: MCP_ERROR_CODES.INVALID_PARAMS,
message: `Invalid parameters: ${reason}`,
data: {
recovery: 'Review the input parameters and try again',
},
};
}
// Error handler wrapper
export function handleToolError(error: unknown): McpErrorWithRecovery {
if (error instanceof Error) {
// Map known error types
if (error.message.includes('ENOENT')) {
return fileNotFoundError(error.message);
}
if (error.message.includes('EACCES')) {
return {
code: MCP_ERROR_CODES.PERMISSION_DENIED,
message: `Permission denied: ${error.message}`,
data: { recovery: 'Check file permissions' },
};
}
// Fallback to internal error
return {
code: MCP_ERROR_CODES.INTERNAL_ERROR,
message: error.message,
};
}
return {
code: MCP_ERROR_CODES.INTERNAL_ERROR,
message: 'An unexpected error occurred',
};
}
```
### Python Error Mapper
```python
from enum import IntEnum
from typing import Any, Optional
from dataclasses import dataclass
class McpErrorCode(IntEnum):
PARSE_ERROR = -32700
INVALID_REQUEST = -32600
METHOD_NOT_FOUND = -32601
INVALID_PARAMS = -32602
INTERNAL_ERROR = -32603
# Custom codes
FILE_NOT_FOUND = -32001
PERMISSION_DENIED = -32002
RESOURCE_NOT_FOUND = -32003
@dataclass
class McpError(Exception):
code: int
message: str
recovery: Optional[str] = None
details: Optional[Any] = None
def to_dict(self) -> dict:
result = {'code': self.code, 'message': self.message}
if self.recovery or self.details:
result['data'] = {}
if self.recovery:
result['data']['recovery'] = self.recovery
if self.details:
result['data']['details'] = self.details
return result
def file_not_found_error(path: str) -> McpError:
return McpError(
code=McpErrorCode.FILE_NOT_FOUND,
message=f'File not found: {path}',
recovery='Check if the file exists and the path is correct',
details={'path': path}
)
def handle_tool_error(error: Exception) -> McpError:
error_msg = str(error)
if 'FileNotFoundError' in type(error).__name__:
return file_not_found_error(error_msg)
if 'PermissionError' in type(error).__name__:
return McpError(
code=McpErrorCode.PERMISSION_DENIED,
message=f'Permission denied: {error_msg}',
recovery='Check file permissions'
)
return McpError(
code=McpErrorCode.INTERNAL_ERROR,
message=error_msg
)
```
## Workflow
1. **Define errors** - List application errors
2. **Map codes** - Assign MCP error codes
3. **Create messages** - User-friendly messages
4. **Add recovery** - Recovery suggestions
5. **Generate handlers** - Error handling code
6. **Document errors** - Error documentation
## Target Processes
- mcp-tool-implementation
- mcp-server-security-hardening
- error-handling-user-feedback
Related 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.