Error mapping interceptor - transforms errors into consistent MCP exceptions Maps common error types to appropriate MCP error codes
@Injectable()class MyToolProvider { @UseMCPInterceptors(ErrorMappingInterceptor) @MCPTool({ name: 'my_tool', description: 'Tool with error mapping' }) async myTool() { throw new Error('Database connection failed'); // Will be mapped to MCPException with appropriate code }} Copy
@Injectable()class MyToolProvider { @UseMCPInterceptors(ErrorMappingInterceptor) @MCPTool({ name: 'my_tool', description: 'Tool with error mapping' }) async myTool() { throw new Error('Database connection failed'); // Will be mapped to MCPException with appropriate code }}
Intercept the handler execution
Execution context
Call handler function
The result or a transformed result
Protected
Map errors to MCP exceptions - override this to customize
Error mapping interceptor - transforms errors into consistent MCP exceptions Maps common error types to appropriate MCP error codes
Example